Skip to content

Show how long the current setup has been unchanged, and its last change - #2618

Merged
ps2 merged 8 commits into
next-devfrom
feature/current-setup
Oct 28, 2026
Merged

ps2 merged 8 commits into
next-devfrom
feature/current-setup

Conversation

@ps2

@ps2 ps2 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Settings gets a Current Setup row under Statistics showing how long the setup has been unchanged and what the last change was, e.g. "5 days · Last change: Carb Ratios". It opens a screen with the time since the last change, its date, what changed, and a note that about 2 weeks with the same setup is a good amount of time to see a change in outcomes.

This is the first step toward comparing your results before and after a change, and later toward sharing that data with the developers. Both of those build on this date.

Settings Current Setup
row detail

What counts as a change

The last change is found in the settings history Loop already stores (90 days), by comparing consecutive records:

  • basal rates, insulin sensitivities, carb ratios, correction range, pre-meal range, glucose safety limit and delivery limits
  • insulin type and model
  • dosing strategy
  • turning an algorithm experiment on or off

Not counted: running a preset, turning closed loop on or off, alerts and notifications, devices, the glucose unit and the time zone.

Details:

  • Schedules are compared by their values. A value saved in the other glucose unit counts as the same within 2%, which covers the rounding to 0.1 mmol/L.
  • Changes within an hour of the latest one are reported together, as one edit.
  • With no change in the history, the screen says the setup has had no change recorded since the oldest record, and the time reads "at least …".

Experiments

Experiment changes come from the experiments recorded on each dosing decision, which builds since LoopKit/LoopWorkspace#534 store. That covers changes made before this build, and it uses the experiments actually in effect, so Glucose Based Partial Application turns off with automatic bolus. Decisions from older builds, which recorded nothing, are skipped. The experiment transitions are cached in UserDefaults, so each decision is read once. The 2-week note also appears on the Algorithm Experiments screen.

SetupHistory lists every change from both sources, oldest first, each with the date of the change before it. The Current Setup row uses the latest; #2619 uses the rest.

Needs LoopKit/LoopKit#669 (getDosingDecisions(start:end:as:)).

Testing

  • 12 SetupChangeTests: change detection, grouping, ignored fields, units, the pump's missing insulin type, experiment changes from dosing decisions, grouping with settings changes, and the cache reading each decision once. All pass.
  • Built with the LoopWorkspace scheme and checked in the simulator: turning Guard + Runway off updated the row to "1 minute · Last change: Guard + Runway turned off".
  • A therapy settings change was not checked in the UI; the tests cover that comparison.

ps2 added 2 commits October 26, 2026 22:35
Settings gets a Current Setup row under Statistics, e.g. "5 days · Last
change: Carb Ratios". It opens a screen with the time since the last
change, its date, what changed, and a note that about 2 weeks with the
same setup is a good amount of time to see a change in outcomes.

The last change is found in the stored settings history by comparing
consecutive records: basal rates, insulin sensitivities, carb ratios,
correction range, pre-meal range, glucose safety limit, delivery limits,
insulin type and model, and dosing strategy. Schedules are compared by
their values, not their time zone. Changes within an hour of the latest
are reported together. Presets, closed loop, alerts, devices and the
glucose unit don't count. With no change in the history, the setup is
unchanged since at least the oldest record.

Turning an algorithm experiment on or off records the time and which
one. An experiment that was already on before this build counts from the
first launch that sees it, as a lower bound.
The stored insulin type comes from the pump's status, which has none
while the pump is being replaced or hasn't loaded yet, so the history
flips between a type and none. Carry the last known type across those
gaps and only count a change from one type to another.
@ps2

ps2 commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

Added c0a7651: the stored insulin type comes from the pump's status, which has none while the pump is being replaced or hasn't loaded, so the history flipped between a type and none and showed up as "Insulin Type" changes. The last known type is now carried across those gaps, and only a change from one type to another counts. Found by decoding a simulator's settings history.

The Current Setup screen now opens with a summary, e.g. "It's been 5 days
since your last setup change: Carb Ratios. Compared with the 2 weeks
before it, time in range rose from 68% to 79%, and time below 70 mg/dL
stayed about the same at 5.6%." Below it are time-in-range bars for both
periods, before and after values for time in range, time below 70,
average glucose and insulin per day, and the median glucose by time of
day before (dashed) and since (solid) the change.

The before period is the 14 days before the change, cut short at the
change before it so it covers one setup. It's left out with less than a
day or less than 70% CGM data. Results start a day after the change, and
while the setup has run under 2 weeks the summary says the numbers can
still change a lot. Insulin per day is shown only where the dose records
cover the period.
ps2 added 5 commits October 27, 2026 00:41
…story

Experiment changes now come from the experiments recorded on each dosing
decision instead of a date saved when a switch is flipped. That covers
changes made before this build, back to the builds that started recording
experiments, so an experiment that's on no longer counts from the first
launch as "at least". It also uses the experiments actually in effect, so
Glucose Based Partial Application turns off with automatic bolus.

SetupHistory lists every change from both sources, oldest first, grouping
changes within an hour, each with the date of the change before it. The
experiment transitions read from dosing decisions are cached, so each
decision is read once. Needs LoopKit/LoopKit#669.
Merges feature/current-setup (#2618), whose SetupHistory
replaces this branch's single latest change.

The Current Setup screen gets a Setup History list: every change, newest
first, with its date, how long that setup ran, what changed and its time
in range. Tapping one compares that setup, from its change to the next
one, with the period before it. The latest is selected at first. Glucose
and insulin are read once for the whole history, so switching is instant.
Compare outcomes since the last setup change with the period before it
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