Przeglądaj źródła

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.
quarktwain 1 miesiąc temu
rodzic
commit
3aeeeb0f41
1 zmienionych plików z 4 dodań i 2 usunięć
  1. 4 2
      LoopFollow/Controllers/Graphs.swift

+ 4 - 2
LoopFollow/Controllers/Graphs.swift

@@ -2062,9 +2062,11 @@ extension MainViewController {
 
             var coneData = [ConeChartDataEntry]()
             if !allArrays.isEmpty {
-                let maxLength = min(allArrays.map { $0.count }.max()!, toLoad + 1)
+                // Cap at the shortest predBG array length so every cone point uses
+                // the same set of contributing arrays. Matches Trio's ForecastSetup.
+                let coneLength = min(allArrays.map { $0.count }.min()!, toLoad + 1)
                 var t = predictionStart
-                for i in 0 ..< maxLength {
+                for i in 0 ..< coneLength {
                     var valuesAtIndex = [Double]()
                     for arr in allArrays where i < arr.count {
                         valuesAtIndex.append(arr[i])