Просмотр исходного кода

Display pump basal rates in autotune profile

Jan Dittmer 4 лет назад
Родитель
Сommit
b8b9fcc647

+ 6 - 0
FreeAPS/Sources/Modules/AutotuneConfig/AutotuneConfigProvider.swift

@@ -8,6 +8,12 @@ extension AutotuneConfig {
             storage.retrieve(OpenAPS.Settings.autotune, as: Autotune.self)
         }
 
+        var basalProfilePump: [BasalProfileEntry] {
+            storage.retrieve(OpenAPS.Settings.basalProfile, as: [BasalProfileEntry].self)
+                ?? [BasalProfileEntry](from: OpenAPS.defaults(for: OpenAPS.Settings.basalProfile))
+                ?? []
+        }
+
         func runAutotune() -> AnyPublisher<Autotune?, Never> {
             apsManager.autotune()
         }

+ 15 - 0
FreeAPS/Sources/Modules/AutotuneConfig/AutotuneConfigStateModel.swift

@@ -7,6 +7,7 @@ extension AutotuneConfig {
         @Injected() var apsManager: APSManager!
         @Published var useAutotune = false
         @Published var autotune: Autotune?
+        @Published var basalProfile: [BasalProfileEntry?] = []
         private(set) var units: GlucoseUnits = .mmolL
         @Published var publishedDate = Date()
         @Persisted(key: "lastAutotuneDate") private var lastAutotuneDate = Date() {
@@ -19,6 +20,20 @@ extension AutotuneConfig {
 
         override func subscribe() {
             autotune = provider.autotune
+            var bp: [BasalProfileEntry?] = []
+            for p in provider.autotune?.basalProfile ?? [] {
+                var np: BasalProfileEntry?
+                for b in provider.basalProfilePump {
+                    if b.start > p.start {
+                        NSLog("Matched \(p) with \(b)")
+                        break
+                    }
+                    np = b
+                }
+                bp.append(np)
+            }
+            NSLog("basalProfile \(bp)")
+            basalProfile = bp
             units = settingsManager.settings.units
             useAutotune = settingsManager.settings.useAutotune
             publishedDate = lastAutotuneDate

+ 17 - 4
FreeAPS/Sources/Modules/AutotuneConfig/View/AutotuneConfigRootView.swift

@@ -66,10 +66,23 @@ extension AutotuneConfig {
                     Section(header: Text("Basal profile")) {
                         ForEach(0 ..< autotune.basalProfile.count, id: \.self) { index in
                             HStack {
-                                Text(autotune.basalProfile[index].start).foregroundColor(.secondary)
-                                Spacer()
-                                Text(rateFormatter.string(from: autotune.basalProfile[index].rate as NSNumber) ?? "0")
-                                Text("U/hr").foregroundColor(.secondary)
+                                VStack {
+                                    HStack {
+                                        Text(autotune.basalProfile[index].displayTime).foregroundColor(.secondary)
+                                        Spacer()
+                                        Text(rateFormatter.string(from: autotune.basalProfile[index].rate as NSNumber) ?? "0")
+                                        Text("U/hr").foregroundColor(.secondary)
+                                    }
+                                    if let basalProfile = state.basalProfile[index] {
+                                        HStack {
+                                            Text("Pump")
+                                            Text(basalProfile.displayTime)
+                                            Spacer()
+                                            Text(rateFormatter.string(from: basalProfile.rate as NSNumber) ?? "0")
+                                            Text("U/hr").foregroundColor(.secondary)
+                                        }.font(Font.system(size: 12))
+                                    }
+                                }
                             }
                         }
                     }