From 10ea560fcfedaa8e1a683b0e6295abbf96c1d3a2 Mon Sep 17 00:00:00 2001 From: Lars Date: Sat, 28 Mar 2026 09:35:36 +0100 Subject: [PATCH] fix: Phase 0b - fix last sleep column names in health_stability_score MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed remaining sleep_log column name errors in calculate_health_stability_score: - SELECT: total_sleep_min, deep_min, rem_min → duration_minutes, deep_minutes, rem_minutes - _score_sleep_quality: Updated dict access to use new column names This was blocking goal_progress_score from calculating. Changes: - scores.py: Fixed sleep_log SELECT query and _score_sleep_quality dict access This should be the LAST column name bug! All Phase 0b calculations should now work. Co-Authored-By: Claude Opus 4.6 --- backend/calculations/scores.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/calculations/scores.py b/backend/calculations/scores.py index b528759..266d8c3 100644 --- a/backend/calculations/scores.py +++ b/backend/calculations/scores.py @@ -218,7 +218,7 @@ def calculate_health_stability_score(profile_id: str) -> Optional[int]: # 2. Sleep quality (25%) cur.execute(""" - SELECT total_sleep_min, deep_min, rem_min + SELECT duration_minutes, deep_minutes, rem_minutes FROM sleep_log WHERE profile_id = %s AND date >= CURRENT_DATE - INTERVAL '28 days' @@ -317,7 +317,7 @@ def _score_blood_pressure(readings: List) -> int: def _score_sleep_quality(sleep_data: List) -> int: """Score sleep quality (0-100)""" # Average sleep duration and quality - avg_total = sum(s['total_sleep_min'] for s in sleep_data) / len(sleep_data) + avg_total = sum(s['duration_minutes'] for s in sleep_data) / len(sleep_data) avg_total_hours = avg_total / 60 # Duration score (7+ hours = good) @@ -333,8 +333,8 @@ def _score_sleep_quality(sleep_data: List) -> int: # Quality score (deep + REM percentage) quality_scores = [] for s in sleep_data: - if s['deep_min'] and s['rem_min']: - quality_pct = ((s['deep_min'] + s['rem_min']) / s['total_sleep_min']) * 100 + if s['deep_minutes'] and s['rem_minutes']: + quality_pct = ((s['deep_minutes'] + s['rem_minutes']) / s['duration_minutes']) * 100 # 40-60% deep+REM is good if quality_pct >= 45: quality_scores.append(100)