Explorar el Código

Display autotune basal profile in pump profile editor

Jan Dittmer hace 4 años
padre
commit
7c91266fa1

+ 4 - 0
FreeAPS/Sources/Modules/BasalProfileEditor/BasalProfileEditorProvider.swift

@@ -12,6 +12,10 @@ extension BasalProfileEditor {
                 ?? []
         }
 
+        var autotune: Autotune? {
+            storage.retrieve(OpenAPS.Settings.autotune, as: Autotune.self)
+        }
+
         var supportedBasalRates: [Decimal]? {
             deviceManager.pumpManager?.supportedBasalRates.map { Decimal($0) }
         }

+ 16 - 0
FreeAPS/Sources/Modules/BasalProfileEditor/BasalProfileEditorStateModel.swift

@@ -4,6 +4,7 @@ extension BasalProfileEditor {
     final class StateModel: BaseStateModel<Provider> {
         @Published var syncInProgress = false
         @Published var items: [Item] = []
+        @Published var autotuneProfile: [BasalProfileEntry?] = []
 
         let timeValues = stride(from: 0.0, to: 1.days.timeInterval, by: 30.minutes.timeInterval).map { $0 }
 
@@ -22,6 +23,21 @@ extension BasalProfileEditor {
                 let rateIndex = rateValues.firstIndex(of: value.rate) ?? 0
                 return Item(rateIndex: rateIndex, timeIndex: timeIndex)
             }
+
+            var bp: [BasalProfileEntry?] = []
+            for p in provider.profile {
+                var np: BasalProfileEntry?
+                for b in provider.autotune?.basalProfile ?? [] {
+                    if b.start > p.start {
+                        NSLog("Matched \(p) with \(b)")
+                        break
+                    }
+                    np = b
+                }
+                bp.append(np)
+            }
+            NSLog("basalProfile \(bp)")
+            autotuneProfile = bp
         }
 
         func add() {

+ 22 - 10
FreeAPS/Sources/Modules/BasalProfileEditor/View/BasalProfileEditorRootView.swift

@@ -105,16 +105,28 @@ extension BasalProfileEditor {
             List {
                 ForEach(state.items.indexed(), id: \.1.id) { index, item in
                     NavigationLink(destination: pickers(for: index)) {
-                        HStack {
-                            Text("Rate").foregroundColor(.secondary)
-                            Text(
-                                "\(rateFormatter.string(from: state.rateValues[item.rateIndex] as NSNumber) ?? "0") U/hr"
-                            )
-                            Spacer()
-                            Text("starts at").foregroundColor(.secondary)
-                            Text(
-                                "\(dateFormatter.string(from: Date(timeIntervalSince1970: state.timeValues[item.timeIndex])))"
-                            )
+                        VStack {
+                            HStack {
+                                Text("Rate").foregroundColor(.secondary)
+                                Text(
+                                    "\(rateFormatter.string(from: state.rateValues[item.rateIndex] as NSNumber) ?? "0") U/hr"
+                                )
+                                Spacer()
+                                Text("starts at").foregroundColor(.secondary)
+                                Text(
+                                    "\(dateFormatter.string(from: Date(timeIntervalSince1970: state.timeValues[item.timeIndex])))"
+                                )
+                            }
+                            if let basalProfile = state.autotuneProfile[index] {
+                                HStack {
+                                    Text("Autotune")
+                                    Text(rateFormatter.string(from: basalProfile.rate as NSNumber) ?? "0")
+                                    Text("U/hr").foregroundColor(.secondary)
+                                    Spacer()
+                                    Text("@")
+                                    Text(basalProfile.displayTime)
+                                }.font(Font.system(size: 12))
+                            }
                         }
                     }
                     .moveDisabled(true)