Преглед изворни кода

make presets optional, remove predictions

polscm32 пре 2 година
родитељ
комит
c4c07a0048

+ 0 - 4
FreeAPS.xcodeproj/project.pbxproj

@@ -19,7 +19,6 @@
 		190EBCC829FF13AA00BA767D /* StatConfigStateModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 190EBCC729FF13AA00BA767D /* StatConfigStateModel.swift */; };
 		190EBCCB29FF13CB00BA767D /* StatConfigRootView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 190EBCCA29FF13CB00BA767D /* StatConfigRootView.swift */; };
 		191F62682AD6B05A004D7911 /* NightscoutSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 191F62672AD6B05A004D7911 /* NightscoutSettings.swift */; };
-		19229B962AFBB84800CD91CA /* Predictions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 19229B952AFBB84800CD91CA /* Predictions.swift */; };
 		1927C8E62744606D00347C69 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 1927C8E82744606D00347C69 /* InfoPlist.strings */; };
 		1935364028496F7D001E0B16 /* Oref2_variables.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1935363F28496F7D001E0B16 /* Oref2_variables.swift */; };
 		193F6CDD2A512C8F001240FD /* Loops.swift in Sources */ = {isa = PBXBuildFile; fileRef = 193F6CDC2A512C8F001240FD /* Loops.swift */; };
@@ -544,7 +543,6 @@
 		190EBCCA29FF13CB00BA767D /* StatConfigRootView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatConfigRootView.swift; sourceTree = "<group>"; };
 		1918333A26ADA46800F45722 /* fi */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = fi; path = fi.lproj/Localizable.strings; sourceTree = "<group>"; };
 		191F62672AD6B05A004D7911 /* NightscoutSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NightscoutSettings.swift; sourceTree = "<group>"; };
-		19229B952AFBB84800CD91CA /* Predictions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Predictions.swift; sourceTree = "<group>"; };
 		1927C8E92744611700347C69 /* ar */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ar; path = ar.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1927C8EA2744611800347C69 /* ca */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ca; path = ca.lproj/InfoPlist.strings; sourceTree = "<group>"; };
 		1927C8EB2744611900347C69 /* zh-Hans */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "zh-Hans"; path = "zh-Hans.lproj/InfoPlist.strings"; sourceTree = "<group>"; };
@@ -2180,7 +2178,6 @@
 				10A0C32B0DAB52726EF9B6D9 /* BolusRootView.swift */,
 				BDFD165B2AE40688007F0DDA /* DefaultBolusCalcRootView.swift */,
 				BDFD16592AE40438007F0DDA /* AlternativeBolusCalcRootView.swift */,
-				19229B952AFBB84800CD91CA /* Predictions.swift */,
 			);
 			path = View;
 			sourceTree = "<group>";
@@ -2952,7 +2949,6 @@
 				1967DFBE29D052C200759F30 /* Icons.swift in Sources */,
 				38E8754F275556FA00975559 /* WatchManager.swift in Sources */,
 				A228DF96647338139F152B15 /* PreferencesEditorDataFlow.swift in Sources */,
-				19229B962AFBB84800CD91CA /* Predictions.swift in Sources */,
 				389ECE052601144100D86C4F /* ConcurrentMap.swift in Sources */,
 				CE7CA3562A064973004BE681 /* StateIntentRequest.swift in Sources */,
 				E4984C5262A90469788754BB /* PreferencesEditorProvider.swift in Sources */,

