From b230a03fddcafbcaa61eb27efabac0f5a16e74fe Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 09:32:04 +0100 Subject: [PATCH] fix: Phase 0b - fix blood_pressure and top_goal_name bugs Final bug fixes: 1. blood_pressure_log query - changed 'date' column to 'measured_at' (correct column for TIMESTAMP) 2. top_goal_name KeyError - added 'name' to SELECT in get_active_goals() 3. top_goal_name fallback - use goal_type if name is NULL Changes: - scores.py: Fixed blood_pressure_log query to use measured_at instead of date - goal_utils.py: Added 'name' column to get_active_goals() SELECT - placeholder_resolver.py: Added fallback to goal_type if name is None These were the last 2 errors showing in logs. All major calculation bugs should now be fixed. Co-Authored-By: Claude Opus 4.6 --- backend/calculations/scores.py | 4 ++-- backend/goal_utils.py | 2 +- backend/placeholder_resolver.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/calculations/scores.py b/backend/calculations/scores.py index f75e882..b528759 100644 --- a/backend/calculations/scores.py +++ b/backend/calculations/scores.py @@ -207,8 +207,8 @@ def calculate_health_stability_score(profile_id: str) -> Optional[int]: SELECT systolic, diastolic FROM blood_pressure_log WHERE profile_id = %s - AND date >= CURRENT_DATE - INTERVAL '28 days' - ORDER BY date DESC + AND measured_at >= CURRENT_DATE - INTERVAL '28 days' + ORDER BY measured_at DESC """, (profile_id,)) bp_readings = cur.fetchall() diff --git a/backend/goal_utils.py b/backend/goal_utils.py index c680b97..25cc5e5 100644 --- a/backend/goal_utils.py +++ b/backend/goal_utils.py @@ -526,7 +526,7 @@ def get_active_goals(profile_id: str) -> List[Dict]: with get_db() as conn: cur = get_cursor(conn) cur.execute(""" - SELECT id, goal_type, target_value, target_date, + SELECT id, goal_type, name, target_value, target_date, current_value, progress_pct, status, is_primary FROM goals WHERE profile_id = %s diff --git a/backend/placeholder_resolver.py b/backend/placeholder_resolver.py index f16e866..b734eea 100644 --- a/backend/placeholder_resolver.py +++ b/backend/placeholder_resolver.py @@ -595,7 +595,7 @@ def _safe_str(func_name: str, profile_id: str) -> str: from calculations import body_metrics, nutrition_metrics, activity_metrics, scores, correlation_metrics func_map = { - 'top_goal_name': lambda pid: scores.get_top_priority_goal(pid)['name'] if scores.get_top_priority_goal(pid) else None, + 'top_goal_name': lambda pid: (scores.get_top_priority_goal(pid).get('name') or scores.get_top_priority_goal(pid).get('goal_type')) if scores.get_top_priority_goal(pid) else None, 'top_goal_status': lambda pid: scores.get_top_priority_goal(pid)['status'] if scores.get_top_priority_goal(pid) else None, 'top_focus_area_name': lambda pid: scores.get_top_focus_area(pid)['label'] if scores.get_top_focus_area(pid) else None, 'recomposition_quadrant': body_metrics.calculate_recomposition_quadrant,