Goals -System refactored - Platzhaltersystem enhanced (als draft) #53

Merged
Lars merged 86 commits from develop into main 2026-03-31 11:46:48 +02:00
Showing only changes of commit 10ea560fcf - Show all commits

View File

@ -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)