Salud: a card opens onto the day, hour by hour, and onto the days before it
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
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.
This commit is contained in:
1 parent
34d28fa5c5
commit
aa6ec8ef22
14 files changed
+839
-63
No files matched your search
@@ -211,6 +211,46 @@ test('a raw-sample automation accumulates a day without double counting, and a f
|
||||
assert.deepEqual(narrow.metrics.step_count.days.map(d => d.day), [today]);
|
||||
});
|
||||
|
||||
test('GET /api/vitals/hours opens one metric\'s day, and only with a session', async t => {
|
||||
const h = await startServer(t);
|
||||
const key = (await (await fetch(`${h.api}/api/vitals/key`, { method: 'POST', headers: cookie('u_h1') })).json()).key;
|
||||
const read = async q => (await (await fetch(`${h.api}/api/vitals/hours?${q}`, { headers: cookie('u_h1') }))).json();
|
||||
|
||||
// Signed out, and with the write-only ingest key, there is nothing to read here either.
|
||||
assert.equal((await fetch(`${h.api}/api/vitals/hours?metric=step_count&day=${today}`)).status, 401);
|
||||
assert.equal((await fetch(`${h.api}/api/vitals/hours?metric=step_count&day=${today}`, { headers: { Authorization: `Bearer ${key}` } })).status, 401);
|
||||
|
||||
// "Time Grouping: Hours" beside a metric the phone totals by day.
|
||||
await ingest(h, key, { data: { metrics: [
|
||||
{ name: 'step_count', units: 'count', data: [
|
||||
{ qty: 500, date: `${today} 08:00:00 +0000` },
|
||||
{ qty: 900, date: `${today} 09:00:00 +0000` }
|
||||
] },
|
||||
{ name: 'weight_body_mass', units: 'kg', data: [{ qty: 80.5, date: `${today} 00:00:00 +0000` }] }
|
||||
] } });
|
||||
|
||||
const hours = await read(`metric=step_count&day=${today}`);
|
||||
assert.equal(hours.ok, true);
|
||||
assert.deepEqual(hours.hours.map(x => x.h), ['08', '09'], 'oldest hour first');
|
||||
assert.deepEqual(hours.hours.map(x => x.f.qty.sum), [500, 900]);
|
||||
assert.equal(hours.units, 'count');
|
||||
|
||||
// The day view still reads a day as one number, and now says whether there is anything behind it.
|
||||
const day = (await (await fetch(`${h.api}/api/vitals?days=1`, { headers: cookie('u_h1') })).json()).metrics.step_count.days[0];
|
||||
assert.equal(day.f.qty.sum, 1400);
|
||||
assert.equal(day.hours, 2);
|
||||
|
||||
// A metric the phone grouped by day has no hours, and neither does a day nobody sent.
|
||||
assert.deepEqual((await read(`metric=weight_body_mass&day=${today}`)).hours, []);
|
||||
assert.deepEqual((await read(`metric=step_count&day=2000-01-01`)).hours, []);
|
||||
assert.equal((await read(`metric=step_count&day=2000-01-01`)).day, null);
|
||||
// A day that is not a date is not looked up at all (nothing here builds a path from input).
|
||||
const bogus = await read('metric=step_count&day=not-a-day');
|
||||
assert.equal(bogus.day, null);
|
||||
assert.deepEqual(bogus.hours, []);
|
||||
assert.equal((await read('metric=nope&day=' + today)).metric, null);
|
||||
});
|
||||
|
||||
test('DELETE /api/vitals wipes the health file and leaves the account, the key and the workouts alone', async t => {
|
||||
const h = await startServer(t);
|
||||
const key = (await (await fetch(`${h.api}/api/vitals/key`, { method: 'POST', headers: cookie('u_h1') })).json()).key;
|
||||
|
||||
Reference in new issue
Block a user