polscm32 aka Marvout 1 год назад
Родитель
Сommit
8cf205bf95

+ 7 - 1
FreeAPS/Sources/Modules/Stat/StatStateModel+Setup/BolusStatsSetup.swift

@@ -67,7 +67,13 @@ extension Stat.StateModel {
             let calendar = Calendar.current
 
             // Group entries by hour for hourly statistics
-            let hourlyGrouped = Dictionary(grouping: fetchedResults) { entry in
+            let now = Date()
+            let twentyDaysAgo = Calendar.current.date(byAdding: .day, value: -20, to: now) ?? now
+
+            let hourlyGrouped = Dictionary(grouping: fetchedResults.filter { entry in
+                guard let date = entry.pumpEvent?.timestamp else { return false }
+                return date >= twentyDaysAgo && date <= now
+            }) { entry in
                 let components = calendar.dateComponents(
                     [.year, .month, .day, .hour],
                     from: entry.pumpEvent?.timestamp ?? Date()

+ 7 - 1
FreeAPS/Sources/Modules/Stat/StatStateModel+Setup/MealStatsSetup.swift

@@ -61,7 +61,13 @@ extension Stat.StateModel {
             let calendar = Calendar.current
 
             // Group entries by hour for hourly statistics
-            let hourlyGrouped = Dictionary(grouping: fetchedResults) { entry in
+            let now = Date()
+            let twentyDaysAgo = Calendar.current.date(byAdding: .day, value: -20, to: now) ?? now
+
+            let hourlyGrouped = Dictionary(grouping: fetchedResults.filter { entry in
+                guard let date = entry.date else { return false }
+                return date >= twentyDaysAgo && date <= now
+            }) { entry in
                 let components = calendar.dateComponents([.year, .month, .day, .hour], from: entry.date ?? Date())
                 return calendar.date(from: components) ?? Date()
             }