File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -800,14 +800,21 @@ final class LoopDataManager {
800800 insulinEffect. filterDateRange ( startDate, endDate)
801801 )
802802
803+ // Ensure we're not repeating effects
804+ if let lastEffect = insulinCounteractionEffects. last {
805+ guard startDate >= lastEffect. endDate else {
806+ return
807+ }
808+ }
809+
803810 // Compare that retrospective, insulin-driven prediction to the actual glucose change to
804811 // calculate the effect of all insulin counteraction
805812 guard let lastGlucose = prediction. last else { return }
806813 let glucoseUnit = HKUnit . milligramsPerDeciliter ( )
807814 let velocityUnit = glucoseUnit. unitDivided ( by: HKUnit . second ( ) )
808815 let discrepancy = change. end. quantity. doubleValue ( for: glucoseUnit) - lastGlucose. quantity. doubleValue ( for: glucoseUnit) // mg/dL
809816 let averageVelocity = HKQuantity ( unit: velocityUnit, doubleValue: discrepancy / change. end. endDate. timeIntervalSince ( change. start. endDate) )
810- let effect = GlucoseEffectVelocity ( startDate: change . start . startDate, endDate: change. end. startDate, quantity: averageVelocity)
817+ let effect = GlucoseEffectVelocity ( startDate: startDate, endDate: change. end. startDate, quantity: averageVelocity)
811818
812819 insulinCounteractionEffects. append ( effect)
813820 // For now, only keep the last 24 hours of values
You can’t perform that action at this time.
0 commit comments