Skip to content

fix(analytics): serve the glucose indices as one figure on every platform - #1583

Merged
MBombeck merged 1 commit into
mainfrom
fix/glucose-index-stable-rounding
Nov 26, 2026
Merged

MBombeck merged 1 commit into
mainfrom
fix/glucose-index-stable-rounding

Conversation

@MBombeck

Copy link
Copy Markdown
Owner

LBGI and HBGI differed in the last digits between Node 22 (CI, production image) and Node 24+, so the launch-reads parity snapshots recorded on one failed on the other. Cause: Math.pow with a fractional exponent in the Kovatchev transform; V8 changed its pow between those versions, while Math.exp / Math.log did not.

  • Transform through exp(1.084 · ln ln BG); risk branches summed with Neumaier compensation (compensatedSum in src/lib/stats/central.ts).
  • SD, CV%, J-index, LBGI, HBGI served through roundStableTo at four decimals, on the per-reading engine and on the report's bucket path (Postgres sums). The Monnier flag reads the served CV.
  • Same class elsewhere: summarize() means (vs. the slice and the generate path's Postgres AVG), the mood day series and overview daily means (tier vs. fold), the BP recency weight (pow(0.5, x) → exp), and the Withings unit scaling (Math.pow(10, -4|-5) is a last bit off on Node 22).

Tests: a unit test that nudges Math.pow/exp/log by a few ulps, one that reverses tied readings, and one that pins the four-decimal figures; the first two were red before the change, and the pin passes on Node 22 and Node 26. Parity snapshots re-recorded (only sd, cv, jIndex, lbgi, hbgi change) and verified on Node 22 and Node 26.

No changelog line: the surfaces show CV% as a whole number and the indices to one decimal, so no shown value changes outside an exact-boundary case.

…form

LBGI and HBGI came back with different last digits on Node 22 than on
Node 24 and later, so parity snapshots recorded on one failed on the other.
The Kovatchev transform raised ln BG to 1.084 through Math.pow, and V8's
pow with a fractional exponent changed between those versions; Math.exp
and Math.log did not. The transform now runs through exp and log, the
risk branches are summed with Neumaier compensation (tied readings arrive
in no fixed order), and SD, CV%, the J-index, LBGI and HBGI are served
through roundStableTo at four decimals, on the per-reading engine and on
the report's bucket path, whose sums come out of Postgres. The Monnier
flag reads the served CV.

The same class elsewhere:
- summarize() rounds mean, avg7, avg30 and the prior-period means with
  roundStable2, like the summaries slice and the generate path's
  Postgres AVG over the same windows.
- The mood day series and the overview's daily means round with
  roundStable2: the rollup tier and the fold sum a day in different orders.
- The BP recency weight uses exp instead of pow(0.5, x).
- Withings divides by an exact power of ten for a negative unit;
  Math.pow(10, -4) and (10, -5) are a last bit off on Node 22.

The launch-reads and analytics parity snapshots hold the stable values,
and pass on Node 22 and Node 26.
@MBombeck
MBombeck merged commit e74f659 into main Nov 26, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant