fix: Phase 0b - fix remaining calculation bugs from log analysis
Deploy Development / deploy (push) Successful in 43s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s

Bugs fixed based on actual error logs:
1. TypeError: progress_pct None handling - changed .get('progress_pct', 0) to (goal.get('progress_pct') or 0)
2. UUID Error: focus_area_id query - changed WHERE focus_area_id = %s to WHERE key = %s
3. NameError: calculate_recovery_score_v2 - added missing import in calculate_category_progress
4. UndefinedColumn: c_thigh_r - removed left/right separation, only c_thigh exists
5. UndefinedColumn: resting_heart_rate - fixed remaining AVG(resting_heart_rate) to AVG(resting_hr)
6. KeyError: total_sleep_min - changed dict access to duration_minutes

Changes:
- scores.py: Fixed progress_pct None handling, focus_area key query, added recovery import
- body_metrics.py: Fixed thigh_28d_delta to use single c_thigh column
- recovery_metrics.py: Fixed resting_hr SELECT queries, fixed sleep_debt dict access

All errors from logs should now be resolved.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-28 08:50:55 +01:00
1 parent dd3a4111fc
commit 02394ea19c
3 files changed
+10 -10

No files matched your search

+3 -2
View File
@@ -404,7 +404,7 @@ def get_top_priority_goal(profile_id: str) -> Optional[Dict]:
for goal in goals:
# Progress gap (0-100, higher = further from target)
goal['progress_gap'] = 100 - goal.get('progress_pct', 0)
goal['progress_gap'] = 100 - (goal.get('progress_pct') or 0)
# Get focus areas for this goal
with get_db() as conn:
@@ -480,7 +480,7 @@ def calculate_focus_area_progress(profile_id: str, focus_area_id: str) -> Option
JOIN goal_focus_contributions gfc ON g.id = gfc.goal_id
WHERE g.profile_id = %s
AND gfc.focus_area_id = (
SELECT id FROM focus_area_definitions WHERE focus_area_id = %s
SELECT id FROM focus_area_definitions WHERE key = %s
)
AND g.status = 'active'
""", (profile_id, focus_area_id))
@@ -533,6 +533,7 @@ def calculate_category_progress(profile_id: str, category: str) -> Optional[int]
from calculations.activity_metrics import calculate_activity_score
return calculate_activity_score(profile_id)
elif score_func_name == 'recovery_score':
from calculations.recovery_metrics import calculate_recovery_score_v2
return calculate_recovery_score_v2(profile_id)
elif score_func_name == 'data_quality_score':
return calculate_data_quality_score(profile_id)