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