Skip to content

Fix delta-scale IOB ripple for basal segments longer than delta#35

Open
ps2 wants to merge 1 commit into
tidepool-org:mainfrom
ps2:fix/iob-basal-segment-ripple
Open

Fix delta-scale IOB ripple for basal segments longer than delta#35
ps2 wants to merge 1 commit into
tidepool-org:mainfrom
ps2:fix/iob-basal-segment-ripple

Conversation

@ps2

@ps2 ps2 commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

continuousDeliveryInsulinOnBoard quantized its integration bound to the delta grid (floor((time + delay) / delta) * delta), so a whole chunk was added discontinuously each time time crossed a delta boundary. This produced a delta-scale ripple in insulinOnBoard for any basal segment longer than one delta -- i.e. essentially every real temp basal / suspend (median ~10 min in real dose histories).

Integrate the delivered fraction up to time, weighting a partial final chunk, and sample each chunk's remaining-effect at its midpoint. IOB is now continuous and matches a finely-subdivided equivalent delivery.

Scoped to the insulinOnBoard path; glucoseEffect (and therefore dosing) is unchanged. Adds a regression test. All package tests pass.

continuousDeliveryInsulinOnBoard quantized its integration bound to the
delta grid (floor((time + delay) / delta) * delta), so a whole chunk was
added discontinuously each time `time` crossed a delta boundary. This
produced a delta-scale ripple in insulinOnBoard for any basal segment
longer than one delta -- i.e. essentially every real temp basal / suspend
(median ~10 min in real dose histories).

Integrate the delivered fraction up to `time`, weighting a partial final
chunk, and sample each chunk's remaining-effect at its midpoint. IOB is
now continuous and matches a finely-subdivided equivalent delivery.

Scoped to the insulinOnBoard path; glucoseEffect (and therefore dosing)
is unchanged. Adds a regression test. All package tests pass.
@ps2

ps2 commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator Author

This is mostly a display issue; dosing is not changed. See the field dosing in the first pic, and how it is smoother in the second.

Screenshot 2026-07-12 at 2 20 34 PM Screenshot 2026-07-12 at 2 20 39 PM

@ps2 ps2 requested review from Camji55 and nhamming July 12, 2026 19:22

@nhamming nhamming left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

2 participants