mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 05:12:14 +00:00
Apple Health stores sleep as one Measurement row per stage per night, so the existing single-value SLEEP_DURATION summary would treat each stage as its own datapoint and grossly understate the per-night total. The route now sums per Berlin day before summarising — one summary datapoint per night, value equal to total minutes asleep. A new optional `sleepStages` block surfaces the per-stage breakdown over the trailing 30 days when stage-tagged rows exist (and `null` otherwise so the existing UI keeps painting the totals-only path). The block reports total minutes, the night count covered, and the per-stage minute sums so the upcoming insights surface can render "averaged across N nights" captions truthfully. Two integration tests cover both shapes — a four-stage night aggregating to 880 minutes with a populated stages map, and a manual-source no-stage row keeping `sleepStages` at null. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>