+ 1 - 1
FreeAPS.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -39,7 +39,7 @@
       },
       {
         "package": "SwiftCharts",
-        "repositoryURL": "https://github.com/ivanschuetz/SwiftCharts",
+        "repositoryURL": "https://github.com/ivanschuetz/SwiftCharts.git",
         "state": {
           "branch": "master",
           "revision": "c354c1945bb35a1f01b665b22474f6db28cba4a2",

+ 3 - 3
FreeAPS/Sources/Models/FreeAPSSettings.swift

@@ -53,7 +53,7 @@ struct FreeAPSSettings: JSON, Equatable {
     var fattyMealFactor: Decimal = 0.7
     var sweetMeals: Bool = false
     var sweetMealFactor: Decimal = 2
-    var displayPredictions: Bool = true
+    var displayPresets: Bool = true
     var useLiveActivity: Bool = false
     var historyLayout: HistoryLayout = .twoTabs
     var lockScreenView: LockScreenView = .simple
@@ -278,8 +278,8 @@ extension FreeAPSSettings: Decodable {
             settings.onlyAutotuneBasals = onlyAutotuneBasals
         }
 
-        if let displayPredictions = try? container.decode(Bool.self, forKey: .displayPredictions) {
-            settings.displayPredictions = displayPredictions
+        if let displayPresets = try? container.decode(Bool.self, forKey: .displayPresets) {
+            settings.displayPresets = displayPresets
         }
 
         if let useLiveActivity = try? container.decode(Bool.self, forKey: .useLiveActivity) {

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

@@ -60,7 +60,7 @@ extension Bolus {
         @Published var fattyMeals: Bool = false
         @Published var fattyMealFactor: Decimal = 0
         @Published var useFattyMealCorrectionFactor: Bool = false
-        @Published var displayPredictions: Bool = true
+        @Published var displayPresets: Bool = true
 
         @Published var currentBasal: Decimal = 0
         @Published var sweetMeals: Bool = false
@@ -106,7 +106,7 @@ extension Bolus {
             fattyMealFactor = settings.settings.fattyMealFactor
             sweetMeals = settings.settings.sweetMeals
             sweetMealFactor = settings.settings.sweetMealFactor
-            displayPredictions = settings.settings.displayPredictions
+            displayPresets = settings.settings.displayPresets
 
             carbsRequired = provider.suggestion?.carbsReq
             maxCarbs = settings.settings.maxCarbs

+ 5 - 12
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -349,9 +349,11 @@ extension Bolus {
                     }
                 } header: { Text("Carbs") }.listRowBackground(Color.chart)
 
-                Section {
-                    mealPresets
-                }.listRowBackground(Color.chart)
+                if state.displayPresets {
+                    Section {
+                        mealPresets
+                    }.listRowBackground(Color.chart)
+                }
 
                 Section {
                     HStack {
@@ -485,15 +487,6 @@ extension Bolus {
                 }
         }
 
-        var predictionChart: some View {
-            ZStack {
-                PredictionView(
-                    predictions: $state.predictions, units: $state.units, eventualBG: $state.evBG, target: $state.target,
-                    displayPredictions: $state.displayPredictions
-                )
-            }
-        }
-
         var calcSettingsFirstRow: some View {
             GridRow {
                 Group {

+ 0 - 11
FreeAPS/Sources/Modules/Bolus/View/DefaultBolusCalcRootView.swift

@@ -57,8 +57,6 @@ extension Bolus {
                 Section {
                     if state.waitForSuggestion {
                         Text("Please wait")
-                    } else {
-                        predictionChart
                     }
                 } header: { Text("Predictions") }.listRowBackground(Color.chart)
 
@@ -180,15 +178,6 @@ extension Bolus {
             state.amount <= 0 || state.amount > state.maxBolus
         }
 
-        var predictionChart: some View {
-            ZStack {
-                PredictionView(
-                    predictions: $state.predictions, units: $state.units, eventualBG: $state.evBG, target: $state.target,
-                    displayPredictions: $state.displayPredictions
-                )
-            }
-        }
-
         var changed: Bool {
             ((meal.first?.carbs ?? 0) > 0) || ((meal.first?.fat ?? 0) > 0) || ((meal.first?.protein ?? 0) > 0)
         }

+ 0 - 113
FreeAPS/Sources/Modules/Bolus/View/Predictions.swift

@@ -1,113 +0,0 @@
-import Charts
-import CoreData
-import SwiftUI
-import Swinject
-
-struct PredictionView: View {
-    @Binding var predictions: Predictions?
-    @Binding var units: GlucoseUnits
-    @Binding var eventualBG: Int
-    @Binding var target: Decimal
-    @Binding var displayPredictions: Bool
-
-    private enum Config {
-        static let height: CGFloat = 160
-        static let lineWidth: CGFloat = 2
-    }
-
-    var body: some View {
-        VStack {
-            if displayPredictions {
-                chart()
-            }
-            HStack {
-                let conversion = units == .mmolL ? 0.0555 : 1
-                Text("Eventual Glucose")
-                Spacer()
-                Text(
-                    (Double(eventualBG) * conversion)
-                        .formatted(.number.grouping(.never).rounded().precision(.fractionLength(units == .mmolL ? 1 : 0)))
-                )
-                Text(units.rawValue).foregroundStyle(.secondary)
-                Divider()
-            }.font(.callout)
-        }
-    }
-
-    func chart() -> some View {
-        // Data Source
-        let iob = predictions?.iob ?? [Int]()
-        let cob = predictions?.cob ?? [Int]()
-        let uam = predictions?.uam ?? [Int]()
-        let zt = predictions?.zt ?? [Int]()
-        let count = max(iob.count, cob.count, uam.count, zt.count)
-        var now = Date.now
-        var startIndex = 0
-        let conversion = units == .mmolL ? 0.0555 : 1
-        // Organize the data needed for prediction chart.
-        var data = [ChartData]()
-        repeat {
-            now = now.addingTimeInterval(5.minutes.timeInterval)
-            if startIndex < count {
-                let addedData = ChartData(
-                    date: now,
-                    iob: startIndex < iob.count ? Double(iob[startIndex]) * conversion : 0,
-                    zt: startIndex < zt.count ? Double(zt[startIndex]) * conversion : 0,
-                    cob: startIndex < cob.count ? Double(cob[startIndex]) * conversion : 0,
-                    uam: startIndex < uam.count ? Double(uam[startIndex]) * conversion : 0,
-                    id: UUID()
-                )
-                data.append(addedData)
-            }
-            startIndex += 1
-        } while startIndex < count
-        // Chart
-        return Chart(data) {
-            // Remove 0 (empty) values
-            if $0.iob != 0 {
-                LineMark(
-                    x: .value("Time", $0.date),
-                    y: .value("IOB", $0.iob),
-                    series: .value("IOB", "A")
-                )
-                .foregroundStyle(Color(.insulin))
-                .lineStyle(StrokeStyle(lineWidth: Config.lineWidth))
-            }
-            if $0.uam != 0 {
-                LineMark(
-                    x: .value("Time", $0.date),
-                    y: .value("UAM", $0.uam),
-                    series: .value("UAM", "B")
-                )
-                .foregroundStyle(Color(.UAM))
-                .lineStyle(StrokeStyle(lineWidth: Config.lineWidth))
-            }
-            if $0.cob != 0 {
-                LineMark(
-                    x: .value("Time", $0.date),
-                    y: .value("COB", $0.cob),
-                    series: .value("COB", "C")
-                )
-                .foregroundStyle(Color(.loopYellow))
-                .lineStyle(StrokeStyle(lineWidth: Config.lineWidth))
-            }
-            if $0.zt != 0 {
-                LineMark(
-                    x: .value("Time", $0.date),
-                    y: .value("ZT", $0.zt),
-                    series: .value("ZT", "D")
-                )
-                .foregroundStyle(Color(.ZT))
-                .lineStyle(StrokeStyle(lineWidth: Config.lineWidth))
-            }
-        }
-        .frame(minHeight: Config.height)
-        .chartForegroundStyleScale([
-            "IOB": Color(.insulin),
-            "UAM": .uam,
-            "COB": Color(.loopYellow),
-            "ZT": .zt
-        ])
-        .chartYAxisLabel(NSLocalizedString("Glucose, ", comment: "") + units.rawValue, alignment: .center)
-    }
-}

+ 2 - 2
FreeAPS/Sources/Modules/BolusCalculatorConfig/BolusCalculatorStateModel.swift

@@ -9,7 +9,7 @@ extension BolusCalculatorConfig {
         @Published var sweetMeals: Bool = false
         @Published var sweetMealFactor: Decimal = 0
         @Published var insulinReqPercentage: Decimal = 70
-        @Published var displayPredictions: Bool = true
+        @Published var displayPresets: Bool = true
 
         override func subscribe() {
             subscribeSetting(\.overrideFactor, on: $overrideFactor, initial: {
@@ -20,7 +20,7 @@ extension BolusCalculatorConfig {
             })
             subscribeSetting(\.useCalc, on: $useCalc) { useCalc = $0 }
             subscribeSetting(\.fattyMeals, on: $fattyMeals) { fattyMeals = $0 }
-            subscribeSetting(\.displayPredictions, on: $displayPredictions) { displayPredictions = $0 }
+            subscribeSetting(\.displayPresets, on: $displayPresets) { displayPresets = $0 }
             subscribeSetting(\.fattyMealFactor, on: $fattyMealFactor, initial: {
                 let value = max(min($0, 1.2), 0.1)
                 fattyMealFactor = value

+ 1 - 1
FreeAPS/Sources/Modules/BolusCalculatorConfig/View/BolusCalculatorConfigRootView.swift

@@ -62,7 +62,7 @@ extension BolusCalculatorConfig {
                 } header: { Text("Calculator settings") }
 
                 Section {
-                    Toggle("Display Predictions", isOn: $state.displayPredictions)
+                    Toggle("Display Presets", isOn: $state.displayPresets)
 
                 } header: { Text("Smaller iPhone Screens") }