Explorar o código

Add Eventual Glucose

Jon Mårtensson %!s(int64=2) %!d(string=hai) anos
pai
achega
a96d220026

+ 0 - 1
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -57,7 +57,6 @@ extension Bolus {
         @Published var fattyMeals: Bool = false
         @Published var fattyMealFactor: Decimal = 0
         @Published var useFattyMealCorrectionFactor: Bool = false
-        @Published var eventualBG: Int = 0
 
         @Published var meal: [CarbsEntry]?
         @Published var carbs: Decimal = 0

+ 1 - 1
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -197,7 +197,7 @@ extension Bolus {
         var predictionChart: some View {
             ZStack {
                 PredictionView(
-                    predictions: $state.predictions, units: $state.units
+                    predictions: $state.predictions, units: $state.units, eventualBG: $state.evBG, target: $state.target
                 )
             }
         }

+ 1 - 1
FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift

@@ -166,7 +166,7 @@ extension Bolus {
         var predictionChart: some View {
             ZStack {
                 PredictionView(
-                    predictions: $state.predictions, units: $state.units
+                    predictions: $state.predictions, units: $state.units, eventualBG: $state.evBG, target: $state.target
                 )
             }
         }

+ 18 - 14
FreeAPS/Sources/Modules/Bolus/View/Predictions.swift

@@ -6,6 +6,8 @@ import Swinject
 struct PredictionView: View {
     @Binding var predictions: Predictions?
     @Binding var units: GlucoseUnits
+    @Binding var eventualBG: Int
+    @Binding var target: Decimal
 
     var body: some View {
         chart()
@@ -21,6 +23,8 @@ struct PredictionView: View {
         var now = Date.now
         var startIndex = 0
         let conversion = units == .mmolL ? 0.0555 : 1
+        let eventualRounded: String = (Double(eventualBG) * conversion)
+            .formatted(.number.grouping(.never).rounded().precision(.fractionLength(units == .mmolL ? 1 : 0)))
         // Organize the data needed for prediction chart.
         var data = [ChartData]()
         repeat {
@@ -39,39 +43,39 @@ struct PredictionView: View {
             startIndex += 1
         } while startIndex < count
         // Chart
-        return Chart(data) { item in
+        return Chart(data) {
             // Remove 0 (empty) values
-            if item.iob != 0 {
+            if $0.iob != 0 {
                 LineMark(
-                    x: .value("Time", item.date),
-                    y: .value("IOB", item.iob),
+                    x: .value("Time", $0.date),
+                    y: .value("IOB", $0.iob),
                     series: .value("IOB", "A")
                 )
                 .foregroundStyle(Color(.insulin))
                 .lineStyle(StrokeStyle(lineWidth: 2))
             }
-            if item.uam != 0 {
+            if $0.uam != 0 {
                 LineMark(
-                    x: .value("Time", item.date),
-                    y: .value("UAM", item.uam),
+                    x: .value("Time", $0.date),
+                    y: .value("UAM", $0.uam),
                     series: .value("UAM", "B")
                 )
                 .foregroundStyle(Color(.UAM))
                 .lineStyle(StrokeStyle(lineWidth: 2))
             }
-            if item.cob != 0 {
+            if $0.cob != 0 {
                 LineMark(
-                    x: .value("Time", item.date),
-                    y: .value("COB", item.cob),
+                    x: .value("Time", $0.date),
+                    y: .value("COB", $0.cob),
                     series: .value("COB", "C")
                 )
                 .foregroundStyle(Color(.loopYellow))
                 .lineStyle(StrokeStyle(lineWidth: 2))
             }
-            if item.zt != 0 {
+            if $0.zt != 0 {
                 LineMark(
-                    x: .value("Time", item.date),
-                    y: .value("ZT", item.zt),
+                    x: .value("Time", $0.date),
+                    y: .value("ZT", $0.zt),
                     series: .value("ZT", "D")
                 )
                 .foregroundStyle(Color(.ZT))
@@ -85,6 +89,6 @@ struct PredictionView: View {
             "COB": Color(.loopYellow),
             "ZT": Color(.ZT)
         ])
-        .chartYAxisLabel("Glucose (" + units.rawValue + ")")
+        .chartYAxisLabel("Eventual Glucose: " + eventualRounded + " " + units.rawValue, alignment: .center)
     }
 }