polscm32 1 год назад
Родитель
Сommit
9e3bb1379b

+ 2 - 3
FreeAPS/Sources/Models/RawFetchedProfile.swift

@@ -8,11 +8,10 @@ struct FetchedNightscoutProfileStore: JSON {
     // <<<<<<< HEAD
     let mills: Decimal
     let enteredBy: String
-    let store: [String: ScheduledNightscoutProfile]
+//    let store: [String: ScheduledNightscoutProfile]
     let created_at: String
     //=======
-//    let enteredBy: String
-//    let store: [String: FetchedNightscoutProfile]
+    let store: [String: FetchedNightscoutProfile]
     // >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
 }
 

+ 25 - 23
FreeAPS/Sources/Services/Network/TidepoolManager.swift

@@ -12,7 +12,7 @@ protocol TidepoolManager {
     func deleteCarbs(at date: Date, isFPU: Bool?, fpuID: String?, syncID: String)
     func deleteInsulin(at date: Date)
 //    func uploadStatus()
-    func uploadGlucose(device: HKDevice?)
+    func uploadGlucose(device: HKDevice?) async
     func forceUploadData(device: HKDevice?)
 //    func uploadPreferences(_ preferences: Preferences)
 //    func uploadProfileAndSettings(_: Bool)
@@ -317,39 +317,41 @@ final class BaseTidepoolManager: TidepoolManager, Injectable {
         }
     }
 
-    func uploadGlucose(device: HKDevice?) {
-        let glucose: [BloodGlucose] = glucoseStorage.recent()
-
+    func uploadGlucose(device: HKDevice?) async {
+        // TODO: get correct glucose values
+        let glucose: [BloodGlucose] = await glucoseStorage.getGlucoseNotYetUploadedToNightscout()
+        
         guard !glucose.isEmpty, let tidepoolService = self.tidepoolService else { return }
-
-        let glucoseWithoutCorrectID = glucose.filter { UUID(uuidString: $0._id) != nil }
-
+        
+        let glucoseWithoutCorrectID = glucose.filter { UUID(uuidString: $0._id ?? UUID().uuidString) != nil }
+        
+        let chunks = glucoseWithoutCorrectID.chunks(ofCount: tidepoolService.glucoseDataLimit ?? 100)
+        
         processQueue.async {
-            glucoseWithoutCorrectID.chunks(ofCount: tidepoolService.glucoseDataLimit ?? 100)
-                .forEach { chunk in
-                    // all glucose attached with the current device ;-(
-
-                    let chunkStoreGlucose = Array(chunk).map {
-                        $0.convertStoredGlucoseSample(device: device)
-                    }
-                    tidepoolService.uploadGlucoseData(chunkStoreGlucose) { result in
-                        switch result {
-                        case let .failure(error):
-                            debug(.nightscout, "Error synchronizing glucose data: \(String(describing: error))")
-                        // self.uploadFailed(key)
+            for chunk in chunks {
+                // Link all glucose values with the current device
+                let chunkStoreGlucose = chunk.map { $0.convertStoredGlucoseSample(device: device) }
+                
+                tidepoolService.uploadGlucoseData(chunkStoreGlucose) { result in
+                    switch result {
                         case .success:
                             debug(.nightscout, "Success synchronizing glucose data:")
-                        }
+                        case .failure(let error):
+                            debug(.nightscout, "Error synchronizing glucose data: \(String(describing: error))")
+                            // self.uploadFailed(key)
                     }
                 }
+            }
         }
     }
 
     /// force to uploads all data in Tidepool Service
     func forceUploadData(device: HKDevice?) {
-        uploadDose()
-        uploadCarbs()
-        uploadGlucose(device: device)
+        Task {
+            uploadDose()
+            uploadCarbs()
+            await uploadGlucose(device: device)
+        }
     }
 }
 

+ 2 - 3
Trio.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -1,5 +1,4 @@
 {
-  "originHash" : "59ac7eba66375d6eb406e758cb0b9964f4b3b0ae45c5665596f00384c32262b9",
   "pins" : [
     {
       "identity" : "cryptoswift",
@@ -49,7 +48,7 @@
     {
       "identity" : "swiftcharts",
       "kind" : "remoteSourceControl",
-      "location" : "https://github.com/ivanschuetz/SwiftCharts.git",
+      "location" : "https://github.com/ivanschuetz/SwiftCharts",
       "state" : {
         "branch" : "master",
         "revision" : "c354c1945bb35a1f01b665b22474f6db28cba4a2"
@@ -92,5 +91,5 @@
       }
     }
   ],
-  "version" : 3
+  "version" : 2
 }