Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions LoopFollow/Controllers/Nightscout/BGData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,26 @@ extension MainViewController {
return
}

// Dexcom only returns 24 hrs of data. If we need more, call NS.
if graphHours > 24, IsNightscoutEnabled() {
self.webLoadNSBGData(dexData: data)
// Dexcom Share can return duplicate readings when multiple uploaders
// write to the same Dexcom account. Dedup before any further use.
var dedupedData: [ShareGlucoseData] = []
var lastDexTime = Double.infinity
var lastDexSGV: Int?
for reading in data {
if lastDexSGV == nil || lastDexSGV != reading.sgv || (lastDexTime - reading.date >= 30) {
dedupedData.append(reading)
lastDexTime = reading.date
lastDexSGV = reading.sgv
}
}

// Supplement with NS if Dex data doesn't cover the full requested window.
let dexCutoff = dateTimeUtils.getNowTimeIntervalUTC() - Double(graphHours) * 3600
let dexCoversFull = dedupedData.last.map { $0.date <= dexCutoff } ?? false
if !dexCoversFull, IsNightscoutEnabled() {
self.webLoadNSBGData(dexData: dedupedData)
} else {
self.ProcessDexBGData(data: data, sourceName: "Dexcom")
self.ProcessDexBGData(data: dedupedData, sourceName: "Dexcom")
}
}
}
Expand All @@ -52,7 +67,7 @@ extension MainViewController {

var parameters: [String: String] = [:]
let date = Calendar.current.date(byAdding: .day, value: -1 * Storage.shared.downloadDays.value, to: Date())!
parameters["count"] = "\(Storage.shared.downloadDays.value * 2 * 24 * 60 / 5)"
parameters["count"] = "\(Storage.shared.downloadDays.value * 4 * 24 * 60 / 5)"
parameters["find[date][$gte]"] = "\(Int(date.timeIntervalSince1970 * 1000))"

// Exclude 'cal' entries
Expand Down
2 changes: 1 addition & 1 deletion LoopFollow/Stats/StatsDataFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StatsDataFetcher {
var parameters: [String: String] = [:]
let utcISODateFormatter = ISO8601DateFormatter()
let startDate = dataService?.startDate ?? dateTimeUtils.displayCalendar().date(byAdding: .day, value: -1 * days, to: Date())!
parameters["count"] = "\(days * 2 * 24 * 60 / 5)"
parameters["count"] = "\(days * 4 * 24 * 60 / 5)"
parameters["find[dateString][$gte]"] = utcISODateFormatter.string(from: startDate)
parameters["find[type][$ne]"] = "cal"

Expand Down
Loading