Skip to content

Commit 70edb11

Browse files
committed
fix calculation of differential correction
1 parent 07be82e commit 70edb11

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Loop/Models/RetrospectiveCorrection/IntegralRetrospectiveCorrection.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,10 @@ class IntegralRetrospectiveCorrection: RetrospectiveCorrection {
180180
// Overall glucose effect calculated as a sum of propotional, integral and differential effects
181181
proportionalCorrection = IntegralRetrospectiveCorrection.proportionalGain * currentDiscrepancyValue
182182
// Differential effect added only when negative, to avoid upward stacking with momentum, while still mitigating sluggishness of retrospective correction when discrepancies start decreasing
183-
if differentialDiscrepancy < 0 {
183+
if differentialDiscrepancy < 0.0 {
184184
differentialCorrection = IntegralRetrospectiveCorrection.differentialGain * differentialDiscrepancy
185+
} else {
186+
differentialCorrection = 0.0
185187
}
186188
let totalCorrection = proportionalCorrection + integralCorrection + differentialCorrection
187189
totalGlucoseCorrectionEffect = HKQuantity(unit: unit, doubleValue: totalCorrection)

0 commit comments

Comments
 (0)