openloop mode fix

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

View file

@ -69,17 +69,17 @@ public class APSResult {
return this; return this;
} }
public APSResult tempBasalRequested(boolean tempBasalRequested) { public APSResult tempBasalRequested(boolean tempBasalRequested) {
this.tempBasalRequested = tempBasalRequested; this.tempBasalRequested = tempBasalRequested;
return this; return this;
} }
public APSResult usePercent(boolean usePercent) { public APSResult usePercent(boolean usePercent) {
this.usePercent = usePercent; this.usePercent = usePercent;
return this; return this;
} }
public APSResult json(JSONObject json) { public APSResult json(JSONObject json) {
this.json = json; this.json = json;
return this; return this;
} }
@ -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))
log.debug("TRUE: Inside allowed range " + (change * 100d) + "%");
return false;
} }
if (L.isEnabled(L.APS))
log.debug("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 /= 100d;
percentMinChangeChange /= 100; double lowThreshold = 1 - percentMinChangeChange;
double change = rate / activeTemp.tempBasalConvertedToAbsolute(now, profile); double highThreshold = 1 + percentMinChangeChange;
double lowThreshold = 1 - percentMinChangeChange; double change = rate / profile.getBasal();
double highThreshold = 1 + percentMinChangeChange; 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))
log.debug("TRUE: Inside allowed range " + (change * 100d) + "%");
return false;
} }
if (L.isEnabled(L.APS))
log.debug("FALSE");
return false;
} }
} }
} }