Files
HealthLog/src/lib/measurements/vital-precision.ts
T
Marc-André Bombeck aa222f5b02 fix(daily): speak about today only from today's readings
A statement that says "today", or compares today against a baseline,
now only rests on a reading taken on the current calendar day in the
reader's zone. Yesterday morning's pulse read at nine in the evening
was narrated as today's: the signals of the day accepted any reading
from the last two weeks, and the Today overview, the coincident
deviation flag and the health status counted yesterday as current.

- computeSignalsOfDay drops a metric with no reading today, so the
  briefing prompt and its content hash never see a stale value as the
  day's; the prompt says so in both languages.
- The digest serves no cached briefing written on an earlier day and
  drops a reading-backed signal whose metric was not measured today,
  so the web hero, the iOS topSignal and the morning push agree.
- The Today overview's vitals line and deterministic lead, the
  coincident flag and the health status deviations use the new
  isFromToday rule (calendar day, not elapsed hours).

Signal deltas now carry each metric's display precision: the prompt
input is rounded (whole bpm and mmHg, one decimal of kg), and the
delta string under the hero lead is re-read at that precision in the
reader's locale ("+34 bpm", not "+33,72 bpm").
2026-10-05 21:22:57 +02:00

38 lines
1.3 KiB
TypeScript

/**
* Decimal places a vital reading is shown at, in the unit it is shown in.
*
* The transform's own `decimals` covers the converted units (lb, °F,
* mmol/L); body temperature and weight read at one decimal; the rest
* (pulse, blood pressure, HRV, SpO2, respiratory rate, the cumulative
* same-hours metrics) are whole numbers on every device and in every chart
* that shows them.
*
* One answer for every server-side text that prints a vital or a difference
* of one: the Today overview's value and range labels, the signals of the
* day the briefing prompt is given, and the delta under the hero lead. A
* difference is read at the precision of the readings it was taken from, so
* "+34 bpm", never "+33.72 bpm".
*/
export function vitalDisplayDecimals(
type: string,
transformDecimals: number,
): number {
switch (type) {
case "BODY_TEMPERATURE":
case "SKIN_TEMPERATURE":
case "WEIGHT":
return 1;
case "BLOOD_GLUCOSE":
return transformDecimals;
default:
return 0;
}
}
/** Round to `decimals` fraction digits. Non-finite input passes through. */
export function roundToDisplay(value: number, decimals: number): number {
if (!Number.isFinite(value)) return value;
const scale = 10 ** decimals;
return Math.round(value * scale) / scale;
}