Skip to content

Commit 3aeeeb0

Browse files
authored
Cap prediction cone to shortest predBG array length (#653)
Fixes #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.
1 parent 17991b7 commit 3aeeeb0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

‎LoopFollow/Controllers/Graphs.swift‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,9 +2062,11 @@ extension MainViewController {
20622062

20632063
var coneData = [ConeChartDataEntry]()
20642064
if !allArrays.isEmpty {
2065-
let maxLength = min(allArrays.map { $0.count }.max()!, toLoad + 1)
2065+
// Cap at the shortest predBG array length so every cone point uses
2066+
// the same set of contributing arrays. Matches Trio's ForecastSetup.
2067+
let coneLength = min(allArrays.map { $0.count }.min()!, toLoad + 1)
20662068
var t = predictionStart
2067-
for i in 0 ..< maxLength {
2069+
for i in 0 ..< coneLength {
20682070
var valuesAtIndex = [Double]()
20692071
for arr in allArrays where i < arr.count {
20702072
valuesAtIndex.append(arr[i])

0 commit comments

Comments
 (0)