Skip to content

Cap prediction cone to shortest predBG array length#653

Merged
marionbarker merged 1 commit into
loopandlearn:devfrom
quarktwain:fix/637-cone-cap-shortest-predbg
Jun 16, 2026
Merged

Cap prediction cone to shortest predBG array length#653
marionbarker merged 1 commit into
loopandlearn:devfrom
quarktwain:fix/637-cone-cap-shortest-predbg

Conversation

@quarktwain

Copy link
Copy Markdown

Fixes #637.

Summary

updateOpenAPSPredictionDisplay() capped the cone at the longest predBG
array, so at indices past shorter arrays the cone deformed -- the band
narrowed or shifted as contributing arrays dropped out one by one.

This caps at the shortest array length instead. Every cone point is
computed from the same set of contributing arrays; the band ends cleanly
when the first array runs out.

Compared against nightscout/Trio Trio/Sources/Modules/Home/HomeStateModel+Setup/ForecastSetup.swift:

minCount = max(12, allForecastValues.map(\.count).min() ?? 0)
let localMinCount = minCount
// ...
let minForecast = (0 ..< localMinCount).map { ... }
let maxForecast = (0 ..< localMinCount).map { ... }

Trio iterates 0 ..< localMinCount -- every cone point uses values from
all contributing arrays. This PR brings LoopFollow to the same shape.

Did not adopt Trio's max(12, ...) floor; open to adding it if preferred.

User-visible behavior

  • For users whose shortest predBG array is materially shorter than the
    longest, the cone will visibly end earlier than before. The
    previously-rendered tail was narrowing/shifting with no real meaning.
  • topPredictionBG (graph y-axis upper bound) is updated inside the
    loop. With the shorter loop, the upper bound may sit slightly tighter
    for some sessions. No data is cropped (the loop's output is what gets
    drawn); just less empty headroom in mixed-length-array cases.

Fixes loopandlearn#637.

The cone of uncertainty in updateOpenAPSPredictionDisplay() was capped
at the longest predBG array (.max()), which let the band visibly deform
at the tail as shorter arrays dropped out one by one.

Cap at the shortest array length instead so every cone point is computed
from the same set of contributing arrays. Matches Trio's ForecastSetup
(Trio/Sources/Modules/Home/HomeStateModel+Setup/ForecastSetup.swift),
which uses allForecastValues.map(\.count).min() and then iterates
0 ..< localMinCount.

Renamed maxLength to coneLength since the variable no longer represents
a max.
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ This PR targets the main branch. We do not accept PRs directly to main — please retarget your PR to the dev branch instead.

@quarktwain quarktwain changed the base branch from main to dev May 10, 2026 06:27
@quarktwain

Copy link
Copy Markdown
Author

Retargeted to dev -- thanks for the auto-warning. Branch is clean against dev (no rebase needed; main and dev are at the same commit currently).

@dnzxy

dnzxy commented May 12, 2026

Copy link
Copy Markdown
Collaborator

+1 on this one. Reported the same quirk (#637 ) privately to the LF team.

@marionbarker

Copy link
Copy Markdown
Collaborator

Test

✅ successful test

Configuration

Use an iPhone SE running iOS 26.5.
Build LoopFollow dev and this branch
Observe a Trio URL

Screenshots

These screenshots demonstrate this PR (middle screen in graphic) fixes the distorted cone (right screen in graphic is dev branch).

Graphic has forecast set as cones for Trio (left screen) and LoopFollow.

lf-653-cone

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

Approve from code review and test.

@bjorkert bjorkert closed this Jun 16, 2026
@bjorkert bjorkert reopened this Jun 16, 2026
@bjorkert bjorkert requested a review from codebymini as a code owner June 16, 2026 04:58
@marionbarker

Copy link
Copy Markdown
Collaborator

Thanks for the close/reopen - that fixed the test that was stuck.

@marionbarker marionbarker merged commit 3aeeeb0 into loopandlearn:dev Jun 16, 2026
2 checks passed
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.

Cone of uncertainty: cap to shortest predBG array to match Trio

4 participants