Skip to content

Dashboard: Support hrv_sleep sparkline (period summary for contextual HRV) #224

@fiddur

Description

@fiddur

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:

  1. Separate contextual HRV metrics from regular metrics in getPeriodSummary
  2. Compute stats (avg, min, max, count, stddev) from the contextual HRV data
  3. Include previous period comparison for trend calculation

Affected files

  • apps/backend/src/services/queries.tsgetPeriodSummary() function
  • apps/web/src/state/api.ts — add fetchHrvSleep function
  • apps/web/src/components/widgets/SparklineCardWidget.tsx — add hrv_sleep to fetcher maps
  • packages/api-spec/src/schemas/dashboard.ts — add hrv_sleep to dashboardMetricSchema

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions