diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java
index f886524dfb..62d2bc3a7d 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java
@@ -69,17 +69,17 @@ public class APSResult {
return this;
}
- public APSResult tempBasalRequested(boolean tempBasalRequested) {
+ public APSResult tempBasalRequested(boolean tempBasalRequested) {
this.tempBasalRequested = tempBasalRequested;
return this;
}
- public APSResult usePercent(boolean usePercent) {
+ public APSResult usePercent(boolean usePercent) {
this.usePercent = usePercent;
return this;
}
- public APSResult json(JSONObject json) {
+ public APSResult json(JSONObject json) {
this.json = json;
return this;
}
@@ -129,7 +129,7 @@ public class APSResult {
"" + MainApp.gs(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min
";
else
ret = "" + MainApp.gs(R.string.rate) + ": " + DecimalFormatter.to2Decimal(rate) + " U/h " +
- "(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100) + "%)
" +
+ "(" + DecimalFormatter.to2Decimal(rate / pump.getBaseBasalRate() * 100d) + "%)
" +
"" + MainApp.gs(R.string.duration) + ": " + DecimalFormatter.to2Decimal(duration) + " min
";
// 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) + "%");
- return true;
- }
+ if (change < lowThreshold || change > highThreshold) {
+ if (L.isEnabled(L.APS))
+ log.debug("TRUE: Outside allowed range " + (change * 100d) + "%");
+ 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 {
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);
- double lowThreshold = 1 - percentMinChangeChange;
- double highThreshold = 1 + percentMinChangeChange;
+ double percentMinChangeChange = SP.getDouble(R.string.key_loop_openmode_min_change, 30d);
+ 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) + "%");
- return true;
- }
+ if (change < lowThreshold || change > highThreshold) {
+ if (L.isEnabled(L.APS))
+ log.debug("TRUE: Outside allowed range " + (change * 100d) + "%");
+ 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;
}
}
}