openloop mode fix

This commit is contained in:
Milos Kozak 2018-09-11 22:32:04 +02:00
parent f7269a806d
commit 874be7ff48

View file

@ -129,7 +129,7 @@ public class APSResult {
"<b>" + MainApp.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
else
ret = "<b>" + MainApp.gs(R.string.rate) + "</b>: " + DecimalFormatter.to2Decimal(rate) + " U/h " +
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%) <br>" +
"(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100d) + "%) <br>" +
"<b>" + MainApp.gs(R.string.duration) + "</b>: " + DecimalFormatter.to2Decimal(duration) + " min<br>";
// smb
@ -334,22 +334,23 @@ public class APSResult {
}
}
// report change bigger than 30%
if (activeTemp != null) {
double percentToBeSmallChange = 30;
percentToBeSmallChange /= 100;
double change = percent / (double) activeTemp.tempBasalConvertedToPercent(now, profile);
double lowThreshold = 1 - percentToBeSmallChange;
double highThreshold = 1 + percentToBeSmallChange;
double percentMinChangeChange = SP.getDouble(R.string.key_loop_openmode_min_change, 30d);
percentMinChangeChange /= 100d;
double lowThreshold = 1 - percentMinChangeChange;
double highThreshold = 1 + percentMinChangeChange;
double change = percent / 100d;
if (activeTemp != null)
change = percent / (double) activeTemp.tempBasalConvertedToPercent(now, profile);
if (change < lowThreshold || change > highThreshold) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Outside allowed range " + (change * 100) + "%");
log.debug("TRUE: Outside allowed range " + (change * 100d) + "%");
return true;
}
}
} else {
if (L.isEnabled(L.APS))
log.debug("FALSE");
log.debug("TRUE: Inside allowed range " + (change * 100d) + "%");
return false;
}
} else {
if (activeTemp == null && rate == pump.getBaseBasalRate()) {
if (L.isEnabled(L.APS))
@ -377,22 +378,23 @@ public class APSResult {
}
}
// report change bigger than 30%
if (activeTemp != null) {
double percentMinChangeChange = SP.getDouble(R.string.key_loop_openmode_min_change, 30d);
percentMinChangeChange /= 100;
double change = rate / activeTemp.tempBasalConvertedToAbsolute(now, profile);
percentMinChangeChange /= 100d;
double lowThreshold = 1 - percentMinChangeChange;
double highThreshold = 1 + percentMinChangeChange;
double change = rate / profile.getBasal();
if (activeTemp != null)
change = rate / activeTemp.tempBasalConvertedToAbsolute(now, profile);
if (change < lowThreshold || change > highThreshold) {
if (L.isEnabled(L.APS))
log.debug("TRUE: Outside allowed range " + (change * 100) + "%");
log.debug("TRUE: Outside allowed range " + (change * 100d) + "%");
return true;
}
}
} else {
if (L.isEnabled(L.APS))
log.debug("FALSE");
log.debug("TRUE: Inside allowed range " + (change * 100d) + "%");
return false;
}
}
}
}