better wizard and constraint logging
This commit is contained in:
parent
0563420996
commit
37c384e1c9
2 changed files with 66 additions and 18 deletions
|
@ -44,7 +44,7 @@ public class Constraint<T extends Comparable> {
|
||||||
|
|
||||||
public Constraint<T> set(T value, String reason, Object from) {
|
public Constraint<T> set(T value, String reason, Object from) {
|
||||||
if (L.isEnabled(L.CONSTRAINTS))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Setting value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
log.debug("Setting value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
addReason(reason, from);
|
addReason(reason, from);
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -54,7 +54,7 @@ public class Constraint<T extends Comparable> {
|
||||||
public Constraint<T> setIfDifferent(T value, String reason, Object from) {
|
public Constraint<T> setIfDifferent(T value, String reason, Object from) {
|
||||||
if (!this.value.equals(value)) {
|
if (!this.value.equals(value)) {
|
||||||
if (L.isEnabled(L.CONSTRAINTS))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
log.debug("Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
addReason(reason, from);
|
addReason(reason, from);
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -65,7 +65,7 @@ public class Constraint<T extends Comparable> {
|
||||||
public Constraint<T> setIfSmaller(T value, String reason, Object from) {
|
public Constraint<T> setIfSmaller(T value, String reason, Object from) {
|
||||||
if (value.compareTo(this.value) < 0) {
|
if (value.compareTo(this.value) < 0) {
|
||||||
if (L.isEnabled(L.CONSTRAINTS))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
log.debug("Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
mostLimiting.clear();
|
mostLimiting.clear();
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -79,7 +79,7 @@ public class Constraint<T extends Comparable> {
|
||||||
public Constraint<T> setIfGreater(T value, String reason, Object from) {
|
public Constraint<T> setIfGreater(T value, String reason, Object from) {
|
||||||
if (value.compareTo(this.value) > 0) {
|
if (value.compareTo(this.value) > 0) {
|
||||||
if (L.isEnabled(L.CONSTRAINTS))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
log.debug("Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
mostLimiting.clear();
|
mostLimiting.clear();
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package info.nightscout.utils;
|
package info.nightscout.utils;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
|
|
||||||
|
@ -13,35 +17,38 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class BolusWizard {
|
public class BolusWizard {
|
||||||
|
private Logger log = LoggerFactory.getLogger(L.CORE);
|
||||||
// Inputs
|
// Inputs
|
||||||
private Profile specificProfile = null;
|
private Profile specificProfile = null;
|
||||||
private TempTarget tempTarget;
|
private TempTarget tempTarget;
|
||||||
public Integer carbs = 0;
|
public Integer carbs = 0;
|
||||||
private Double bg = 0d;
|
private Double bg = 0d;
|
||||||
|
private Double cob = 0d;
|
||||||
private Double correction;
|
private Double correction;
|
||||||
|
private Double percentageCorrection;
|
||||||
private Boolean includeBolusIOB = true;
|
private Boolean includeBolusIOB = true;
|
||||||
private Boolean includeBasalIOB = true;
|
private Boolean includeBasalIOB = true;
|
||||||
public Boolean superBolus = false;
|
public Boolean superBolus = false;
|
||||||
private Boolean trend = false;
|
private Boolean trend = false;
|
||||||
|
|
||||||
// Intermediate
|
// Intermediate
|
||||||
public Double sens = 0d;
|
public double sens = 0d;
|
||||||
public Double ic = 0d;
|
public double ic = 0d;
|
||||||
|
|
||||||
public GlucoseStatus glucoseStatus;
|
public GlucoseStatus glucoseStatus;
|
||||||
|
|
||||||
public Double targetBGLow = 0d;
|
public double targetBGLow = 0d;
|
||||||
public Double targetBGHigh = 0d;
|
public double targetBGHigh = 0d;
|
||||||
public Double bgDiff = 0d;
|
public double bgDiff = 0d;
|
||||||
|
|
||||||
public Double insulinFromBG = 0d;
|
public double insulinFromBG = 0d;
|
||||||
public Double insulinFromCarbs = 0d;
|
public double insulinFromCarbs = 0d;
|
||||||
public Double insulingFromBolusIOB = 0d;
|
public double insulingFromBolusIOB = 0d;
|
||||||
public Double insulingFromBasalsIOB = 0d;
|
public double insulingFromBasalsIOB = 0d;
|
||||||
public Double insulinFromCorrection = 0d;
|
public double insulinFromCorrection = 0d;
|
||||||
public Double insulinFromSuperBolus = 0d;
|
public double insulinFromSuperBolus = 0d;
|
||||||
public Double insulinFromCOB = 0d;
|
public double insulinFromCOB = 0d;
|
||||||
public Double insulinFromTrend = 0d;
|
public double insulinFromTrend = 0d;
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
public Double calculatedTotalInsulin = 0d;
|
public Double calculatedTotalInsulin = 0d;
|
||||||
|
@ -57,7 +64,9 @@ public class BolusWizard {
|
||||||
this.tempTarget = tempTarget;
|
this.tempTarget = tempTarget;
|
||||||
this.carbs = carbs;
|
this.carbs = carbs;
|
||||||
this.bg = bg;
|
this.bg = bg;
|
||||||
|
this.cob = cob;
|
||||||
this.correction = correction;
|
this.correction = correction;
|
||||||
|
this.percentageCorrection = percentageCorrection;
|
||||||
this.includeBolusIOB = includeBolusIOB;
|
this.includeBolusIOB = includeBolusIOB;
|
||||||
this.includeBasalIOB = includeBasalIOB;
|
this.includeBasalIOB = includeBasalIOB;
|
||||||
this.superBolus = superBolus;
|
this.superBolus = superBolus;
|
||||||
|
@ -109,7 +118,7 @@ public class BolusWizard {
|
||||||
if (superBolus) {
|
if (superBolus) {
|
||||||
insulinFromSuperBolus = specificProfile.getBasal();
|
insulinFromSuperBolus = specificProfile.getBasal();
|
||||||
long timeAfter1h = System.currentTimeMillis();
|
long timeAfter1h = System.currentTimeMillis();
|
||||||
timeAfter1h += 60L * 60 * 1000;
|
timeAfter1h += T.hours(1).msecs();
|
||||||
insulinFromSuperBolus += specificProfile.getBasal(timeAfter1h);
|
insulinFromSuperBolus += specificProfile.getBasal(timeAfter1h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,6 +139,45 @@ public class BolusWizard {
|
||||||
double bolusStep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep;
|
double bolusStep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep;
|
||||||
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep);
|
calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep);
|
||||||
|
|
||||||
|
log.debug(log());
|
||||||
|
|
||||||
return calculatedTotalInsulin;
|
return calculatedTotalInsulin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String log() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
sb.append("TempTarget=").append(tempTarget != null ? tempTarget.toString() : "null").append("; ");
|
||||||
|
sb.append("Carbs=").append(carbs != null ? carbs : null).append("; ");
|
||||||
|
sb.append("Bg=").append(bg).append("; ");
|
||||||
|
sb.append("Cob=").append(cob).append("; ");
|
||||||
|
sb.append("Correction=").append(correction).append("; ");
|
||||||
|
sb.append("PercentageCorrection=").append(percentageCorrection).append("; ");
|
||||||
|
sb.append("IncludeBolusIOB=").append(includeBolusIOB).append("; ");
|
||||||
|
sb.append("IncludeBasalIOB=").append(includeBasalIOB).append("; ");
|
||||||
|
sb.append("Superbolus=").append(superBolus).append("; ");
|
||||||
|
sb.append("Trend=").append(trend).append("; ");
|
||||||
|
sb.append("Profile=").append(specificProfile != null ? specificProfile.getData().toString() : "null").append("; ");
|
||||||
|
sb.append("\n");
|
||||||
|
|
||||||
|
sb.append("targetBGLow=").append(targetBGLow).append("; ");
|
||||||
|
sb.append("targetBGHigh=").append(targetBGHigh).append("; ");
|
||||||
|
sb.append("bgDiff=").append(bgDiff).append("; ");
|
||||||
|
sb.append("insulinFromBG=").append(insulinFromBG).append("; ");
|
||||||
|
sb.append("insulinFromCarbs=").append(insulinFromCarbs).append("; ");
|
||||||
|
sb.append("insulingFromBolusIOB=").append(insulingFromBolusIOB).append("; ");
|
||||||
|
sb.append("insulingFromBasalsIOB=").append(insulingFromBasalsIOB).append("; ");
|
||||||
|
sb.append("insulinFromCorrection=").append(insulinFromCorrection).append("; ");
|
||||||
|
sb.append("insulinFromSuperBolus=").append(insulinFromSuperBolus).append("; ");
|
||||||
|
sb.append("insulinFromCOB=").append(insulinFromCOB).append("; ");
|
||||||
|
sb.append("insulinFromTrend=").append(insulinFromTrend).append("; ");
|
||||||
|
sb.append("\n");
|
||||||
|
|
||||||
|
|
||||||
|
sb.append("calculatedTotalInsulin=").append(calculatedTotalInsulin).append("; ");
|
||||||
|
sb.append("totalBeforePercentageAdjustment=").append(totalBeforePercentageAdjustment).append("; ");
|
||||||
|
sb.append("carbsEquivalent=").append(carbsEquivalent).append("; ");
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue