Преглед изворни кода

Only safe necessary elements

Jon Mårtensson пре 3 година
родитељ
комит
71384eece1

+ 1 - 1
FreeAPS/Sources/APS/OpenAPS/Constants.swift

@@ -59,7 +59,7 @@ extension OpenAPS {
         static let alertHistory = "monitor/alerthistory.json"
         static let statistics = "monitor/statistics.json"
         static let loopStats = "monitor/loopStats.json"
-        static let glucose_data = "monitor/glucose_data.json"
+        static let glucose_data = "monitor/glucose_data.data"
     }
 
     enum Enact {

+ 17 - 2
FreeAPS/Sources/APS/Storage/GlucoseStorage.swift

@@ -33,12 +33,27 @@ final class BaseGlucoseStorage: GlucoseStorage, Injectable {
     }
 
     func storeGlucose(_ glucose: [BloodGlucose]) {
+        let storeGlucoseStarted = Date()
+
+        let stat_glucose = BloodGlucose(
+            _id: glucose[0].id,
+            sgv: nil,
+            date: glucose[0].date,
+            dateString: glucose[0].dateString,
+            unfiltered: nil,
+            filtered: nil,
+            noise: nil,
+            glucose: glucose[0].glucose ?? 0,
+            type: nil
+        )
+
         processQueue.sync {
             let file = OpenAPS.Monitor.glucose
             self.storage.transaction { storage in
                 storage.append(glucose, to: file, uniqBy: \.dateString)
-                // Save for statistics also
-                storage.append(glucose, to: OpenAPS.Monitor.glucose_data, uniqBy: \.dateString)
+
+                // Save for statistics also (only glucose, date, datestring and id)
+                storage.append(stat_glucose, to: OpenAPS.Monitor.glucose_data, uniqBy: \.id)
 
                 let uniqEvents = storage.retrieve(file, as: [BloodGlucose].self)?
                     .filter { $0.dateString.addingTimeInterval(24.hours.timeInterval) > Date() }