Kaynağa Gözat

Add SMB flag for treatment history (#219)

* Add SMB flag and robot emoji for SMB boluses
Deniz Cengiz 2 yıl önce
ebeveyn
işleme
53ccbfa736

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

@@ -44,7 +44,8 @@ final class BasePumpHistoryStorage: PumpHistoryStorage, Injectable {
                         durationMin: nil,
                         durationMin: nil,
                         rate: nil,
                         rate: nil,
                         temp: nil,
                         temp: nil,
-                        carbInput: nil
+                        carbInput: nil,
+                        isSMB: dose.automatic
                     )]
                     )]
                 case .tempBasal:
                 case .tempBasal:
                     guard let dose = event.dose else { return [] }
                     guard let dose = event.dose else { return [] }

+ 5 - 1
FreeAPS/Sources/Models/PumpHistoryEvent.swift

@@ -11,6 +11,7 @@ struct PumpHistoryEvent: JSON, Equatable {
     let temp: TempType?
     let temp: TempType?
     let carbInput: Int?
     let carbInput: Int?
     let note: String?
     let note: String?
+    let isSMB: Bool?
 
 
     init(
     init(
         id: String,
         id: String,
@@ -22,7 +23,8 @@ struct PumpHistoryEvent: JSON, Equatable {
         rate: Decimal? = nil,
         rate: Decimal? = nil,
         temp: TempType? = nil,
         temp: TempType? = nil,
         carbInput: Int? = nil,
         carbInput: Int? = nil,
-        note: String? = nil
+        note: String? = nil,
+        isSMB: Bool? = nil
     ) {
     ) {
         self.id = id
         self.id = id
         self.type = type
         self.type = type
@@ -34,6 +36,7 @@ struct PumpHistoryEvent: JSON, Equatable {
         self.temp = temp
         self.temp = temp
         self.carbInput = carbInput
         self.carbInput = carbInput
         self.note = note
         self.note = note
+        self.isSMB = isSMB
     }
     }
 }
 }
 
 
@@ -80,5 +83,6 @@ extension PumpHistoryEvent {
         case temp
         case temp
         case carbInput = "carb_input"
         case carbInput = "carb_input"
         case note
         case note
+        case isSMB
     }
     }
 }
 }

+ 14 - 8
FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift

@@ -66,8 +66,9 @@ enum DataTable {
         let isFPU: Bool?
         let isFPU: Bool?
         let fpuID: String?
         let fpuID: String?
         let note: String?
         let note: String?
+        let isSMB: Bool?
 
 
-        private var numberFormater: NumberFormatter {
+        private var numberFormatter: NumberFormatter {
             let formatter = NumberFormatter()
             let formatter = NumberFormatter()
             formatter.numberStyle = .decimal
             formatter.numberStyle = .decimal
             formatter.maximumFractionDigits = 2
             formatter.maximumFractionDigits = 2
@@ -92,7 +93,8 @@ enum DataTable {
             idPumpEvent: String? = nil,
             idPumpEvent: String? = nil,
             isFPU: Bool? = false,
             isFPU: Bool? = false,
             fpuID: String? = nil,
             fpuID: String? = nil,
-            note: String? = nil
+            note: String? = nil,
+            isSMB: Bool? = nil
         ) {
         ) {
             self.units = units
             self.units = units
             self.type = type
             self.type = type
@@ -105,6 +107,7 @@ enum DataTable {
             self.isFPU = isFPU
             self.isFPU = isFPU
             self.fpuID = fpuID
             self.fpuID = fpuID
             self.note = note
             self.note = note
+            self.isSMB = isSMB
         }
         }
 
 
         static func == (lhs: Treatment, rhs: Treatment) -> Bool {
         static func == (lhs: Treatment, rhs: Treatment) -> Bool {
@@ -126,14 +129,17 @@ enum DataTable {
 
 
             switch type {
             switch type {
             case .carbs:
             case .carbs:
-                return numberFormater.string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carbs")
+                return numberFormatter
+                    .string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carbs")
             case .fpus:
             case .fpus:
-                return numberFormater
+                return numberFormatter
                     .string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carb equilvalents")
                     .string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carb equilvalents")
             case .bolus:
             case .bolus:
-                return numberFormater.string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
+                return numberFormatter
+                    .string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit") +
+                    "\(isSMB ?? false ? " SMB" : "")"
             case .tempBasal:
             case .tempBasal:
-                return numberFormater
+                return numberFormatter
                     .string(from: amount as NSNumber)! + NSLocalizedString(" U/hr", comment: "Unit insulin per hour")
                     .string(from: amount as NSNumber)! + NSLocalizedString(" U/hr", comment: "Unit insulin per hour")
             case .tempTarget:
             case .tempTarget:
                 var converted = amount
                 var converted = amount
@@ -142,7 +148,7 @@ enum DataTable {
                 }
                 }
 
 
                 guard var secondAmount = secondAmount else {
                 guard var secondAmount = secondAmount else {
-                    return numberFormater.string(from: converted as NSNumber)! + " \(units.rawValue)"
+                    return numberFormatter.string(from: converted as NSNumber)! + " \(units.rawValue)"
                 }
                 }
                 if units == .mmolL {
                 if units == .mmolL {
                     secondAmount = secondAmount.asMmolL
                     secondAmount = secondAmount.asMmolL
@@ -177,7 +183,7 @@ enum DataTable {
             guard let duration = duration, duration > 0 else {
             guard let duration = duration, duration > 0 else {
                 return nil
                 return nil
             }
             }
-            return numberFormater.string(from: duration as NSNumber)! + " min"
+            return numberFormatter.string(from: duration as NSNumber)! + " min"
         }
         }
     }
     }
 
 

+ 8 - 1
FreeAPS/Sources/Modules/DataTable/DataTableStateModel.swift

@@ -66,7 +66,14 @@ extension DataTable {
                 let boluses = self.provider.pumpHistory()
                 let boluses = self.provider.pumpHistory()
                     .filter { $0.type == .bolus }
                     .filter { $0.type == .bolus }
                     .map {
                     .map {
-                        Treatment(units: units, type: .bolus, date: $0.timestamp, amount: $0.amount, idPumpEvent: $0.id)
+                        Treatment(
+                            units: units,
+                            type: .bolus,
+                            date: $0.timestamp,
+                            amount: $0.amount,
+                            idPumpEvent: $0.id,
+                            isSMB: $0.isSMB
+                        )
                     }
                     }
 
 
                 let tempBasals = self.provider.pumpHistory()
                 let tempBasals = self.provider.pumpHistory()

+ 1 - 1
FreeAPS/Sources/Modules/DataTable/View/DataTableRootView.swift

@@ -113,7 +113,7 @@ extension DataTable {
                 Image(systemName: "circle.fill").foregroundColor(item.color)
                 Image(systemName: "circle.fill").foregroundColor(item.color)
                 Text(dateFormatter.string(from: item.date))
                 Text(dateFormatter.string(from: item.date))
                     .moveDisabled(true)
                     .moveDisabled(true)
-                Text(item.type.name)
+                Text((item.isSMB ?? false) ? "🤖" : item.type.name)
                 Text(item.amountText).foregroundColor(.secondary)
                 Text(item.amountText).foregroundColor(.secondary)
 
 
                 if let duration = item.durationText {
                 if let duration = item.durationText {