fix: Phase 0b - fix remaining calculation errors
Deploy Development / deploy (push) Successful in 47s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 13s

Fixes applied:
1. WHERE clause column names (total_sleep_min → duration_minutes, resting_heart_rate → resting_hr)
2. COUNT() column names (avg_heart_rate → hr_avg, quality_label → rpe)
3. Type errors (Decimal * float) - convert to float before multiplication
4. rest_days table (type column removed in migration 010, now uses rest_config JSONB)
5. c_thigh_l → c_thigh (no separate left/right columns)
6. focus_area_definitions queries (focus_area_id → key, label_de → name_de)

Missing functions implemented:
- goal_utils.get_active_goals() - queries goals table for active goals
- goal_utils.get_goal_by_id() - gets single goal
- calculations.scores.calculate_category_progress() - maps categories to score functions

Changes:
- activity_metrics.py: Fixed Decimal/float type errors, rest_config JSONB, data quality query
- recovery_metrics.py: Fixed all WHERE clause column names
- body_metrics.py: Fixed c_thigh column reference
- scores.py: Fixed focus_area queries, added calculate_category_progress()
- goal_utils.py: Added get_active_goals(), get_goal_by_id()

All calculation functions should now work with correct schema.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-28 08:39:31 +01:00
1 parent 4817fd2b29
commit dd3a4111fc
6 files changed
+112 -36

No files matched your search

+13 -14
View File
@@ -199,32 +199,31 @@ def update_baseline(
# Build SET clause dynamically
updates = []
values = []
idx = 1
if entry.resting_hr is not None:
updates.append(f"resting_hr = ${idx}")
updates.append("resting_hr = %s")
values.append(entry.resting_hr)
idx += 1
if entry.hrv is not None:
updates.append(f"hrv = ${idx}")
updates.append("hrv = %s")
values.append(entry.hrv)
idx += 1
if entry.vo2_max is not None:
updates.append(f"vo2_max = ${idx}")
updates.append("vo2_max = %s")
values.append(entry.vo2_max)
idx += 1
if entry.spo2 is not None:
updates.append(f"spo2 = ${idx}")
updates.append("spo2 = %s")
values.append(entry.spo2)
idx += 1
if entry.respiratory_rate is not None:
updates.append(f"respiratory_rate = ${idx}")
updates.append("respiratory_rate = %s")
values.append(entry.respiratory_rate)
idx += 1
if entry.body_temperature is not None:
updates.append("body_temperature = %s")
values.append(entry.body_temperature)
if entry.resting_metabolic_rate is not None:
updates.append("resting_metabolic_rate = %s")
values.append(entry.resting_metabolic_rate)
if entry.note:
updates.append(f"note = ${idx}")
updates.append("note = %s")
values.append(entry.note)
idx += 1
if not updates:
raise HTTPException(400, "No fields to update")
@@ -237,7 +236,7 @@ def update_baseline(
query = f"""
UPDATE vitals_baseline
SET {', '.join(updates)}
WHERE id = ${idx} AND profile_id = ${idx + 1}
WHERE id = %s AND profile_id = %s
RETURNING *
"""
cur.execute(query, values)