|
@@ -17,9 +17,10 @@ struct IobGenerator {
|
|
|
// DIA value in dealing with suspended pumps in JS
|
|
// 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 >= lastDia || $0.isSuspendOrResume() }).map({ $0.computedEvent() })
|
|
|
|
|
|
|
|
- // To make sure that lastTemp is filled in correctly, we need to check
|
|
|
|
|
- // if there aren't any tempBasal events in the DIA-filtered list.
|
|
|
|
|
- // If not, find the most recent one from the full history and add it.
|
|
|
|
|
|
|
+ // To make sure that lastTemp and lastBolusTime are filled in
|
|
|
|
|
+ // correctly, we need to check if there aren't any tempBasal or bolus
|
|
|
|
|
+ // events in the DIA-filtered list. If not, find the most recent one
|
|
|
|
|
+ // from the full history and add it.
|
|
|
if pumpHistory.filter({ $0.type == .tempBasal }).isEmpty {
|
|
if pumpHistory.filter({ $0.type == .tempBasal }).isEmpty {
|
|
|
// Find the most recent TempBasal event from before the DIA cutoff
|
|
// 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 < lastDia })
|
|
@@ -34,6 +35,15 @@ 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 })
|
|
|
|
|
+ if let lastBolus = olderBoluses.max(by: { $0.timestamp < $1.timestamp }) {
|
|
|
|
|
+ pumpHistory.append(lastBolus.computedEvent())
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
let treatments = try IobHistory.calcTempTreatments(
|
|
let treatments = try IobHistory.calcTempTreatments(
|
|
|
history: pumpHistory,
|
|
history: pumpHistory,
|
|
|
profile: profile,
|
|
profile: profile,
|