Skip to content

[1/8] Add a Trends screen that replaces Statistics - #2637

Open
Nutcasey wants to merge 25 commits into
LoopKit:next-devfrom
Nutcasey:redesign-1-trends
Open

Nutcasey wants to merge 25 commits into
LoopKit:next-devfrom
Nutcasey:redesign-1-trends

Conversation

@Nutcasey

@Nutcasey Nutcasey commented Nov 1, 2026 •

Copy link
Copy Markdown

Part 1 of the series splitting #2621. Updated after Pete's review (3 November 2026): Trends now replaces Statistics, each figure appears once, and the day page, Gaps and Export have moved to follow-up parts. Updated again on 7 November 2026 for Pete's second review and the contrast request: see Colours and the first set of screenshots. Updated on 13 November 2026 for Pete's third review: Trends' glucose figures now come from GlucoseStatistics, CGM coverage is measured by time, and the new strings are English only.

Trends reviews one period at a time: a day, 7, 14, 30 or 90 days. It opens from Settings → Trends, where Statistics was, as a sheet with a Done button.

  • Summary: average glucose with SD and CV, GMI (with its IFCC value for people using mmol/L), carbs per day and boluses per day. Each tile carries its target.
  • Time in range: the share of time in five bands, each with its target in its row and its hours a day of CGM-covered time.
  • Daily pattern (AGP).
  • Insulin: daily totals with the average, basal against its schedule, bolus split into manual, automatic and unknown, and "today so far, usually X U by now" when the period ends today.
  • Loop status: closed loop, limited and open loop, from Loop's stored settings.
  • One day: a one-day period leads with that day's timeline.

Trends after the 7 November update, overview

Where the figures come from

  • Inside Loop's local history (the cache duration, 90 days by default) figures come from Loop's stores. For each kind of data the boundary is the later of the cache start and Loop's first record of that kind; before it, Trends reads Apple Health. The two never overlap.
  • Closed and open loop come from StoredSettings.dosingEnabled, which SettingsStore keeps for the cache duration, including the record before the period. A manual temp basal counts as open loop, as on the home screen since Show the loop as open while a manual temp basal is running #2649, from the temp basal's own record and its end or cancellation.
  • Manual and automatic are read from each bolus's own record. A bolus that doesn't record it shows as unknown, never as manual. Logged injections count as manual.
  • Scheduled basal is shown only for days Loop has its own schedule history, with "N of M days" when that's part of the period. Older days don't fall back to today's schedule. Dated settings bound both basal and target schedules: time before the first saved profile, or a saved record without that profile, stays unknown. Those gaps supply neither scheduled totals nor inferred basal delivery.
  • GMI always shows, with mmol/mol only when glucose is in mmol/L. "Best over 14 days with 70% CGM data" appears when the period is shorter or coverage is lower (the 2019 international consensus and ADA 2026 guidance).
  • Glucose statistics come from GlucoseStatistics, which Current Setup also uses: mean, SD, CV, GMI, time in range and the daily pattern. Time in range weights each reading by the time until the next, with gaps capped. The band edges are ..<181 and ..<251 mg/dL, so 10.0 mmol/L is in range and 13.9 mmol/L is high.
  • CGM active is measured by time. Each reading covers the time until the next one, up to five minutes, so a CGM that reports every minute counts only the minutes it reports.
  • mmol/L uses LoopKit's conversion factor, as Loop's other screens do.
  • Fingerstick readings are left out of every figure, as in Statistics. When Apple Health readings are thinned, a fingerstick never takes the place of the CGM reading beside it.

Colours

No new colour sets. Marks use Loop's existing glucose, insulin, carbs and accent; the AGP bands, target band and basal fill are those colours at reduced opacity. Time in range uses GlucoseBand.agpColor, which gains dark-mode variants (Current Setup picks these up). The period picker is a system segmented Picker.

Insulin is one colour, told apart by shape. Bolus is solid, automatic bolus is hatched and basal is an outline with a faint wash. insulin is 2.2:1 on white, so no lighter tint of it reaches 3:1 against it, and faded orange on a dark card always looks brown. Basal was already insulin at 25%, and that's what looked brown in dark mode. Statistics' 35%, 65% and 100% gives neighbouring marks 1.27:1 and 1.30:1 in light and 1.84:1 and 1.82:1 in dark, with basal #765421 in dark. Over one day, basal is a plain 25% fill, because an outline along its steps looks like small boluses. That fill still looks slightly brown in dark mode.

Text. Primary text is label. Muted text is inkMuted, black at 70% in light and white at 85% in dark, to meet WCAG AAA for normal text (7:1). secondaryLabel can't reach that here.

Muted text Light before Light after Dark before Dark after
On a Summary tile 3.20:1 7.90:1 4.11:1 7.56:1
On a card 3.44:1 8.59:1 5.29:1 10.56:1

Measured from simulator captures of the 14-day view, using the WCAG relative-luminance formula.

Still below these targets:

  • The selected segment of the system picker in dark mode is 5.45:1.
  • SetupComparisonCharts.swift (Current Setup) still has .secondary text that this PR doesn't change.
  • Insulin marks are 2.2:1 on a white card, below WCAG 1.4.11's 3:1 for graphics. AAA's text rule doesn't apply to them.
  • inkMuted doesn't respond to Increase Contrast, though it's already above 7:1.

