From aa6ec8ef2267799e045366e47339d472d26072ab Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Wed, 23 Sep 2026 13:28:58 -0400 Subject: [PATCH] Salud: a card opens onto the day, hour by hour, and onto the days before it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported as "le doy a cualquier actividad y solo me presenta los pasos de hoy… debiera presentarme una medida por hora, y no me da el histórico". Two separate things, and only one of them was the app's fault. **The history was the automation's setting.** With Date Range on its default (`Today`) every sync carries today and nothing else, so there is exactly one day in the file to draw. That is why a card looked frozen: not a rendering bug, a range that was never sent. The setup steps now say `Previous 7 Days` and say why. **The hours were thrown away by us.** Even when the phone sends 288 readings a day, the receiver folded every one of them into a single day aggregate, so "8,123 steps today" was all there could ever be — a number you cannot look into. Worse, the recommended setting was Time Grouping `Days`, which sends one point per metric per day: the intraday detail never arrived in the first place. The recommendation is now `Hours`, and the storage keeps the hours. The merge rule for them is the same shape as the day rule, for the same reason: a payload whose datapoints all sit on the hour is HAE's own hour grouping, and the hour *in progress* grows on every run of a five-minute automation, so it is replaced and never unioned — 500 + 900 + 1,340 steps in one hour is a number no watch recorded. The day is then recomputed as the sum of its hours, which is what keeps the card and the detail from ever disagreeing, and which also makes switching an automation from Days to Hours mid-day converge instead of double-count. Raw samples (real timestamps) still union by instant plus numbers, and they now land in their own hour, which is where intraday detail comes from when nothing is grouped. Three things that would have been silent bugs, caught while writing it: - The hour rule is decided from the **whole payload**, never from one timestamp. A five-minute automation produces samples that sit exactly on the hour, and reading one of those as an hour total wipes the hour it belongs to. There is a test with a 09:00:00 and a 09:05:00 sample in one payload, and it fails against the per-point version of the rule. - A day that arrived as a day total keeps its hours beside it, and a day stored before this existed keeps its aggregate when the first hour shows up — recomputing it from hours it does not have would delete 2,000 steps. Both are mutation-checked (removing either guard fails a test). - A payload grouped by hour writes the ledger row anyway, because a later payload with real minutes can describe the same instant and the union path can only see the ledger. Without it the raw-sample route test double-counts a single sample. The hours are the bulky part of this data, so they are kept for a week (the day aggregates still live the full 400 days), pruned when the night's file is written, and fetched one metric and one day at a time — `GET /api/vitals/hours`. A screen listing forty cards downloads none of them; the day view carries only a count per day, which is what tells the sheet whether it is worth asking. The sheet draws the hours, the days before it (tapping one moves the hour list to that day), and every field the watch sent; when the automation groups by Days it says so instead of leaving a gap where a chart should be. Coverage: 6 new tests in `api/test/vitals.test.js` (19 total) and a route test in `api/test/server-vitals.test.js` (5), the hour/history model in `vitals-view.test.js` (31), three render tests through the real sheet, the route documented in `api/openapi.yaml` and `website/api.html`, and `docs/HEALTH.md` with the settings, the new merge row and the two symptoms now in Troubleshooting. --- CHANGELOG.md | 21 ++- CLAUDE.md | 3 +- api/openapi.yaml | 100 +++++++++++- api/server.js | 14 +- api/test/server-vitals.test.js | 40 +++++ api/test/vitals.test.js | 143 ++++++++++++++++- api/vitals.js | 185 ++++++++++++++++++++-- docs/HEALTH.md | 44 +++-- frontend/src/lib/vitals-view.js | 79 +++++++-- frontend/src/lib/vitals-view.test.js | 79 ++++++++- frontend/src/locales/es.js | 7 +- frontend/src/views/Health.jsx | 66 +++++++- frontend/src/views/Health.render.test.jsx | 114 ++++++++++++- website/api.html | 7 +- 14 files changed, 839 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56812c..d19781f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,11 +23,26 @@ is re-sent), while real samples are identified by instant plus numbers and store every five minutes, hourly, or once a day all land the same way. `docs/HEALTH.md` has the settings, the merge table and the one configuration that is merely approximate rather than wrong. +The other half of that problem is **granularity**. "8,123 steps today" is a number you cannot look +into, and the phone that sent it sent 288 readings to build it. With *Time Grouping: Hours* each +hour arrives as its own bucket, and the receiver replaces that hour exactly the way it replaces a +day (the hour in progress grows on every run), then recomputes the day as the sum of its hours — so +the day total and the hourly detail can never disagree, and switching an automation from Days to +Hours mid-day converges instead of double-counting. Tapping a card now opens the day **hour by +hour**, the days before it, and every field the watch sent; when the automation still groups by +Days, the sheet says so rather than drawing an empty chart. The hours are kept for a week (the day +aggregates keep the full 400 days) and are fetched one metric and one day at a time, so a screen +showing forty cards does not download 24 buckets × forty metrics to draw a grid. `Date range` is +the setting that decides whether history exists at all: with HAE's default `Today`, yesterday is +never sent, which is exactly what a card frozen on a single day looks like — `Previous 7 Days` is +what the setup steps now say. + Also here: the watch's workouts are shown **read-only** in Salud and deliberately kept out of the history — they carry no sets or weights, so folding them into progression, PRs and the recovery -model would be inventing data. Coverage: `api/vitals.js` (13 tests), the routes against a real -server (4), the card model (18), plus the endpoint documented in `api/openapi.yaml` and the new -`docs/HEALTH.md` setup guide. +model would be inventing data. Coverage: `api/vitals.js` (19 tests), the routes against a real +server (5), the card model and its hour/history rows (31), the screen and its detail sheet (12 +render tests), plus the endpoints documented in `api/openapi.yaml` and the new `docs/HEALTH.md` +setup guide.