Skip to content

Compare outcomes since the last setup change with the period before it - #2619

Merged
ps2 merged 4 commits into
feature/current-setupfrom
feature/setup-results
Oct 28, 2026
Merged

ps2 merged 4 commits into
feature/current-setupfrom
feature/setup-results

Conversation

@ps2

@ps2 ps2 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Builds on #2618 (based on its branch; retarget to next-dev once it merges).

The Current Setup screen now shows how things have gone since the last setup change, compared with the period before it.

Summary Results
summary results

Screenshots use synthetic glucose for 19 days, injected by a local patch that isn't in this PR, since the simulator only has two days of history.

What it shows

  • Summary: "It's been 5 days since your last setup change: Carb Ratios and Guard + Runway turned on. 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%. With less than 2 weeks so far, these numbers can still change a lot."
  • Time-in-range bars for the period before the change and the period since.
  • Before → since for time in range, time below 70, average glucose and insulin per day.
  • Median glucose by time of day, dashed before and solid since, with the 25–75% band since the change.

How it's computed

  • Before period: the 14 days before the change, cut short at the change before that, so it only covers one setup. SetupChange now carries previousDate for this. Settings history provides it for settings changes; for an experiment change, the latest settings change before it is used.
  • Leaving the comparison out:
    • Results start a day after the change.
    • The before period is skipped if it's shorter than a day or has less than 70% CGM data, and the summary says so.
    • The summary notes when CGM covers less than 70% of the time since the change.
  • "About the same": time in range within 1 point, or time below 70 within 0.5 points.
  • Insulin per day is shown only where the dose records cover the whole period.
  • Glucose uses the same filtering as Statistics: no display-only or user-entered readings. Time in range and the percentiles come from GlucoseStatistics.

Testing

  • 8 new SetupComparisonTests: windows, the previous-change cutoff, missing before data, the one-day wait, lower bounds, insulin per day and dose coverage. All 19 setup tests pass.
  • Built with the LoopWorkspace scheme and checked in the simulator against real history (after the insulin type fix in Show how long the current setup has been unchanged, and its last change #2618, the row reports the real last change) and with the synthetic data above.

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.
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.
@ps2

ps2 commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator Author

Added ed32171, which merges #2618's branch and adds Setup History:

  • The list: every setup change, newest first. Each row shows the date, how long that setup ran, what changed and its time in range.
  • Tapping a row: compares that setup, from its change to the next one, with the 14 days before it, cut at the change before that. The latest is selected at first.
  • Past setups: the summary reads "The setup from Oct 25 ran for 9 days, after a change to Dosing Strategy. Compared with the 2 weeks before it, …". A setup that ran less than a day says it's too short to compare.
  • Speed: glucose and insulin are read once for the whole history, so switching rows is instant.

The history now comes from the settings history plus the experiments recorded on each dosing decision (#2618, LoopKit/LoopKit#669). Changes made before this build show up too.

History (simulator, real data) A past setup selected
history selected

Tests: 21 setup tests pass, including a new one for a past setup ending at the next change.

@ps2
ps2 merged commit 1db72c6 into feature/current-setup Oct 28, 2026
@ps2
ps2 deleted the feature/setup-results branch October 28, 2026 02:32
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