Commits

The first two are the original Trends and Statistics-parity commits. The branch is rebased onto next-dev 698fb063 (21 November 2026). The review changes follow, one commit per point so each can be reviewed on its own:

  1. Replace Statistics with Trends
  2. Move the day page, Gaps and Export to follow-up parts
  3. Show each Trends figure once
  4. Show targets beside their figures instead of Aim lines
  5. Use Loop's existing colours in Trends
  6. Read closed and open loop from stored settings
  7. Follow the cache duration and mark partial older periods
  8. Stack Trends rows at the largest text sizes
  9. Remove the unused ValueTile
  10. Fix issues found testing the review changes
  11. Tighten dose boundaries and use a darker bolus colour
  12. Keep unrecorded schedule history unknown in Trends (Codex review)
  13. Keep chart labels readable at accessibility sizes (Codex review)
  14. Show the GMI's mmol/mol line only with mmol/L (Pete's second review)
  15. Tell insulin apart by shape instead of a darker bolus (Pete's second review)
  16. Raise Trends' muted text to WCAG AAA contrast (contrast request)
  17. Keep Trends' new strings English-only (Pete's third review)
  18. Use GlucoseStatistics for Trends' glucose figures (Pete's third review)
  19. Measure CGM coverage by time rather than by reading count (Pete's third review)
  20. Keep CGM readings beside fingersticks when thinning Health glucose (Pete's third review)
  21. Say why only temp basals marked not automatic count as manual (Pete's third review)
  22. Convert Trends' mmol/L with LoopKit's factor (found testing the third review)
  23. Give Trends' test doses a dose id (for Send each dose with a dose id and keep its metadata in Loop #2675, after the 22 November rebase)

Screenshots

Annotated, from the loop simulator's demo data on this PR's latest commit. "Before" is 596606a2 for insulin and the build with the insulin change for contrast. The 14-day insulin captures end a day apart, so their totals differ. Most of the demo's older boluses have no manual/automatic flag, so they draw solid.

GMI in mg/dL and mmol/L

Summary text contrast before and after

Insulin marks in light mode, before and after

Insulin marks in dark mode, before and after

One-day timeline, before and after

Also: 30 and 90 days, one day's insulin bar, largest text.

Screenshots from the 3 November review

Annotated, with before and after where something was removed. These predate the 7 November colour and text changes, so their colours, contrast figures and the mmol/mol line in mg/dL no longer apply. From the loop simulator's demo data; its seeded boluses before 26 October have no manual/automatic flag, which is why much of the 14-day bolus shows as unknown.

Trends replaces Statistics Summary with aims in tiles Targets in each row

One Insulin card Loop status from stored settings One day, timeline only

N of M days notes Apple Health footnote Apple Health before Loop's first records

Colours, light Colours, dark Largest text

Also: Current Setup still working, Boluses tile with unknown.

Testing

On the loop simulator (iOS 27.0, Pump and CGM Simulators, 90 days of history), based on next-dev f7b08cad:

  • 1, 7, 14, 30 and 90 days; previous and next; an older week from Apple Health; a week across the local/Health boundary; an empty period; light, dark and AX XXXL.
  • Apple Health filling days before Loop's first local records, checked by removing early local records from a copy of the store.
  • Settings → Trends → Done, and Current Setup still working.
  • Codex follow-up: AX XXXL chart labels use fewer ticks with the end dates anchored inside the plot; card titles and subtitles stack.
  • 7 November update: 14, 30 and 90 days and one day in light and dark; 14 days at AX XXXL; GMI in mg/dL and mmol/L, with data and with none. The colour change wasn't re-run against the older Apple Health periods.
  • 13 November update:
    • Trends checked on one day, 14 days and a 30-day period read from Apple Health, plus Current Setup.
    • Every glucose figure matches an independent calculation from the simulator's glucose store and Health database: CGM active, mean, SD, CV, GMI and time in range.
    • With the CGM Simulator set to 1-minute readings and 3 hours backfilled into a day with an overnight gap, Trends shows 35% CGM active and 3.0 h in range. The old count-based method gives 100% and 8.8 h.
    • Dark mode, AX sizes and mg/dL weren't re-run, as no layout or colour code changed.

Selected LoopTests: 460 run, 458 pass, re-run on 13 November with these changes. The two failures are BolusEntryViewModelTests.testCarbEntryDateAndAbsorptionTimeString and …String2, which fail the same way on plain next-dev ("12:00 PM" against "12:00"). LoopHistoryMathTests covers the boundary, manual temp basal, GMI and classification rules. The Codex follow-up adds a real-SettingsStore regression for schedule start dates, missing profiles and the preceding setting; restoring the old queries reproduces 5 U instead of the correct 3 U. LoopDataManagerTests passes 28/28, LoopHistoryMathTests 31/31, GlucoseStatisticsTests 16/16 and SetupComparisonTests 8/8. New tests cover the band edges for mmol/L readings, coverage with 1-minute readings, and a fingerstick beside a CGM reading. HealthKit-hosted DeviceDataManagerTests were not run.

22 November 2026: rebased onto next-dev 698fb063, which includes #2652, so the branch builds on its own. The 22 earlier commits applied without conflicts. #2675 renamed DoseEntry(decisionId:), so commit 23 updates the Trends tests. On the loop simulator, Trends opened from Settings and showed the 14-day and one-day views. In the isolated harness, 471 LoopTests ran; the only failures were the two clock-format assertions.

Strings. New keys are English only, for Loop's translators to pick up through Lokalise. Existing keys, including the alarm names "High" and "Low", are unchanged from next-dev. Statistics' strings and those only the moved screens used are removed.

Moved to later parts

The series

#2621 is split into eight PRs in the order Pete suggested: statistics and Trends first, then the Logbook, then the home screen. Each part builds on the one before it and targets next-dev, so a PR shows the earlier parts' commits too. #2621 stays open as the combined reference until the series lands.

  1. [1/8] Add a Trends screen that replaces Statistics #2637 Trends, opened from Settings, replacing Statistics
  2. [2/8] Add a Logbook of the last 7 days #2638 Logbook, opened from Settings
  3. [3/8] Add the Now home screen with Now, Trends, Logbook and Settings tabs #2639 Now home screen with Now, Trends, Logbook and Settings tabs, and the New Interface toggle
  4. [4/8] Rebuild Add carbs around a live preview of the meal #2640 Redesigned Add carbs
  5. [5/8] Restyle the widget, Dynamic Island and Live Activity for the new interface #2641 Widget, Dynamic Island and Live Activity
  6. [6/8] Add Day and Night app icons and an appearance setting #2642 Day and Night app icons and the appearance setting
  7. [7/8] Add a day page and a list of Loop's gaps #2696 Day page and Gaps
  8. [8/8] Export Trends as a PDF report or a CSV of each day #2697 Export: PDF report and CSV

Rebuilt on 22 November 2026. Parts 2–8 were rebuilt on this part as it stands now. They follow the same rules: Loop's existing colours and no new colour sets in the app, new strings in English only, and loop mode read from Loop's stored settings. Each lists where it differs from #2621.

Merging. With squash merges, each next PR needs a rebase onto next-dev once the previous one lands. I'll rebase each PR as the one before it merges.

Strings. Each part adds only its own catalogue entries, in English only. GitHub's line diff of Localizable.xcstrings can show deletions where Xcode's ordering interleaves new keys.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG

@ps2 ps2 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for splitting this up. Trends reads well and the Statistics parity work is careful. Before this goes further I'd like to shrink it and remove the overlap with Statistics.

Replace Statistics. Trends should replace Statistics in this PR rather than sit beside it in Settings. Two screens answering the same question will confuse people, and the parity commit already covers what Statistics shows. Please remove the Statistics entry and the screen as part of this change.

Duplicated figures. Several numbers appear two or three times on one page:

  • Insulin per day and the basal/bolus split are in the Summary tile, the Basal and bolus card, and the Insulin per day chart's average line and legend. Could Summary stay focused on glucose (plus carbs and boluses), and Basal and bolus fold into the Insulin per day card, with Scheduled and Manual/Automatic under the chart?
  • Loop active in Summary repeats the Loop status card, and it covers a different window from the period's other figures. It's clearer only in Loop status, beside its coverage note.
  • "Usually X U by HH:MM" appears twice. One place is enough.

Aim lines. The Aim sentences, especially the six-target one under Time in range, are hard to scan. Showing each band's target in its row, or marking a figure that misses its target, would say the same with less text.

Colors. The PR adds 17 named colors, and most could reuse what Loop already has. glucose-ink, accent-ink, insulin-ink, bolus and carbs-ink are variants of the existing glucose, accent, insulin and carbs colors. agp-inner, agp-outer, target-band, basal and basal-edge can be those colors at reduced opacity, with no new color sets. ink-muted can be .secondary. The five range-* colors duplicate GlucoseBand.agpColor in Statistics (TimeInRangeBar.swift). Since Trends replaces Statistics, keep one time-in-range palette; your dark-mode variants are an improvement, so move them there. control-thumb goes away with a system segmented Picker.

Scope. Could the day page, Gaps and Export come as follow-up parts? Export in particular produces a shareable, clinical-looking report that deserves its own review.

Open/closed loop history. Loop keeps 90 days of data (Bundle.main.localCacheDuration, LOOP_LOCAL_CACHE_DURATION_DAYS), and localHistoryStart already uses it. Rather than a new UserDefaults record (LoopModeHistory, 100 days), please read closed/open loop from data Loop already stores. StoredSettings carries dosingEnabled with a date, and SettingsStore keeps those records for the cache duration. The provider already uses getStoredSettings for target history. If that doesn't work out, a new record should follow the other stores' design (Core Data in the cache store, expiring with localCacheDuration) rather than live in UserDefaults.standard. It's also worth checking that every closed-loop toggle path saves settings, so the history isn't missing changes.

"Loop keeps 7 days". Two strings hard-code this: the Loop status footnote and the day page's Apple Health note. The provider's window is localHistoryStart, which is the cache duration, 90 days by default, so the text is wrong for most builds. It should follow the cache duration rather than hard-code a number.

Older periods. For days beyond Loop's local history, how does the screen show that the Manual/Automatic split and the scheduled basal are partial or estimated?

Nutcasey added a commit to Nutcasey/Loop-1 that referenced this pull request Nov 3, 2026
@Nutcasey Nutcasey changed the title [1/6] Add a Trends screen for glucose, insulin and Loop status [1/8] Add a Trends screen that replaces Statistics Nov 3, 2026
@Nutcasey

Nutcasey commented Nov 3, 2026

Copy link
Copy Markdown
Author

Thanks, Pete. I've taken almost all of this, one commit per point (listed in the description). Point by point:

1. Replace Statistics

Trends should replace Statistics in this PR rather than sit beside it in Settings.

Done. The Statistics entry and screen are removed: StatisticsView, StatisticsViewModel, AGPChartView, DailyInsulinChartView and the TimeInRangeBar view, with their strings and the two README screenshots. Trends takes Statistics' place in Settings, above Current Setup.

Everything Current Setup shares with Statistics stays: the GlucoseBand display extension (now GlucoseBand+Display.swift), SetupComparisonCharts, GlucoseStatistics, InsulinDeliveryHistory and their tests.

Trends replaces Statistics

2. Duplicated figures

Could Summary stay focused on glucose (plus carbs and boluses)…

All three are done:

  • Summary is now Average, GMI, Carbs per day and Boluses per day.
  • Insulin per day is one card: the daily bars with the average line, then Basal with Scheduled under it, Bolus with Manual / Automatic under it, and Total. The rows double as the chart's legend.
  • Loop active is only in Loop status, beside its coverage note.
  • "Usually X U by HH:MM" appears once, under the Insulin card when the period ends today.

Summary Insulin card

3. Aim lines

Showing each band's target in its row, or marking a figure that misses its target, would say the same with less text.

The Aim sentences are gone. Each target sits beside its figure, muted:

  • Summary tiles: "aim < 8.6, CV ≤ 36%" under Average and "aim < 7%" under GMI.
  • CGM active: "· aim > 70%" beside its figure.
  • Time-in-range bands: each row ends with its target.

High and Low read "< 25% above range" and "< 4% below range", because those consensus targets cover both bands on that side, and a bare "< 25%" beside High alone would mislead. Misses aren't coloured; red stays for warnings.

Targets in each row

4. Colours

The PR adds 17 named colors, and most could reuse what Loop already has.

16 of the 17 are gone:

  • The -ink sets existed only so tinted text had enough contrast. Text now uses .primary and .secondary.
  • agp-inner, agp-outer, target-band and basal are glucose and insulin at reduced opacity.
  • ink-muted is .secondary.
  • The five range-* colours are gone, and their dark-mode variants moved into GlucoseBand.agpColor. There's one time-in-range palette, and Current Setup picks up the dark variants too.
  • The period selector is a system segmented Picker, so control-thumb is gone.

I'd like to keep one: a darker bolus (light #A9480A, dark #FFA347). We tried basal and bolus as one hue split only by lightness, and in use the two couldn't be told apart. Plain insulin is only 2.3:1 against white, so no lighter tint of it reaches 3:1 against bolus. With the darker bolus and a card-coloured gap where bolus sits on basal, they measure 4.7:1 in light mode and 4.4:1 in dark. If you'd rather solve this another way, I'm happy to change it.

Colours, light Colours, dark

5. Scope

Could the day page, Gaps and Export come as follow-up parts?

Done. The day page, the Gaps list and Export (PDF and CSV) are out of this PR, with their strings, code and tests. A one-day period still leads with that day's timeline, but it no longer opens a day page.

One day

6. Open/closed loop history

Rather than a new UserDefaults record… please read closed/open loop from data Loop already stores… check that every closed-loop toggle path saves settings.

Done:

  • The old record is gone. LoopModeHistory, its UserDefaults key and the LoopAppManager hook are removed.
  • Loop status reads stored settings. It takes dosingEnabled from getStoredSettings over the period, plus the last record before it, so the mode at the start of the period is known.
  • Toggle paths checked:
    • The Settings toggle, onboarding, the forced version update and the one-time legacy migration all go through mutateLoopSettings or storeSettings, and save a record.
    • Siri, remote commands and the watch can't change closed loop.
    • The SettingsViewModelDelegate.automaticDosingEnabled setter changes it without saving, but nothing calls it.
  • Show the loop as open while a manual temp basal is running #2649: a manual temp basal counts as open loop. It's taken from the temp basal dose itself and ends where the pump ended or cancelled it, rather than from the last run's error, so a later run failing for another reason doesn't hide it.

Loop status

7. "Loop keeps 7 days"

Fixed. The Loop status footnote reads "Covers …, from the start of Loop's records, which it keeps for 90 days", with the number from localCacheDuration. The day page's note left with the day page, and the "7 days" code comment is corrected.

8. Older periods

How does the screen show that the Manual/Automatic split and the scheduled basal are partial or estimated?

Before, it didn't: Scheduled used today's schedule for older days as if it were fact. Now:

  • Scheduled basal shows only for days Loop has its own schedule history, with a day count when that's part of the period ("Scheduled 28.0 U · 6 of 7 days").
  • Manual and automatic come from each bolus's own record. A bolus that doesn't record it shows as unknown, never as manual, and logged injections count as manual. Manual, automatic and unknown always add up to Bolus.
  • A period that's all from Apple Health gets a footnote: "Older days come from Apple Health, which doesn't record the basal schedule, and some boluses there don't say whether they were manual or automatic."
  • Weekly periods say how many days the averages cover ("weekly average · 6 of 90 days").

While checking this, I also found that days inside the cache window but before Loop's first records came up empty. Trends now reads Apple Health for those, with the boundary per kind of data at the later of the cache start and Loop's first record, and no overlap.

Partial week Apple Health week

Also fixed while testing

  • GMI always shows its mmol/mol value, as Statistics did, with "Best over 14 days with 70% CGM data" when the period is shorter or coverage is lower.
  • Time-in-range hours count only time with CGM readings.
  • Rows stack at the largest text sizes.

Deferred

  • Day page and Gaps come as their own PR, with stepping between days and the reasons Loop stopped running.
  • Export comes as its own PR, so the PDF and CSV report gets its own review.
  • Parts 2–6 ([2/8] Add a Logbook of the last 7 days #2638–[6/8] Add Day and Night app icons and an appearance setting #2642) will be restacked on this part once it settles. Until then they still carry the pre-review Trends.
  • Current Setup: its Since Change insulin shows "–". This PR doesn't change that code, which is the same as on next-dev, so I'll raise it separately.
  • Translations for the new strings would benefit from native-speaker review.

🤖 Generated with Claude Code

@Nutcasey Nutcasey left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Codex has reviewed PR #2637 using code-reviewer-cx, against next-dev f7b08cad, including the full diff and Pete's existing feedback. Codex has fixed all outstanding high-confidence issues found in this review. No further findings at or above 80/100 confidence remain.

Critical (90–100 confidence)

  • 98/100 — Schedule history extended into unknown time. LoopHistoryProvider.swift:107: the historical schedule queries backfilled the first saved profile and skipped records without a profile. Trends could therefore infer basal delivery and draw targets during unknown time. Fixed in 0081d73c: reporting uses each saved setting only for its recorded interval, including the setting before the requested start. A real-SettingsStore regression catches both leading unknown time and missing profiles; restoring the old queries produces 5 U instead of 3 U, and the corrected implementation passes.

Important (80–89 confidence)

  • 89/100 — Unreadable chart axes at accessibility text sizes. TrendsComponents.swift:732: the 90-day chart's dates overlapped at AX XXXL. Fixed in 596606a2: fewer axis labels, correctly anchored end dates, and stacked card titles/subtitles. The AGP and day timeline also reduce their axis labels at accessibility sizes. Verified on the loop simulator, including a before/after check of the insulin chart.

Verification

  • App build and build-for-testing succeeded, using the separate #2652 watch build fix locally; that fix is excluded from these commits.
  • Operated Settings → Trends, all five periods, previous/next navigation, older Apple Health data, empty periods, light/dark appearance and AX XXXL; Current Setup still opens.
  • 457 selected LoopTests: 455 passed, 2 failed. LoopDataManagerTests 28/28, LoopHistoryMathTests 32/32, GlucoseStatisticsTests 12/12.
  • The two failures are the already documented BolusEntryViewModelTests.testCarbEntryDateAndAbsorptionTimeString and …String2 locale assertions (12:00 PM versus 12:00). They also appear in the earlier pre-review run. HealthKit-hosted DeviceDataManagerTests were excluded; this is not a claim that the complete hosted suite passes.
  • git diff --check, catalogue JSON and new-string placeholder checks pass. Existing translations are unchanged.

The description now includes these fixes and the final test results. The PR is open and ready for human review.

@ps2 ps2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for all the updates! Looking good! Just a couple more things I noticed:

  • There is a mmol/mol line for users that don't use mmol/l in the GMI panel. That should probably be removed for those users.
  • I understand wanting to keep contrast for the insulin colors. The Basal looks brown though. Is there a way to use the standard insulin color, with different levels of transparency enough to keep the contrast?

@damonbayer

damonbayer commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

@Nutcasey Could you please make sure your colors pass WCAG AAA contrast guidelines for normal text (https://webaim.org/resources/contrastchecker/)? The text in the Summary cards is too low contrast.

Nutcasey added a commit to Nutcasey/Loop-1 that referenced this pull request Nov 7, 2026
@Nutcasey

Nutcasey commented Nov 7, 2026 •

Copy link
Copy Markdown
Author

Thanks both. This is pushed as three new commits on top, with no rebase, and the description and screenshots are updated.

@ps2: GMI (6adb4178). The mmol/mol line now only shows with mmol/L, including in the no-data tile.

GMI in mg/dL, in mg/dL with no data, and in mmol/L

@ps2: insulin colours (123113df). All insulin marks now use the standard insulin colour, and the darker bolus colour set is gone, so this PR adds no colour sets.

I didn't use transparency alone, because it can't remove the brown. Basal was already insulin at 25%, and that's what looked brown in dark mode. Faded orange on a dark card always does. I tried Statistics' 35/65/100 as well: basal is still brown in dark (#765421), and neighbouring marks are only 1.27:1 and 1.30:1 in light.

So the marks now differ by shape: solid bolus, hatched automatic and hollow basal. Bars have no brown left. The one-day timeline keeps a plain 25% fill, because an outline along its steps looked like small boluses, so that fill is still slightly brown in dark mode. If you'd still prefer the transparency approach, it's a small change to swap.

Before and after, light and dark. The 14-day captures end a day apart, so their totals differ; the marks are the change.

Insulin marks in light mode, before and after

Insulin marks in dark mode, before and after

One-day timeline, before and after, in light and dark

@damonbayer: contrast (4256c71b). You were right, the Summary text was too low. It was iOS's secondaryLabel on a tile's fill. Muted text on Trends now meets AAA:

Muted text Light before Light after Dark before Dark after
On a Summary tile 3.20:1 7.90:1 4.11:1 7.56:1
On a card 3.44:1 8.59:1 5.29:1 10.56:1

These are measured from simulator captures of the 14-day view.

Summary text before and after, in light and dark

@ps2: this moves muted text away from the system colour we settled on after your last review, because secondaryLabel can't reach 7:1 here. It's now black at 70% and white at 85%, so it doesn't respond to Increase Contrast, though it's already above 7:1. Tell me if you'd rather handle that differently.

Still below these targets:

  • The selected segment of the system picker is 5.45:1 in dark mode.
  • Current Setup still has .secondary text that this PR doesn't change.
  • The orange insulin marks are 2.2:1 on a white card. AAA's text rule doesn't cover graphics, but that's under the 3:1 guideline for them.

Selected tests: 455 of 457 pass, and the two failures are the existing BolusEntryViewModelTests locale ones.

@ps2 ps2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the latest round. The mmol/mol line now shows only with mmol/L (6adb417). Telling insulin apart by shape works, and it removes the last new colour asset (123113d). The muted text now has the higher contrast that was asked for (4256c71). A few things remain.

Translations

Localizable.xcstrings gains about 15,500 lines. About 15,200 of them are translations: all 95 new strings in 23 or 24 languages, each marked translated, and 12 existing strings that gain languages ("Average", "GMI", "High" and "Low" go from none to 23). Existing translations are unchanged.

Loop's translations come from volunteers on Lokalise, and new strings land in English. The Statistics strings this PR removes had no translations, and more than half the catalogue has fewer than 5 languages. Marked translated, these would ship as finished work and reach Lokalise as done, not queued for review. "High" and "Low" are also the glucose alarm names (GlucoseAlertManager, GlucoseAlertSettingsView), so their new translations would change the alarm names too.

Please keep the new strings English-only and let the translators pick them up through Lokalise.

One set of glucose statistics

Trends computes its own statistics in LoopHistoryMath.glucoseStats and timeInRange, beside GlucoseStatistics, which Current Setup still uses. The two can give different time in range for the same days:

  • GlucoseStatistics weights each reading by the time until the next one, with gaps capped. Trends counts each reading once.
  • The band edges differ: ..<181 / ..<251 there, and ...180 / ...250 here. A reading of 180.4 mg/dL, which an mmol/L sensor can produce, is in range on one screen and high on the other.

Could Trends use GlucoseStatistics, so there's one definition?

CGM coverage and reading interval

cgmActiveFraction assumes one reading every 5 minutes and caps the result at 100%. A CGM that reports every minute would always read 100%, so the 14-day, 70% GMI check would pass with gaps, and the hours a day per band would be overstated. Readings from Apple Health are thinned to one per 2½ minutes, but readings from Loop's store aren't, so the two sources disagree at the boundary. Time-based coverage, like GlucoseStatistics' gap-capped durations, would cover both.

Smaller

  • healthGlucose thins readings within 150 s before fingersticks are filtered out, so a fingerstick can drop a neighbouring CGM reading. Filtering first avoids it.
  • manualTempBasals matches automatic == false only, so a manual temp basal whose record leaves automatic unset doesn't count as open loop. Is that possible from any pump's history?

@Nutcasey

Copy link
Copy Markdown
Author

Thanks, Pete. All five points are addressed below. They're pushed as six new commits on top, with no rebase, and the description is updated.

Translations (7ec63b5d)

The new strings are English only now. The 23 languages on the 95 new strings are gone, and the 12 existing strings ("Average", "GMI", "High", "Low" and the rest) are back to exactly what next-dev has, so the alarm names are unchanged. The catalogue diff against next-dev drops from about 15,600 lines to +344/−60. Three Now-screen strings from a later part (COB, IOB, unknown) had slipped in, so I've removed them as well.

One set of glucose statistics (f3ee252e)

Trends now uses GlucoseStatistics for the mean, SD, CV, GMI, time in range, CGM coverage and the daily pattern. LoopHistoryMath.glucoseStats, timeInRange, RangeBand, agp and cgmActiveFraction are gone. To support this, GlucoseStatistics gains:

  • an init that takes readings as date and mg/dL values, so Apple Health readings can go through it as well as StoredGlucoseSamples
  • standardDeviation, which Trends shows

That gives one definition:

  • Time in range is time-weighted, with gaps capped.
  • Band edges are ..<181 / ..<251. 10.0 mmol/L (180.2 mg/dL) is in range and 13.9 mmol/L is high, as the consensus defines them in mmol/L.
  • The daily pattern uses agpProfile with 15-minute buckets.

Trends also converted to mmol/L with 18.0182 (a5d1c390), where LoopKit uses 18.0156. A 14-day mean of 7.75 mmol/L showed as 7.7 on Trends and 7.8 elsewhere. Trends now uses LoopKit's factor.

CGM coverage (e2c3852b)

percentActive in GlucoseStatistics is now time-based. Each reading covers the time until the next one, up to one 5-minute slot. A CGM that reports every minute therefore counts only the minutes it reports, and Apple Health readings thinned to one per 2½ minutes give the same coverage as Loop's unthinned ones. The hours a day per band follow from it. Current Setup gets the same fix, through its "before" coverage check.

On the simulator, I switched the CGM to 1-minute readings and backfilled 3 hours into a day with an overnight gap. Trends shows 35% CGM active and 3.0 h in range. The old count-based method gives 100% and 8.8 h for the same readings.

Smaller

  • Fingersticks (5aefabf9): Health readings are thinned among CGM readings only. A fingerstick is kept, but it no longer counts as the last reading, so it can't push out the CGM reading after it. The thinning is now a pure function with a test for this case.
  • automatic == false (fd3635ea): I've kept it, because nil means "not recorded", not "manual". It matches the home screen's isManualTempBasalRunning (Show the loop as open while a manual temp basal is running #2649). Every pump kit in the workspace records a manual temp as false: OmnipodKit and MedtrumKit through their non-optional automatic, and Minimed through its history import. The nil records come from reservoir-derived temp basals, which getNormalizedDoseEntries mixes in. Matching != true would mark all of those as open loop. I've added a comment saying so.

Verification

  • Simulator: Trends on 1 day, 14 days and a 30-day period that reads Apple Health, plus Current Setup. Every figure matches an independent calculation from the simulator's glucose store and Health database: coverage, mean, SD, CV, GMI and time in range.
  • Selected LoopTests: 460 run, 458 pass. GlucoseStatisticsTests 16/16, LoopHistoryMathTests 31/31, LoopDataManagerTests 28/28, SetupComparisonTests 8/8. The two failures are the existing BolusEntryViewModelTests locale assertions.

🤖 Generated with Claude Code

Nutcasey and others added 9 commits November 22, 2026 06:41
Trends reviews one period at a time (a day, 7, 14, 30 or 90 days) on
one screen: summary tiles (average with SD and CV, GMI, insulin, carbs
and boluses per day, Loop active), time in range, the daily pattern
(AGP), basal and bolus, insulin per day and Loop status with its gaps.
A one-day period leads with that day's timeline. Tapping a day opens
a day page with the insulin timeline and active insulin and carbs,
stepping a day at a time. The period exports as a PDF report or a CSV
with one row per day.

Inside Loop's 7 days the figures come from Loop's own stores, so manual
and automatic boluses, temp basals, historical targets and presets are
known. Older days come from Apple Health. Closed and open loop are
recorded from launch, because Loop's automation history only covers
36 hours.

Trends opens from Settings, beside Statistics, as a sheet with its own
navigation and a Done button. Statistics and Current Setup are
unchanged.

This is part 1 of 6 splitting LoopKit#2621.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP7ynB62LNuuYMy3yvH
Trends now carries everything Statistics shows that it lacked, so it
can take Statistics' place:

- Consensus goals: average under 8.6 mmol/L (154 mg/dL), GMI under 7%
  and CV 36% or less under the summary tiles; time in range over 70%,
  under 25% above and 4% below, under 5% very high and 1% very low,
  and CGM active over 70% on the Time in range card.
- Scheduled basal under Basal in Basal and bolus: the schedule that
  applied over the same days (the stored profile with presets), or
  today's schedule where the profile history doesn't reach.
- "Usually X U by HH:MM": today's insulin against the median by this
  time over the last 14 days, from InsulinDeliveryHistory as on
  Statistics. Under Total so far on today's Day view, and under the
  Insulin per day chart on longer periods ending today.
- "CGM data covers 5 of 14 days." under Summary when readings start
  partway through the period.
- Typed-in (fingerstick) readings are left out of every figure, as on
  Statistics. The day timeline still draws them.

Each new line reuses a pattern already on the screen: the Aim
footnote, the indented line under Bolus, and the muted footnote.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP7ynB62LNuuYMy3yvH
Removes the Statistics screen and its Settings entry, and puts Trends where it was. GlucoseBand's display extension, SetupComparisonCharts, GlucoseStatistics and InsulinDeliveryHistory stay, because Current Setup uses them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
A one-day period still leads with its timeline but no longer opens a day page. The removed code, strings and tests come back in their own parts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Summary keeps glucose, carbs and boluses. Basal and bolus fold into the Insulin per day card, Loop active is only in Loop status, and "usually by now" appears once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Each summary tile carries its aim and each time-in-range band shows its target in its row. Misses are not coloured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Removes the 17 colour sets. Marks use the existing glucose, insulin, carbs and accent colours, text uses primary and secondary, and GlucoseBand.agpColor gains dark variants. The period selector is a system segmented Picker.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Loop status reads dosingEnabled from SettingsStore, including the record before the period, instead of a UserDefaults record. A manual temp basal counts as open loop, as on the home screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
The Loop status note uses localCacheDuration instead of 7 days. Scheduled basal and the manual and automatic split cover only days Loop has itself, with a day count, and boluses of unknown kind are no longer counted as manual.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Nutcasey and others added 16 commits November 22, 2026 06:41
Time in range, basal and bolus, and Loop status rows stack at accessibility sizes instead of spilling or breaking words.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Moves the smooth-curve helper into SetupComparisonCharts, its remaining user.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Reads Apple Health for days before Loop's first local records, per kind of data, without overlap. Classifies each bolus from its own record and shows unknown. Always shows GMI with its IFCC value, with a note when the period is short or coverage is low. Counts time-in-range hours over CGM-covered time, restores dark-mode tile backgrounds and matches the Settings chevron.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
Limits the first-record scan to each week, treats logged injections as manual, lets a recorded manual temp basal end win, refreshes cached first records when stores change and lets the Boluses detail wrap. Adds one bolus colour set, so bolus stands apart from basal in light mode.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP6NkV9kiyLRBAeMMt9
HbA1c in mmol/mol goes with glucose in mmol/L, so people who use mg/dL
see the GMI as a percentage only. This applies to the no-data tile too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP9CXfENBveKkXDDz3c
All insulin marks now use Loop's insulin colour, so the darker bolus
colour set is gone and this PR adds no colour sets. Bolus is solid, automatic
bolus is hatched and basal is an outline with a faint wash. No tint of
orange reaches 3:1 against it on a white card, and faded orange turns
brown on a dark one, so opacity alone can't separate them in both modes.

Over one day, basal is a plain 25% fill, because an outline breaks into
pieces along a stepped area and looks like small boluses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP9CXfENBveKkXDDz3c
secondaryLabel reaches 3.2:1 in light mode and 4.1:1 in dark on a Summary
tile. Black at 70% and white at 85% reach 7.9:1 and 7.6:1 there, and more
on cards. All of Trends' muted text uses this token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP9CXfENBveKkXDDz3c
Loop's translations come from volunteers on Lokalise, so new strings land in
English and are picked up there. The 95 new strings lose their 23 languages,
and the 12 existing strings that gained languages ("Average", "GMI", "High",
"Low" and others) are back to their next-dev entries, which keeps the glucose
alarm names unchanged. COB, IOB and unknown belong to a later part and nothing
here uses them, so they are removed too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG
Trends had its own mean, SD, time in range and daily pattern beside
GlucoseStatistics, which Current Setup uses, and the two could disagree:
Trends counted readings where GlucoseStatistics weights them by time, and
its band edges (...180, ...250) put a reading such as 180.4 mg/dL (10.0
mmol/L) in High.

Trends now takes every glucose figure from GlucoseStatistics: mean, SD, CV,
GMI, time in range (time-weighted, gap-capped, ..<181 and ..<251) and the
daily pattern (agpProfile, 15-minute buckets). GlucoseStatistics gains an
init from readings as date and mg/dL, so Apple Health readings go through
it too, and the standard deviation Trends shows. LoopHistoryMath's
GlucoseStats, RangeBand, timeInRange, AGPSlot, agp and percentile are gone,
and the band display moves to GlucoseBand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG
percentActive counted each reading as five minutes and capped the result at
100%, so a CGM reporting every minute always read 100%: the GMI's 70% check
passed through gaps and the hours a day per band were overstated. Apple
Health readings, thinned to one per 2.5 minutes, and Loop's own also
disagreed at the boundary.

Each reading now covers the time until the next, up to one five-minute
slot. Current Setup's coverage check uses the same figure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG
Readings from Apple Health are thinned to one per 2.5 minutes before
fingersticks are left out, so a fingerstick could take the place of the CGM
reading after it. Thinning now compares CGM readings only with the last CGM
reading and always keeps fingersticks, which the one-day chart still draws.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG
A dose record whose automatic is nil hasn't said whether it was manual. The
temp basals Loop works out from reservoir readings are like that, so
counting nil as manual would show the loop as open wherever they appear.
This matches isManualTempBasalRunning on the home screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG
Trends divided by 18.0182 where LoopKit uses 18.0156, so a mean of
139.62 mg/dL read 7.7 mmol/L on Trends and 7.8 on Loop's other screens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP76NGVVgM8zLKUCSEG
LoopKit#2675 replaced DoseEntry's decisionId argument with doseId.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QHnVP8iKGqygup9AoAAPuE
@Nutcasey

Copy link
Copy Markdown
Author

Rebased onto next-dev 698fb063, which brings in #2652, so this branch now builds on its own. The 22 existing commits are unchanged and applied cleanly. The only new commit is c89c203b, which updates the Trends tests for #2675's doseId. LoopTests in the isolated harness: 471 run, with only the two known clock-format failures. Trends was checked on the simulator.

Parts 2–6 are being restacked on this branch. The day page with Gaps, and Export, follow as parts 7 and 8.

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.

3 participants