Explorar el Código

Change DIA -> durationOfInsulinAction

Sam King hace 5 meses
padre
commit
25a27bcc65
Se han modificado 1 ficheros con 7 adiciones y 5 borrados
  1. 7 5
      Trio/Sources/APS/OpenAPSSwift/Iob/IobGenerator.swift

+ 7 - 5
Trio/Sources/APS/OpenAPSSwift/Iob/IobGenerator.swift

@@ -9,13 +9,14 @@ struct IobGenerator {
     ) throws -> [IobResult] {
         // As a performance optimization, filter out any pump events
         // that occurred before the DIA would use it
-        let diaAgo = Double(profile.dia ?? 10) * 60 * 60
+        let durationOfInsulinActionAgo = Double(profile.dia ?? 10) * 60 * 60
         // add an extra two hours to the DIA to ensure we get all temp basals
-        let lastDia = clock - diaAgo - 2.hoursToSeconds
+        let lastDurationOfInsulinAction = clock - durationOfInsulinActionAgo - 2.hoursToSeconds
 
         // we have to keep all of our suspend/resume events due to a hardcoded
         // DIA value in dealing with suspended pumps in JS
-        var pumpHistory = history.filter({ $0.timestamp >= lastDia || $0.isSuspendOrResume() }).map({ $0.computedEvent() })
+        var pumpHistory = history.filter({ $0.timestamp >= lastDurationOfInsulinAction || $0.isSuspendOrResume() })
+            .map({ $0.computedEvent() })
 
         // To make sure that lastTemp and lastBolusTime are filled in
         // correctly, we need to check if there aren't any tempBasal or bolus
@@ -23,7 +24,7 @@ struct IobGenerator {
         // from the full history and add it.
         if pumpHistory.filter({ $0.type == .tempBasal }).isEmpty {
             // Find the most recent TempBasal event from before the DIA cutoff
-            let olderTempBasals = history.filter({ $0.type == .tempBasal && $0.timestamp < lastDia })
+            let olderTempBasals = history.filter({ $0.type == .tempBasal && $0.timestamp < lastDurationOfInsulinAction })
             if let lastTempBasal = olderTempBasals.max(by: { $0.timestamp < $1.timestamp }) {
                 // Find its matching TempBasalDuration (same timestamp)
                 if let matchingDuration = history
@@ -38,7 +39,8 @@ struct IobGenerator {
         // we need to check for amount != 0 to match the lastBolusTime logic
         if pumpHistory.filter({ $0.type == .bolus && $0.amount != 0 }).isEmpty {
             // Find the most recent Bolus event from before the DIA cutoff
-            let olderBoluses = history.filter({ $0.type == .bolus && $0.amount != 0 && $0.timestamp < lastDia })
+            let olderBoluses = history
+                .filter({ $0.type == .bolus && $0.amount != 0 && $0.timestamp < lastDurationOfInsulinAction })
             if let lastBolus = olderBoluses.max(by: { $0.timestamp < $1.timestamp }) {
                 pumpHistory.append(lastBolus.computedEvent())
             }