-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
The sparkline card widget needs period summary data (avg, trend, count) for the metric it displays. Currently, getPeriodSummary in queries.ts doesn't handle contextual HRV metrics (hrv_sleep, hrv_activity, hrv_awake) — it passes them to getTimeSeriesStats which queries the time_series table directly, where these computed metrics don't exist.
This means hrv_sleep can't be used as a sparkline card metric on the dashboard, only as a metric_card (which uses the baseline API).
Solution
Add contextual HRV support to getPeriodSummary(), similar to how queryMetricsBucketed() already handles them:
- Separate contextual HRV metrics from regular metrics in
getPeriodSummary - Compute stats (avg, min, max, count, stddev) from the contextual HRV data
- Include previous period comparison for trend calculation
Affected files
apps/backend/src/services/queries.ts—getPeriodSummary()functionapps/web/src/state/api.ts— addfetchHrvSleepfunctionapps/web/src/components/widgets/SparklineCardWidget.tsx— addhrv_sleepto fetcher mapspackages/api-spec/src/schemas/dashboard.ts— addhrv_sleeptodashboardMetricSchema
Context
The dashboard baseline was switched from hrv_rmssd (all-day) to hrv_sleep (sleep-only) since sleep HRV is the meaningful recovery indicator. The metric_card works via the baseline API, but upgrading to a sparkline with trend line requires this period summary support.