feat: Phase 0c - body_metrics.py module complete
Data Layer: - get_latest_weight_data() - most recent weight with date - get_weight_trend_data() - already existed (PoC) - get_body_composition_data() - already existed (PoC) - get_circumference_summary_data() - already existed (PoC) Placeholder Layer: - get_latest_weight() - refactored to use data layer - get_caliper_summary() - refactored to use get_body_composition_data - get_weight_trend() - already refactored (PoC) - get_latest_bf() - already refactored (PoC) - get_circ_summary() - already refactored (PoC) body_metrics.py now complete with all 4 functions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
b4558b0582
commit
6c23973c5d
3 files changed
+71
-23
No files matched your search
@@ -45,6 +45,7 @@ __all__ = [
|
||||
'serialize_dates',
|
||||
|
||||
# Body Metrics
|
||||
'get_latest_weight_data',
|
||||
'get_weight_trend_data',
|
||||
'get_body_composition_data',
|
||||
'get_circumference_summary_data',
|
||||
|
||||
@@ -4,6 +4,7 @@ Body Metrics Data Layer
|
||||
Provides structured data for body composition and measurements.
|
||||
|
||||
Functions:
|
||||
- get_latest_weight_data(): Most recent weight entry
|
||||
- get_weight_trend_data(): Weight trend with slope and direction
|
||||
- get_body_composition_data(): Body fat percentage and lean mass
|
||||
- get_circumference_summary_data(): Latest circumference measurements
|
||||
@@ -21,6 +22,51 @@ from db import get_db, get_cursor, r2d
|
||||
from data_layer.utils import calculate_confidence, safe_float
|
||||
|
||||
|
||||
def get_latest_weight_data(
|
||||
profile_id: str
|
||||
) -> Dict:
|
||||
"""
|
||||
Get most recent weight entry.
|
||||
|
||||
Args:
|
||||
profile_id: User profile ID
|
||||
|
||||
Returns:
|
||||
{
|
||||
"weight": float, # kg
|
||||
"date": date,
|
||||
"confidence": str
|
||||
}
|
||||
|
||||
Migration from Phase 0b:
|
||||
OLD: get_latest_weight() returned formatted string "85.0 kg"
|
||||
NEW: Returns structured data {"weight": 85.0, "date": ...}
|
||||
"""
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute(
|
||||
"""SELECT weight, date FROM weight_log
|
||||
WHERE profile_id=%s
|
||||
ORDER BY date DESC
|
||||
LIMIT 1""",
|
||||
(profile_id,)
|
||||
)
|
||||
row = cur.fetchone()
|
||||
|
||||
if not row:
|
||||
return {
|
||||
"weight": 0.0,
|
||||
"date": None,
|
||||
"confidence": "insufficient"
|
||||
}
|
||||
|
||||
return {
|
||||
"weight": safe_float(row['weight']),
|
||||
"date": row['date'],
|
||||
"confidence": "high"
|
||||
}
|
||||
|
||||
|
||||
def get_weight_trend_data(
|
||||
profile_id: str,
|
||||
days: int = 28
|
||||
|
||||
Reference in new issue
Block a user