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

Override uniq entries in storage

Ivan Valkou 5 лет назад
Родитель
Сommit
ebadabe947

+ 1 - 1
FreeAPS/Sources/APS/DeviceDataManager.swift

@@ -235,7 +235,7 @@ extension BaseDeviceDataManager: PumpManagerDelegate {
         completion: @escaping (_ error: Error?) -> Void
     ) {
         dispatchPrecondition(condition: .onQueue(processQueue))
-        debug(.deviceManager, "New pump events: \(events)")
+        debug(.deviceManager, "New pump events:\n\(events.map(\.title).joined(separator: "\n"))")
         pumpHistoryStorage.storePumpEvents(events)
         lastEventDate = events.last?.date
         completion(nil)

+ 2 - 0
FreeAPS/Sources/APS/Storage/PumpHistoryStorage.swift

@@ -33,6 +33,8 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                     guard let dose = event.dose else { return [] }
                     let amount = Decimal(string: dose.unitsInDeliverableIncrements.description)
                     let minutes = Int((dose.endDate - dose.startDate).timeInterval / 60)
+
+//                    print("ASDF: \(String(describing: amount)) - \(String(describing: dose.deliveredUnits))")
                     return [PumpHistoryEvent(
                         id: id,
                         type: .bolus,

+ 9 - 6
FreeAPS/Sources/Services/Storage/FileStorage.swift

@@ -73,16 +73,19 @@ final class BaseFileStorage: FileStorage {
 
     func append<Value: JSON, T: Equatable>(_ newValues: [Value], to name: String, uniqBy keyPath: KeyPath<Value, T>) {
         if let value = retrieve(name, as: Value.self) {
-            guard newValues.first(where: { $0[keyPath: keyPath] == value[keyPath: keyPath] }) == nil else {
+            if newValues.firstIndex(where: { $0[keyPath: keyPath] == value[keyPath: keyPath] }) != nil {
+                save(newValues, as: name)
                 return
             }
             append(newValues, to: name)
-        } else if let values = retrieve(name, as: [Value].self) {
-            newValues.forEach { newValue in
-                guard values.first(where: { $0[keyPath: keyPath] == newValue[keyPath: keyPath] }) == nil else {
-                    return
+        } else if var values = retrieve(name, as: [Value].self) {
+            for newValue in newValues {
+                if let index = values.firstIndex(where: { $0[keyPath: keyPath] == newValue[keyPath: keyPath] }) {
+                    values[index] = newValue
+                } else {
+                    values.append(newValue)
                 }
-                append(newValue, to: name)
+                save(values, as: name)
             }
         } else {
             save(newValues, as: name)

+ 1 - 1
FreeAPS/Sources/Views/BolusProgressViewStyle.swift

@@ -11,7 +11,7 @@ public struct BolusProgressViewStyle: ProgressViewStyle {
 
             Circle()
                 .trim(from: 0.0, to: CGFloat(configuration.fractionCompleted ?? 0))
-                .stroke(style: StrokeStyle(lineWidth: 6.0, lineCap: .round, lineJoin: .round))
+                .stroke(style: StrokeStyle(lineWidth: 6.0, lineCap: .butt, lineJoin: .round))
                 .foregroundColor(.insulin)
                 .rotationEffect(Angle(degrees: -90))
                 .frame(width: 16, height: 16)