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

fix Blood glucose ID with Nightscout

Fix #280 with checking the compliance of ID as uuid. Not perfect (lost data in NS) but avoid the 500 error.
Fix for G7 sensor.
Pierre L 2 лет назад
Родитель
Сommit
7c7693c053

+ 1 - 1
FreeAPS/Sources/APS/CGM/dexcomSourceG7.swift

@@ -148,7 +148,7 @@ extension DexcomSourceG7: CGMManagerDelegate {
                 let quantity = newGlucoseSample.quantity
                 let value = Int(quantity.doubleValue(for: .milligramsPerDeciliter))
                 return BloodGlucose(
-                    _id: newGlucoseSample.syncIdentifier,
+                    _id: UUID().uuidString,
                     sgv: value,
                     direction: .init(trendType: newGlucoseSample.trend),
                     date: Decimal(Int(newGlucoseSample.date.timeIntervalSince1970 * 1000)),

+ 4 - 1
FreeAPS/Sources/Services/Network/NightscoutManager.swift

@@ -610,9 +610,12 @@ final class BaseNightscoutManager: NightscoutManager, Injectable {
         guard !glucose.isEmpty, let nightscout = nightscoutAPI, isUploadEnabled, isUploadGlucoseEnabled else {
             return
         }
+        // check if unique code
+        // var uuid = UUID(uuidString: yourString) This will return nil if yourString is not a valid UUID
+        let glucoseWithoutCorrectID = glucose.filter { UUID(uuidString: $0._id) != nil }
 
         processQueue.async {
-            glucose.chunks(ofCount: 100)
+            glucoseWithoutCorrectID.chunks(ofCount: 100)
                 .map { chunk -> AnyPublisher<Void, Error> in
                     nightscout.uploadGlucose(Array(chunk))
                 }