Fix missing avg_hr_day/weight data; add 24hr HR chart to daily snapshot
Backend: - main.py: add ADD COLUMN IF NOT EXISTS migrations for avg_hr_day, max_hr_day, and intraday_hr (JSONB) on health_metrics — these columns were in the model but missing from existing DB instances, silently dropping all avg/max HR data. - models/user.py: add intraday_hr JSON column to HealthMetric. - garmin_connect_sync.py: fetch body composition (weight, BMI, body fat, muscle mass) via get_body_composition() per day, with stats.bodyWeight as fallback. Fetch intraday heart rate via get_heart_rates() and store non-null [epoch_ms, bpm] pairs in intraday_hr. - health.py: add GET /health-metrics/intraday?date=YYYY-MM-DD endpoint that returns the stored intraday_hr array for a specific day. Frontend (HealthPage): - Add IntradayHrChart component: AreaChart rendering the 24-hour HR trace with time-of-day x-axis. - DailySnapshot: show 24-hour HR chart (when intraday data present) above the activity strip; add weight + body fat % to the Heart & HRV card; show max HR alongside avg HR. - HealthPage: query /intraday for the selected day and pass data down. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -115,6 +115,30 @@ async def health_summary(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/intraday")
|
||||
async def intraday_health(
|
||||
date: str = Query(..., description="YYYY-MM-DD"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
current_user: User = Depends(get_current_user),
|
||||
):
|
||||
"""Return intraday heart rate series for a specific day."""
|
||||
from datetime import date as _date
|
||||
from fastapi import HTTPException
|
||||
try:
|
||||
metric_date = _date.fromisoformat(date)
|
||||
except ValueError:
|
||||
raise HTTPException(status_code=400, detail="date must be YYYY-MM-DD")
|
||||
|
||||
result = await db.execute(
|
||||
select(HealthMetric).where(
|
||||
HealthMetric.user_id == current_user.id,
|
||||
func.date(HealthMetric.date) == metric_date,
|
||||
)
|
||||
)
|
||||
metric = result.scalar_one_or_none()
|
||||
return {"hr_values": metric.intraday_hr if metric else None}
|
||||
|
||||
|
||||
@router.put("/manual")
|
||||
async def add_manual_metric(
|
||||
body: dict,
|
||||
|
||||
Reference in New Issue
Block a user