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,15 +26,15 @@ def get_user_focus_weights(profile_id: str) -> Dict[str, float]:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT fa.focus_area_id, ufw.weight_pct
|
||||
SELECT ufw.focus_area_id, ufw.weight as weight_pct, fa.key
|
||||
FROM user_focus_area_weights ufw
|
||||
JOIN focus_area_definitions fa ON ufw.focus_area_id = fa.id
|
||||
WHERE ufw.profile_id = %s
|
||||
AND ufw.weight_pct > 0
|
||||
AND ufw.weight > 0
|
||||
""", (profile_id,))
|
||||
|
||||
return {
|
||||
row['focus_area_id']: float(row['weight_pct'])
|
||||
row['key']: float(row['weight_pct'])
|
||||
for row in cur.fetchall()
|
||||
}
|
||||
|
||||
@@ -410,13 +410,13 @@ def get_top_priority_goal(profile_id: str) -> Optional[Dict]:
|
||||
with get_db() as conn:
|
||||
cur = get_cursor(conn)
|
||||
cur.execute("""
|
||||
SELECT fa.focus_area_id
|
||||
SELECT fa.key as focus_area_key
|
||||
FROM goal_focus_contributions gfc
|
||||
JOIN focus_area_definitions fa ON gfc.focus_area_id = fa.id
|
||||
WHERE gfc.goal_id = %s
|
||||
""", (goal['id'],))
|
||||
|
||||
goal_focus_areas = [row['focus_area_id'] for row in cur.fetchall()]
|
||||
goal_focus_areas = [row['focus_area_key'] for row in cur.fetchall()]
|
||||
|
||||
# Sum focus weights
|
||||
goal['total_focus_weight'] = sum(
|
||||
|
||||
Reference in new issue
Block a user