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

Add insulin distribution to statistics.json

Jon Mårtensson 3 лет назад
Родитель
Сommit
1ba4e972ae

+ 1 - 1
Config.xcconfig

@@ -1,5 +1,5 @@
 APP_DISPLAY_NAME = FreeAPS X
-APP_VERSION = 0.4.9
+APP_VERSION = 0.5.0
 APP_BUILD_NUMBER = 1
 BRANCH = bdb
 DEVELOPER_TEAM = ##TEAM_ID##

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
FreeAPS/Resources/javascript/bundle/determine-basal.js


+ 16 - 4
FreeAPS/Sources/APS/APSManager.swift

@@ -743,7 +743,6 @@ final class BaseAPSManager: APSManager, Injectable {
         guard !array.isEmpty else {
             return 0
         }
-        let units = settingsManager.settings.units
         let sorted = array.sorted()
         let length = array.count
 
@@ -1170,6 +1169,15 @@ final class BaseAPSManager: APSManager, Injectable {
 
         let avg = Averages(Average: [avgs], Median: [median])
 
+        let suggestion = storage.retrieve(OpenAPS.Enact.suggested, as: Suggestion.self)
+
+        let insulin = Ins(
+            TDD: roundDecimal(currentTDD, 2),
+            bolus: suggestion?.insulin?.bolus ?? 0,
+            temp_basal: suggestion?.insulin?.temp_basal ?? 0,
+            scheduled_basal: suggestion?.insulin?.scheduled_basal ?? 0
+        )
+
         let dailystat = Statistics(
             createdAt: Date(),
             iPhone: UIDevice.current.getDeviceId,
@@ -1184,11 +1192,15 @@ final class BaseAPSManager: APSManager, Injectable {
             CGM: cgm.rawValue,
             insulinType: insulin_type.rawValue,
             peakActivityTime: iPa,
-            TDD: roundDecimal(currentTDD, 2),
             Carbs_24h: carbTotal,
             GlucoseStorage_Days: Decimal(daysBG),
-            Statistics: Stats(Distribution: [TimeInRange], Glucose: [avg], HbA1c: [hbs], LoopCycles: [loopstat])
-            // LoopStats: [loopstat]
+            Statistics: Stats(
+                Distribution: [TimeInRange],
+                Glucose: [avg],
+                HbA1c: [hbs],
+                LoopCycles: [loopstat],
+                Insulin: [insulin]
+            )
         )
 
         storage.transaction { storage in

+ 18 - 4
FreeAPS/Sources/Models/Statistics.swift

@@ -14,7 +14,6 @@ struct Statistics: JSON, Equatable {
     var CGM: String
     var insulinType: String
     var peakActivityTime: Decimal
-    var TDD: Decimal
     var Carbs_24h: Decimal
     var GlucoseStorage_Days: Decimal
     var Statistics: Stats
@@ -33,7 +32,6 @@ struct Statistics: JSON, Equatable {
         CGM: String,
         insulinType: String,
         peakActivityTime: Decimal,
-        TDD: Decimal,
         Carbs_24h: Decimal,
         GlucoseStorage_Days: Decimal,
         Statistics: Stats
@@ -51,7 +49,6 @@ struct Statistics: JSON, Equatable {
         self.CGM = CGM
         self.insulinType = insulinType
         self.peakActivityTime = peakActivityTime
-        self.TDD = TDD
         self.Carbs_24h = Carbs_24h
         self.GlucoseStorage_Days = GlucoseStorage_Days
         self.Statistics = Statistics
@@ -81,7 +78,6 @@ extension Statistics {
         case CGM
         case insulinType
         case peakActivityTime
-        case TDD
         case Carbs_24h
         case GlucoseStorage_Days
         case Statistics
@@ -161,11 +157,19 @@ struct Hypers: JSON, Equatable {
     var total: Decimal
 }
 
+struct Ins: JSON, Equatable {
+    let TDD: Decimal?
+    let bolus: Decimal?
+    let temp_basal: Decimal?
+    let scheduled_basal: Decimal?
+}
+
 struct Stats: JSON, Equatable {
     var Distribution: [TIRs]
     var Glucose: [Averages]
     var HbA1c: [Hbs]
     var LoopCycles: [LoopCycles]
+    var Insulin: [Ins]
 }
 
 extension LoopCycles {
@@ -249,11 +253,21 @@ extension Hypers {
     }
 }
 
+extension Ins {
+    private enum CodingKeys: String, CodingKey {
+        case TDD
+        case bolus
+        case temp_basal
+        case scheduled_basal
+    }
+}
+
 extension Stats {
     private enum CodingKeys: String, CodingKey {
         case Distribution
         case Glucose
         case HbA1c
         case LoopCycles
+        case Insulin
     }
 }

+ 18 - 0
FreeAPS/Sources/Models/Suggestion.swift

@@ -20,6 +20,7 @@ struct Suggestion: JSON, Equatable {
     var timestamp: Date?
     var recieved: Bool?
     let tdd: Decimal?
+    let insulin: Insulin?
 }
 
 struct Predictions: JSON, Equatable {
@@ -29,6 +30,13 @@ struct Predictions: JSON, Equatable {
     let uam: [Int]?
 }
 
+struct Insulin: JSON, Equatable {
+    let TDD: Decimal?
+    let bolus: Decimal?
+    let temp_basal: Decimal?
+    let scheduled_basal: Decimal?
+}
+
 extension Suggestion {
     private enum CodingKeys: String, CodingKey {
         case reason
@@ -50,6 +58,7 @@ extension Suggestion {
         case recieved
         case isf = "ISF"
         case tdd = "TDD"
+        case insulin
     }
 }
 
@@ -62,6 +71,15 @@ extension Predictions {
     }
 }
 
+extension Insulin {
+    private enum CodingKeys: String, CodingKey {
+        case TDD
+        case bolus
+        case temp_basal
+        case scheduled_basal
+    }
+}
+
 protocol SuggestionObserver {
     func suggestionDidUpdate(_ suggestion: Suggestion)
 }