Skip to content

Calculate Insulin Effects accurately by taking into account ISF according to the schedule#588

Open
motinis wants to merge 9 commits intoLoopKit:devfrom
motinis:accurate-insulin-effects
Open

Calculate Insulin Effects accurately by taking into account ISF according to the schedule#588
motinis wants to merge 9 commits intoLoopKit:devfrom
motinis:accurate-insulin-effects

Conversation

@motinis
Copy link

@motinis motinis commented Feb 22, 2026

Loop has historically used the ISF at the start of a dose to determine the ISF for the lifetime of the dose, ignoring changes to ISF (whether according to the regular schedule or via overrides).

This contribution changes this to using ISF over the lifetime of the dose. It does this by splitting the calculation in 2 parts:

  1. The drop in IOB for a given dose over time
  2. Multiplying the IOB drop for each "bin" by the constant ISF for that bin (where bins are typically 5 minutes, but can be less, if there happens to be a change in ISF).

Dosage determination is handled by considering the glucose effect change that would happen if giving 1U, and then scaling this to match Loop's existing criteria.

Note that the interpolation during dose determination is done for consistency, even though unitGlucoseEffect should be aligned on the same dates. The interpolation logic was originally implemented in #562 before being generalized in motinis@3040b7b and simplified for 1 value - it is designed to support interpolation as part of a loop where we want to continue to search for the next relevant data point(s) from where we left off at the previous iteration (so as to have O(n) behavior in the length of the data and not O(n^2)).

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