fix: Phase 0b - correct all SQL column names in calculation engine
Schema corrections applied: - weight_log: weight_kg → weight - nutrition_log: calories → kcal - activity_log: duration → duration_min, avg_heart_rate → hr_avg, max_heart_rate → hr_max - rest_days: rest_type → type (aliased for backward compat) - vitals_baseline: resting_heart_rate → resting_hr - sleep_log: total_sleep_min → duration_minutes, deep_min → deep_minutes, rem_min → rem_minutes, waketime → wake_time - focus_area_definitions: fa.focus_area_id → fa.key (proper join column) Affected files: - body_metrics.py: weight column (all queries) - nutrition_metrics.py: kcal column + weight - activity_metrics.py: duration_min, hr_avg, hr_max, quality via RPE mapping - recovery_metrics.py: sleep + vitals columns - correlation_metrics.py: kcal, weight - scores.py: focus_area key selection All 100+ Phase 0b placeholders should now calculate correctly. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
53969f8768
commit
4817fd2b29
6 files changed
+61
-52
No files matched your search
@@ -26,14 +26,14 @@ def calculate_weight_7d_median(profile_id: str) -> Optional[float]:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT weight_kg
|
||||
SELECT weight
|
||||
FROM weight_log
|
||||
WHERE profile_id = %s
|
||||
AND date >= CURRENT_DATE - INTERVAL '7 days'
|
||||
ORDER BY date DESC
|
||||
""", (profile_id,))
|
||||
|
||||
weights = [row['weight_kg'] for row in cur.fetchall()]
|
||||
weights = [row['weight'] for row in cur.fetchall()]
|
||||
|
||||
if len(weights) < 4: # Need at least 4 measurements
|
||||
return None
|
||||
@@ -59,14 +59,14 @@ def _calculate_weight_slope(profile_id: str, days: int) -> Optional[float]:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT date, weight_kg
|
||||
SELECT date, weight
|
||||
FROM weight_log
|
||||
WHERE profile_id = %s
|
||||
AND date >= CURRENT_DATE - INTERVAL '%s days'
|
||||
ORDER BY date
|
||||
""", (profile_id, days))
|
||||
|
||||
data = [(row['date'], row['weight_kg']) for row in cur.fetchall()]
|
||||
data = [(row['date'], row['weight']) for row in cur.fetchall()]
|
||||
|
||||
# Need minimum data points based on period
|
||||
min_points = max(18, int(days * 0.6)) # 60% coverage
|
||||
@@ -158,7 +158,7 @@ def _calculate_body_composition_change(profile_id: str, metric: str, days: int)
|
||||
|
||||
# Get weight and caliper measurements
|
||||
cur.execute("""
|
||||
SELECT w.date, w.weight_kg, c.body_fat_pct
|
||||
SELECT w.date, w.weight, c.body_fat_pct
|
||||
FROM weight_log w
|
||||
LEFT JOIN caliper_log c ON w.profile_id = c.profile_id
|
||||
AND w.date = c.date
|
||||
@@ -170,7 +170,7 @@ def _calculate_body_composition_change(profile_id: str, metric: str, days: int)
|
||||
data = [
|
||||
{
|
||||
'date': row['date'],
|
||||
'weight': row['weight_kg'],
|
||||
'weight': row['weight'],
|
||||
'bf_pct': row['body_fat_pct']
|
||||
}
|
||||
for row in cur.fetchall()
|
||||
|
||||
Reference in new issue
Block a user