Jonas Björkert 1 год назад
Родитель
Сommit
744d9f7896

+ 2 - 2
LoopFollow/Alarm/AlarmCondition/AlarmCondition.swift

@@ -8,7 +8,7 @@ protocol AlarmCondition {
     static var type: AlarmType { get }
     init()
     /// pure, per-alarm logic against `AlarmData`
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool
+    func evaluate(alarm: Alarm, data: AlarmData, now: Date) -> Bool
 }
 
 extension AlarmCondition {
@@ -78,6 +78,6 @@ extension AlarmCondition {
         }
 
         // finally, run the type-specific logic
-        return evaluate(alarm: alarm, data: data)
+        return evaluate(alarm: alarm, data: data, now: now)
     }
 }

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/BuildExpireCondition.swift

@@ -8,7 +8,7 @@ struct BuildExpireCondition: AlarmCondition {
     static let type: AlarmType = .buildExpire
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let expiry = data.expireDate else { return false }
         guard let thresholdDays = alarm.threshold else { return false }
 

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/COBCondition.swift

@@ -8,7 +8,7 @@ struct COBCondition: AlarmCondition {
     static let type: AlarmType = .cob
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let threshold = alarm.threshold, threshold > 0 else { return false }
         guard let cob = data.COB, cob >= threshold else {
             Storage.shared.lastCOBNotified.value = nil

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/FastDropCondition.swift

@@ -8,7 +8,7 @@ struct FastDropCondition: AlarmCondition {
     static let type: AlarmType = .fastDrop
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // ────────────────────────────────
         // 0. sanity checks
         // ────────────────────────────────

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/FastRiseCondition.swift

@@ -9,7 +9,7 @@ struct FastRiseCondition: AlarmCondition {
     static let type: AlarmType = .fastRise
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard
             let rise = alarm.delta, rise > 0,
             let streak = alarm.monitoringWindow, streak > 0,

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/HighBGCondition.swift

@@ -9,7 +9,7 @@ struct HighBGCondition: AlarmCondition {
     static let type: AlarmType = .high
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // ────────────────────────────────
         // 0. get the limit
         // ────────────────────────────────

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/LowBGCondition.swift

@@ -11,7 +11,7 @@ struct LowBGCondition: AlarmCondition {
     static let type: AlarmType = .low
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // ────────────────────────────────
         // 0. sanity checks
         // ────────────────────────────────

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/MissedReadingCondition.swift

@@ -9,7 +9,7 @@ struct MissedReadingCondition: AlarmCondition {
     static let type: AlarmType = .missedReading
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // ────────────────────────────────
         // 0. sanity checks
         // ────────────────────────────────

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/NotLoopingCondition.swift

@@ -8,7 +8,7 @@ struct NotLoopingCondition: AlarmCondition {
     static let type: AlarmType = .notLooping
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // ────────────────────────────────
         // 0. sanity checks
         // ────────────────────────────────

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/OverrideEndCondition.swift

@@ -8,7 +8,7 @@ struct OverrideEndCondition: AlarmCondition {
     static let type: AlarmType = .overrideEnd
     init() {}
 
-    func evaluate(alarm _: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm _: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let endTS = data.latestOverrideEnd, endTS > 0 else { return false }
         guard Date().timeIntervalSince1970 - endTS <= 15 * 60 else { return false }
 

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/OverrideStartCondition.swift

@@ -8,7 +8,7 @@ struct OverrideStartCondition: AlarmCondition {
     static let type: AlarmType = .overrideStart
     init() {}
 
-    func evaluate(alarm _: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm _: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let startTS = data.latestOverrideStart, startTS > 0 else { return false }
 
         let recent = Date().timeIntervalSince1970 - startTS <= 15 * 60

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/PumpChangeCondition.swift

@@ -20,7 +20,7 @@ struct PumpChangeCondition: AlarmCondition {
     /// Pod lifetime = 3 days = 72 h
     private let lifetime: TimeInterval = 3 * 24 * 60 * 60
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // 0. sanity guards
         guard let warnAheadHrs = alarm.threshold, warnAheadHrs > 0 else { return false }
         guard let insertTS = data.pumpInsertTime else { return false }

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/PumpVolumeCondition.swift

@@ -17,7 +17,7 @@ struct PumpVolumeCondition: AlarmCondition {
     static let type: AlarmType = .pump
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let threshold = alarm.threshold, threshold > 0 else { return false }
         guard let latestVol = data.latestPumpVolume else { return false }
 

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/RecBolusCondition.swift

@@ -9,7 +9,7 @@ struct RecBolusCondition: AlarmCondition {
     static let type: AlarmType = .recBolus
     init() {}
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // ────────────────────────────────
         // 0. sanity checks
         // ────────────────────────────────

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/SensorAgeCondition.swift

@@ -13,7 +13,7 @@ struct SensorAgeCondition: AlarmCondition {
     /// Dexcom hard-stop = 10 days = 240 h
     private let lifetime: TimeInterval = 10 * 24 * 60 * 60
 
-    func evaluate(alarm: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data: AlarmData, now _: Date) -> Bool {
         // 0. basic guards
         guard let warnAheadHrs = alarm.threshold, warnAheadHrs > 0 else { return false }
         guard let insertTS = data.sageInsertTime else { return false }

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/TempTargetEndCondition.swift

@@ -9,7 +9,7 @@ struct TempTargetEndCondition: AlarmCondition {
     static let type: AlarmType = .tempTargetEnd
     init() {}
 
-    func evaluate(alarm _: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm _: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let endTS = data.latestTempTargetEnd, endTS > 0 else { return false }
         guard Date().timeIntervalSince1970 - endTS <= 15 * 60 else { return false }
 

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/TempTargetStartCondition.swift

@@ -9,7 +9,7 @@ struct TempTargetStartCondition: AlarmCondition {
     static let type: AlarmType = .tempTargetStart
     init() {}
 
-    func evaluate(alarm _: Alarm, data: AlarmData) -> Bool {
+    func evaluate(alarm _: Alarm, data: AlarmData, now _: Date) -> Bool {
         guard let startTS = data.latestTempTargetStart, startTS > 0 else { return false }
         guard Date().timeIntervalSince1970 - startTS <= 15 * 60 else { return false }
 

+ 1 - 1
LoopFollow/Alarm/AlarmCondition/TemporaryCondition.swift

@@ -9,7 +9,7 @@ struct TemporaryCondition: AlarmCondition {
     static let type: AlarmType = .temporary
     init() {}
 
-    func evaluate(alarm: Alarm, data _: AlarmData) -> Bool {
+    func evaluate(alarm: Alarm, data _: AlarmData, now _: Date) -> Bool {
         // Needs at least ONE limit
         guard alarm.belowBG != nil || alarm.aboveBG != nil else { return false }