Skip to content

Commit

Permalink
fix Blood glucose ID with Nightscout
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
avouspierre authored and Jon-b-m committed Nov 22, 2023
1 parent e80718e commit c79c7c5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion FreeAPS/Sources/APS/CGM/dexcomSourceG7.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
5 changes: 4 additions & 1 deletion FreeAPS/Sources/Services/Network/NightscoutManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,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))
}
Expand Down

0 comments on commit c79c7c5

Please sign in to comment.