Przeglądaj źródła

Fix thresholds); do it all in mg/dL and parse for display only

Deniz Cengiz 1 rok temu
rodzic
commit
9bfc26f103

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

@@ -228,8 +228,8 @@ extension Bolus {
             sweetMealFactor = settings.settings.sweetMealFactor
             displayPresets = settings.settings.displayPresets
             forecastDisplayType = settings.settings.forecastDisplayType
-            lowGlucose = units == .mgdL ? settingsManager.settings.low : settingsManager.settings.low.asMmolL
-            highGlucose = units == .mgdL ? settingsManager.settings.high : settingsManager.settings.high.asMmolL
+            lowGlucose = settingsManager.settings.low
+            highGlucose = settingsManager.settings.high
             maxCarbs = settings.settings.maxCarbs
             maxFat = settings.settings.maxFat
             maxProtein = settings.settings.maxProtein

+ 2 - 5
FreeAPS/Sources/Modules/Bolus/View/ForecastChart.swift

@@ -117,9 +117,6 @@ struct ForecastChart: View {
         ForEach(state.glucoseFromPersistence) { item in
             let glucoseToDisplay = state.units == .mgdL ? Decimal(item.glucose) : Decimal(item.glucose).asMmolL
 
-            // low and high glucose is parsed in state to mmol/L; parse it back to mg/dl here for comparison
-            let lowGlucose = units == .mgdL ? state.lowGlucose : state.lowGlucose.asMgdL
-            let highGlucose = units == .mgdL ? state.highGlucose : state.highGlucose.asMgdL
             let targetGlucose = (state.determination.first?.currentTarget ?? state.currentBGTarget as NSDecimalNumber) as Decimal
 
             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
@@ -129,8 +126,8 @@ struct ForecastChart: View {
 
             let pointMarkColor: Color = FreeAPS.getDynamicGlucoseColor(
                 glucoseValue: Decimal(item.glucose),
-                highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
-                lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
+                highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : state.highGlucose,
+                lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : state.lowGlucose,
                 targetGlucose: targetGlucose,
                 glucoseColorScheme: state.glucoseColorScheme
             )

+ 2 - 2
FreeAPS/Sources/Modules/GlucoseNotificationSettings/GlucoseNotificationSettingsStateModel.swift

@@ -22,7 +22,7 @@ extension GlucoseNotificationSettings {
                 addSourceInfoToGlucoseNotifications = $0 }
             subscribeSetting(\.lowGlucose, on: $lowGlucose, initial: {
                 let value = max(min($0, 400), 40)
-                lowGlucose = units == .mmolL ? value.asMmolL : value
+                lowGlucose = value
             }, map: {
                 guard units == .mmolL else { return $0 }
                 return $0.asMgdL
@@ -30,7 +30,7 @@ extension GlucoseNotificationSettings {
 
             subscribeSetting(\.highGlucose, on: $highGlucose, initial: {
                 let value = max(min($0, 400), 40)
-                highGlucose = units == .mmolL ? value.asMmolL : value
+                highGlucose = value
             }, map: {
                 guard units == .mmolL else { return $0 }
                 return $0.asMgdL

+ 5 - 5
FreeAPS/Sources/Modules/Home/HomeStateModel.swift

@@ -330,8 +330,8 @@ extension Home {
             isSmoothingEnabled = settingsManager.settings.smoothGlucose
             glucoseColorScheme = settingsManager.settings.glucoseColorScheme
             maxValue = settingsManager.preferences.autosensMax
-            lowGlucose = units == .mgdL ? settingsManager.settings.low : settingsManager.settings.low.asMmolL
-            highGlucose = units == .mgdL ? settingsManager.settings.high : settingsManager.settings.high.asMmolL
+            lowGlucose = settingsManager.settings.low
+            highGlucose = settingsManager.settings.high
             overrideUnit = settingsManager.settings.overrideHbA1cUnit
             displayXgridLines = settingsManager.settings.xGridLines
             displayYgridLines = settingsManager.settings.yGridLines
@@ -535,7 +535,7 @@ extension Home {
 
                 if now >= entryStartTime, now < entryEndTime {
                     await MainActor.run {
-                        currentGlucoseTarget = units == .mgdL ? entry.value : entry.value.asMmolL
+                        currentGlucoseTarget = entry.value
                     }
                     return
                 }
@@ -583,8 +583,8 @@ extension Home.StateModel:
         units = settingsManager.settings.units
         manualTempBasal = apsManager.isManualTempBasal
         isSmoothingEnabled = settingsManager.settings.smoothGlucose
-        lowGlucose = units == .mgdL ? settingsManager.settings.low : settingsManager.settings.low.asMmolL
-        highGlucose = units == .mgdL ? settingsManager.settings.high : settingsManager.settings.high.asMmolL
+        lowGlucose = settingsManager.settings.low
+        highGlucose = settingsManager.settings.high
         Task {
             await getCurrentGlucoseTarget()
         }

+ 2 - 2
FreeAPS/Sources/Modules/Home/View/Chart/DummyCharts.swift

@@ -29,10 +29,10 @@ extension MainChartView {
                     glucoseColorScheme: glucoseColorScheme
                 )
 
-                RuleMark(y: .value("High", highGlucose))
+                RuleMark(y: .value("High", units == .mgdL ? highGlucose : highGlucose.asMmolL))
                     .foregroundStyle(highColor)
                     .lineStyle(.init(lineWidth: 1, dash: [5]))
-                RuleMark(y: .value("Low", lowGlucose))
+                RuleMark(y: .value("Low", units == .mgdL ? lowGlucose : lowGlucose.asMmolL))
                     .foregroundStyle(lowColor)
                     .lineStyle(.init(lineWidth: 1, dash: [5]))
             }

+ 0 - 4
FreeAPS/Sources/Modules/Home/View/Chart/GlucoseChartView.swift

@@ -19,10 +19,6 @@ struct GlucoseChartView: ChartContent {
         ForEach(glucoseData) { item in
             let glucoseToDisplay = units == .mgdL ? Decimal(item.glucose) : Decimal(item.glucose).asMmolL
 
-            // low glucose and high glucose is parsed in state to mmol/L; parse it back to mg/dL here for comparison
-            let lowGlucose = units == .mgdL ? lowGlucose : lowGlucose.asMgdL
-            let highGlucose = units == .mgdL ? highGlucose : highGlucose.asMgdL
-
             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
             let hardCodedLow = Decimal(55)
             let hardCodedHigh = Decimal(220)

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

@@ -260,7 +260,7 @@ extension MainChartView {
                     glucoseValue: Decimal(sgv),
                     highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
                     lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
-                    targetGlucose: units == .mgdL ? currentGlucoseTarget : currentGlucoseTarget.asMgdL,
+                    targetGlucose: currentGlucoseTarget,
                     glucoseColorScheme: glucoseColorScheme
                 )
                 HStack {

+ 1 - 6
FreeAPS/Sources/Modules/Home/View/Header/CurrentGlucoseView.swift

@@ -82,11 +82,6 @@ struct CurrentGlucoseView: View {
                             let displayGlucose = units == .mgdL ? Decimal(glucoseValue).description : Decimal(glucoseValue)
                                 .formattedAsMmolL
 
-                            // low glucose, high glucose and target is parsed in state to mmol/L; parse it back to mg/dl here for comparison
-                            let lowGlucose = units == .mgdL ? lowGlucose : lowGlucose.asMgdL
-                            let highGlucose = units == .mgdL ? highGlucose : highGlucose.asMgdL
-                            let targetGlucose = units == .mgdL ? currentGlucoseTarget : currentGlucoseTarget.asMgdL
-
                             var glucoseDisplayColor = Color.primary
 
                             // TODO: workaround for now: set low value to 55, to have dynamic color shades between 55 and user-set low (approx. 70); same for high glucose
@@ -99,7 +94,7 @@ struct CurrentGlucoseView: View {
                                     glucoseValue: Decimal(glucoseValue),
                                     highGlucoseColorValue: isDynamicColorScheme ? hardCodedHigh : highGlucose,
                                     lowGlucoseColorValue: isDynamicColorScheme ? hardCodedLow : lowGlucose,
-                                    targetGlucose: targetGlucose,
+                                    targetGlucose: currentGlucoseTarget,
                                     glucoseColorScheme: glucoseColorScheme
                                 )
                             }