fix: update sleep chart payloads to use duration_minutes and quality_score
- Changed SQL queries in `build_sleep_duration_quality_chart_payload` and `build_sleep_debt_chart_payload` to select `duration_minutes` instead of `total_sleep_min`. - Updated calculations for sleep duration and quality scores to reflect the new field names, ensuring accurate data representation in the recovery charts.
This commit is contained in:
parent
f42d3a9c92
commit
33b08a8d82
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user