Quellcode durchsuchen

Skip enactBolus for amount=0; limit cone vertically and horizontally WIP

Deniz Cengiz vor 1 Jahr
Ursprung
Commit
00dac226d8

+ 4 - 0
FreeAPS/Sources/APS/APSManager.swift

@@ -439,6 +439,10 @@ final class BaseAPSManager: APSManager, Injectable {
     private var bolusReporter: DoseProgressReporter?
     private var bolusReporter: DoseProgressReporter?
 
 
     func enactBolus(amount: Double, isSMB: Bool) async {
     func enactBolus(amount: Double, isSMB: Bool) async {
+        if amount <= 0 {
+            return
+        }
+
         if let error = verifyStatus() {
         if let error = verifyStatus() {
             processError(error)
             processError(error)
             processQueue.async {
             processQueue.async {

+ 4 - 4
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -802,14 +802,14 @@ extension Bolus.StateModel {
             return
             return
         }
         }
 
 
-        let minCount = min(36, nonEmptyArrays.map(\.count).min() ?? 0)
-        guard minCount > 0 else { return }
+        let maxCount = min(36, nonEmptyArrays.map(\.count).max() ?? 0)
+        guard maxCount > 0 else { return }
 
 
-        minForecast = (0 ..< minCount).map { index in
+        minForecast = (0 ..< maxCount).map { index in
             nonEmptyArrays.compactMap { $0.indices.contains(index) ? $0[index] : nil }.min() ?? 0
             nonEmptyArrays.compactMap { $0.indices.contains(index) ? $0[index] : nil }.min() ?? 0
         }
         }
 
 
-        maxForecast = (0 ..< minCount).map { index in
+        maxForecast = (0 ..< maxCount).map { index in
             nonEmptyArrays.compactMap { $0.indices.contains(index) ? $0[index] : nil }.max() ?? 0
             nonEmptyArrays.compactMap { $0.indices.contains(index) ? $0[index] : nil }.max() ?? 0
         }
         }
     }
     }

+ 12 - 13
FreeAPS/Sources/Modules/Bolus/View/ForeCastChart.swift

@@ -87,20 +87,19 @@ struct ForeCastChart: View {
     }
     }
 
 
     private func drawForecastArea() -> some ChartContent {
     private func drawForecastArea() -> some ChartContent {
-        ForEach(state.minForecast.indices, id: \.self) { index in
-            AreaMark(
-                x: .value("Time", timeForIndex(Int32(index))),
-                yStart: .value(
-                    "Min Value",
-                    units == .mgdL ? Decimal(state.minForecast[index]) : Decimal(state.minForecast[index]).asMmolL
-                ),
-                yEnd: .value(
-                    "Max Value",
-                    units == .mgdL ? Decimal(state.maxForecast[index]) : Decimal(state.maxForecast[index]).asMmolL
+        ForEach(0 ..< max(state.minForecast.count, state.maxForecast.count), id: \.self) { index in
+            if index < state.minForecast.count, index < state.maxForecast.count {
+                let yMinValue = Decimal(state.minForecast[index]) <= 300 ? Decimal(state.minForecast[index]) : Decimal(300)
+                let yMaxValue = Decimal(state.maxForecast[index]) <= 300 ? Decimal(state.maxForecast[index]) : Decimal(300)
+
+                AreaMark(
+                    x: .value("Time", timeForIndex(Int32(index)) <= endMarker ? timeForIndex(Int32(index)) : endMarker),
+                    yStart: .value("Min Value", units == .mgdL ? yMinValue : yMinValue.asMmolL),
+                    yEnd: .value("Max Value", units == .mgdL ? yMaxValue : yMaxValue.asMmolL)
                 )
                 )
-            )
-            .foregroundStyle(Color.blue.opacity(0.5))
-            .interpolationMethod(.catmullRom)
+                .foregroundStyle(Color.blue.opacity(0.5))
+                .interpolationMethod(.catmullRom)
+            }
         }
         }
     }
     }
 
 

+ 9 - 10
FreeAPS/Sources/Modules/Home/View/Chart/MainChartView.swift

@@ -536,17 +536,16 @@ extension MainChartView {
     private func drawForecasts() -> some ChartContent {
     private func drawForecasts() -> some ChartContent {
         // Draw AreaMark for the forecast bounds
         // Draw AreaMark for the forecast bounds
         ForEach(0 ..< max(state.minForecast.count, state.maxForecast.count), id: \.self) { index in
         ForEach(0 ..< max(state.minForecast.count, state.maxForecast.count), id: \.self) { index in
-            if index < state.minForecast.count && index < state.maxForecast.count {
+            if index < state.minForecast.count, index < state.maxForecast.count {
+                let yMinValue = units == .mgdL ? Decimal(state.minForecast[index]) : Decimal(state.minForecast[index]).asMmolL
+                let yMaxValue = units == .mgdL ? Decimal(state.maxForecast[index]) : Decimal(state.maxForecast[index]).asMmolL
+
                 AreaMark(
                 AreaMark(
-                    x: .value("Time", timeForIndex(Int32(index))),
-                    yStart: .value(
-                        "Min Value",
-                        units == .mmolL ? Decimal(state.minForecast[index]).asMmolL : Decimal(state.minForecast[index])
-                    ),
-                    yEnd: .value(
-                        "Max Value",
-                        units == .mmolL ? Decimal(state.maxForecast[index]).asMmolL : Decimal(state.maxForecast[index])
-                    )
+                    x: .value("Time", timeForIndex(Int32(index)) <= endMarker ? timeForIndex(Int32(index)) : endMarker),
+
+                    // maxValue is already parsed to user units, no need to parse
+                    yStart: .value("Min Value", yMinValue <= maxValue ? yMinValue : maxValue),
+                    yEnd: .value("Max Value", yMaxValue <= maxValue ? yMaxValue : maxValue)
                 )
                 )
                 .foregroundStyle(Color.blue.opacity(0.5))
                 .foregroundStyle(Color.blue.opacity(0.5))
                 .interpolationMethod(.catmullRom)
                 .interpolationMethod(.catmullRom)