Fitness historie #95

Merged
Lars merged 6 commits from develop into main 2026-04-20 08:26:46 +02:00
Showing only changes of commit 33b08a8d82 - Show all commits

View File

@ -211,7 +211,7 @@ def build_sleep_duration_quality_chart_payload(profile_id: str, days: int) -> Di
with get_db() as conn:
cur = get_cursor(conn)
cur.execute(
"""SELECT date, total_sleep_min
"""SELECT date, duration_minutes
FROM sleep_log
WHERE profile_id=%s AND date >= %s
ORDER BY date""",
@ -231,7 +231,9 @@ def build_sleep_duration_quality_chart_payload(profile_id: str, days: int) -> Di
}
labels = [row["date"].isoformat() for row in rows]
duration_hours = [safe_float(row["total_sleep_min"]) / 60 if row["total_sleep_min"] else None for row in rows]
duration_hours = [
safe_float(row["duration_minutes"]) / 60 if row["duration_minutes"] else None for row in rows
]
quality_scores = [(d / 8 * 100) if d else None for d in duration_hours]
@ -266,7 +268,7 @@ def build_sleep_duration_quality_chart_payload(profile_id: str, days: int) -> Di
"confidence": duration_data["confidence"],
"data_points": len(rows),
"avg_duration_hours": round(duration_data["avg_duration_hours"], 1),
"sleep_quality_score": quality_data.get("sleep_quality_score", 0),
"sleep_quality_score": quality_data.get("quality_score", 0),
}
),
}
@ -295,7 +297,7 @@ def build_sleep_debt_chart_payload(profile_id: str, days: int) -> Dict[str, Any]
with get_db() as conn:
cur = get_cursor(conn)
cur.execute(
"""SELECT date, total_sleep_min
"""SELECT date, duration_minutes
FROM sleep_log
WHERE profile_id=%s AND date >= %s
ORDER BY date""",
@ -321,7 +323,7 @@ def build_sleep_debt_chart_payload(profile_id: str, days: int) -> Dict[str, Any]
debt_values = []
for row in rows:
actual_hours = safe_float(row["total_sleep_min"]) / 60 if row["total_sleep_min"] else 0
actual_hours = safe_float(row["duration_minutes"]) / 60 if row["duration_minutes"] else 0
daily_deficit = target_hours - actual_hours
cumulative_debt += daily_deficit
debt_values.append(cumulative_debt)