diff --git a/FreeAPS/Sources/APS/APSManager.swift b/FreeAPS/Sources/APS/APSManager.swift index bc46b37058..48aed6a0fc 100644 --- a/FreeAPS/Sources/APS/APSManager.swift +++ b/FreeAPS/Sources/APS/APSManager.swift @@ -745,18 +745,14 @@ final class BaseAPSManager: APSManager, Injectable { requestStats.fetchLimit = 1 try? stats = coredataContext.fetch(requestStats) // Only save and upload once per day - guard (-1 * (stats.first?.lastrun ?? now).timeIntervalSinceNow.hours) > 22 else { return } + guard (-1 * (stats.first?.lastrun ?? .distantPast).timeIntervalSinceNow.hours) > 22 else { return } let units = self.settingsManager.settings.units let preferences = settingsManager.preferences - - // MARK: Fetch Carbs from CoreData - + var carbs = [Carbohydrates]() var carbTotal: Decimal = 0 - let requestCarbs = Carbohydrates.fetchRequest() as NSFetchRequest - let daysAgo = Date().addingTimeInterval(-1.days.timeInterval) requestCarbs.predicate = NSPredicate(format: "carbs > 0 AND date > %@", daysAgo as NSDate) @@ -1335,13 +1331,7 @@ final class BaseAPSManager: APSManager, Injectable { ) ) - storage.transaction { storage in - storage.append(dailystat, to: file, uniqBy: \.created_at) - let uniqeEvents: [Statistics] = storage.retrieve(file, as: [Statistics].self)? - .filter { $0.created_at.addingTimeInterval(24.hours.timeInterval) > Date() } - .sorted { $0.created_at > $1.created_at } ?? [] - storage.save(Array(uniqeEvents), as: file) - } + storage.save(dailystat, as: file) nightscout.uploadStatistics(dailystat: dailystat) nightscout.uploadPreferences() diff --git a/FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift b/FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift index a31c7d50eb..5ad7588b9c 100644 --- a/FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift +++ b/FreeAPS/Sources/Modules/StatConfig/View/StatConfigRootView.swift @@ -31,7 +31,7 @@ extension StatConfig { Toggle("Allow Upload of Statistics to NS", isOn: $state.uploadStats) Toggle("Display Chart X - Grid lines", isOn: $state.xGridLines) Toggle("Display Chart Y - Grid lines", isOn: $state.yGridLines) - Toggle("Display Chart Threshold lines for Low and High)", isOn: $state.rulerMarks) + Toggle("Display Chart Threshold lines for Low and High", isOn: $state.rulerMarks) Toggle("Standing / Laying TIR Chart", isOn: $state.oneDimensionalGraph) HStack { diff --git a/FreeAPS/Sources/Views/DecimalTextField.swift b/FreeAPS/Sources/Views/DecimalTextField.swift index a5c1bc5e26..7b46a960f0 100644 --- a/FreeAPS/Sources/Views/DecimalTextField.swift +++ b/FreeAPS/Sources/Views/DecimalTextField.swift @@ -67,7 +67,9 @@ struct DecimalTextField: UIViewRepresentable { let coordinator = context.coordinator if coordinator.isEditing { coordinator.resetEditing() - } else /* if value != 0 */ { + } else if value == 0 { + textField.text = "" + } else { textField.text = formatter.string(for: value) } }