diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java b/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java index 6a47a892db..417f02199d 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/Constraint.java @@ -13,7 +13,7 @@ import info.nightscout.androidaps.logging.L; */ public class Constraint { - private static Logger log = LoggerFactory.getLogger(L.APS); + private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS); T value; T originalValue; @@ -37,10 +37,14 @@ public class Constraint { public Constraint set(T value) { this.value = value; this.originalValue = value; + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting value " + value); return this; } public Constraint set(T value, String reason, Object from) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]"); this.value = value; addReason(reason, from); addMostLimingReason(reason, from); @@ -49,6 +53,8 @@ public class Constraint { public Constraint setIfDifferent(T value, String reason, Object from) { if (!this.value.equals(value)) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]"); this.value = value; addReason(reason, from); addMostLimingReason(reason, from); @@ -58,6 +64,8 @@ public class Constraint { public Constraint setIfSmaller(T value, String reason, Object from) { if (value.compareTo(this.value) < 0) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]"); this.value = value; mostLimiting.clear(); addMostLimingReason(reason, from); @@ -70,6 +78,8 @@ public class Constraint { public Constraint setIfGreater(T value, String reason, Object from) { if (value.compareTo(this.value) > 0) { + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + translateFrom(from) + "]"); this.value = value; mostLimiting.clear(); addMostLimingReason(reason, from); @@ -80,13 +90,17 @@ public class Constraint { return this; } + private String translateFrom(Object from) { + return from.getClass().getSimpleName().replace("Plugin", ""); + } + public Constraint addReason(String reason, Object from) { - reasons.add(from.getClass().getSimpleName().replace("Plugin", "") + ": " + reason); + reasons.add(translateFrom(from) + ": " + reason); return this; } public Constraint addMostLimingReason(String reason, Object from) { - mostLimiting.add(from.getClass().getSimpleName().replace("Plugin", "") + ": " + reason); + mostLimiting.add(translateFrom(from) + ": " + reason); return this; } @@ -97,7 +111,7 @@ public class Constraint { if (count++ != 0) sb.append("\n"); sb.append(r); } - if (L.isEnabled(L.APS)) + if (L.isEnabled(L.CONSTRAINTS)) log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString()); return sb.toString(); } @@ -113,7 +127,8 @@ public class Constraint { if (count++ != 0) sb.append("\n"); sb.append(r); } - log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString()); + if (L.isEnabled(L.CONSTRAINTS)) + log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString()); return sb.toString(); } diff --git a/app/src/main/java/info/nightscout/androidaps/logging/L.java b/app/src/main/java/info/nightscout/androidaps/logging/L.java index 8b35eb8af6..c44d2516c2 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.java +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.java @@ -86,7 +86,7 @@ public class L { public static final String DATAFOOD = "DATAFOOD"; public static final String DATATREATMENTS = "DATATREATMENTS"; public static final String NSCLIENT = "NSCLIENT"; - public static final String OBJECTIVES = "OBJECTIVES"; + public static final String CONSTRAINTS = "CONSTRAINTS"; public static final String PUMP = "PUMP"; public static final String PUMPQUEUE = "PUMPQUEUE"; public static final String PUMPCOMM = "PUMPCOMM"; @@ -102,6 +102,7 @@ public class L { logElements.add(new LogElement(AUTOSENS, true)); logElements.add(new LogElement(BGSOURCE, true)); logElements.add(new LogElement(CONFIGBUILDER, true)); + logElements.add(new LogElement(CONSTRAINTS, true)); logElements.add(new LogElement(CORE, true)); logElements.add(new LogElement(DATABASE, true)); logElements.add(new LogElement(DATAFOOD, true)); @@ -110,7 +111,6 @@ public class L { logElements.add(new LogElement(EVENTS, false, true)); logElements.add(new LogElement(NOTIFICATION, true)); logElements.add(new LogElement(NSCLIENT, true)); - logElements.add(new LogElement(OBJECTIVES, false)); logElements.add(new LogElement(OVERVIEW, true)); logElements.add(new LogElement(PROFILE, true)); logElements.add(new LogElement(PUMP, true)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java index e675adee69..aae2d1f029 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConstraintsObjectives/ObjectivesPlugin.java @@ -33,7 +33,7 @@ import info.nightscout.utils.SP; * Created by mike on 05.08.2016. */ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface { - private static Logger log = LoggerFactory.getLogger(L.OBJECTIVES); + private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS); private static ObjectivesPlugin objectivesPlugin; @@ -95,7 +95,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS); SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS); SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts)); - if (L.isEnabled(L.OBJECTIVES)) + if (L.isEnabled(L.CONSTRAINTS)) log.debug("Objectives stored"); MainApp.bus().post(new EventObjectivesSaved()); } @@ -108,7 +108,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface } catch (Exception e) { log.error("Unhandled exception", e); } - if (L.isEnabled(L.OBJECTIVES)) + if (L.isEnabled(L.CONSTRAINTS)) log.debug("Objectives loaded"); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java b/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java index 06fde217f5..d7172cec97 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/ImportExportPrefs.java @@ -28,6 +28,7 @@ import java.util.Map; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.events.EventAppExit; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.utils.OKDialog; import info.nightscout.utils.ToastUtils; @@ -37,7 +38,7 @@ import info.nightscout.utils.ToastUtils; */ public class ImportExportPrefs { - private static Logger log = LoggerFactory.getLogger(ImportExportPrefs.class); + private static Logger log = LoggerFactory.getLogger(L.CORE); static File path = new File(Environment.getExternalStorageDirectory().toString()); static public final File file = new File(path, MainApp.gs(R.string.app_name) + "Preferences"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java b/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java index 3be97056c5..fc1cc0362a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/LoggerUtils.java @@ -4,13 +4,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.qos.logback.classic.LoggerContext; +import info.nightscout.androidaps.logging.L; /** * This class provides serveral methods for log-handling (eg. sending logs as emails). */ public class LoggerUtils { - private static final Logger LOGGER = LoggerFactory.getLogger(LoggerUtils.class); + private static final Logger LOGGER = LoggerFactory.getLogger(L.CORE); public static String SUFFIX = ".log.zip"; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java index 3fd3745f42..02b8349332 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Maintenance/MaintenancePlugin.java @@ -27,12 +27,13 @@ import info.nightscout.androidaps.R; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSettingsStatus; import info.nightscout.utils.SP; public class MaintenancePlugin extends PluginBase { - private static final Logger LOG = LoggerFactory.getLogger(MaintenancePlugin.class); + private static final Logger LOG = LoggerFactory.getLogger(L.CORE); private final Context ctx; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java index 7470710d8c..de110edd4e 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceNSClientPlugin.java @@ -99,7 +99,7 @@ public class SourceNSClientPlugin extends PluginBase implements BgSourceInterfac public void detectSource(String source, long timeStamp) { if (timeStamp > lastBGTimeStamp) { - if (source.contains("G5 Native") || source.contains("AndroidAPS-DexcomG5")) + if (source.contains("G5 Native") || source.contains("G6 Native") || source.contains("AndroidAPS-DexcomG5")) isAdvancedFilteringEnabled = true; else isAdvancedFilteringEnabled = false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java index b825cc3fb8..b99ad97685 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/fragments/TreatmentsBolusFragment.java @@ -145,6 +145,8 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View. @Override public void onClick(View v) { final Treatment treatment = (Treatment) v.getTag(); + if (treatment == null) + return; switch (v.getId()) { case R.id.treatments_remove: AlertDialog.Builder builder = new AlertDialog.Builder(context); diff --git a/app/src/main/java/info/nightscout/utils/BolusWizard.java b/app/src/main/java/info/nightscout/utils/BolusWizard.java index 3563a8a55d..7d7ff128af 100644 --- a/app/src/main/java/info/nightscout/utils/BolusWizard.java +++ b/app/src/main/java/info/nightscout/utils/BolusWizard.java @@ -1,10 +1,14 @@ package info.nightscout.utils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.TempTarget; import info.nightscout.androidaps.interfaces.TreatmentsInterface; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; @@ -13,35 +17,38 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; */ public class BolusWizard { + private Logger log = LoggerFactory.getLogger(L.CORE); // Inputs private Profile specificProfile = null; private TempTarget tempTarget; public Integer carbs = 0; private Double bg = 0d; + private Double cob = 0d; private Double correction; + private Double percentageCorrection; private Boolean includeBolusIOB = true; private Boolean includeBasalIOB = true; public Boolean superBolus = false; private Boolean trend = false; // Intermediate - public Double sens = 0d; - public Double ic = 0d; + public double sens = 0d; + public double ic = 0d; public GlucoseStatus glucoseStatus; - public Double targetBGLow = 0d; - public Double targetBGHigh = 0d; - public Double bgDiff = 0d; + public double targetBGLow = 0d; + public double targetBGHigh = 0d; + public double bgDiff = 0d; - public Double insulinFromBG = 0d; - public Double insulinFromCarbs = 0d; - public Double insulingFromBolusIOB = 0d; - public Double insulingFromBasalsIOB = 0d; - public Double insulinFromCorrection = 0d; - public Double insulinFromSuperBolus = 0d; - public Double insulinFromCOB = 0d; - public Double insulinFromTrend = 0d; + public double insulinFromBG = 0d; + public double insulinFromCarbs = 0d; + public double insulingFromBolusIOB = 0d; + public double insulingFromBasalsIOB = 0d; + public double insulinFromCorrection = 0d; + public double insulinFromSuperBolus = 0d; + public double insulinFromCOB = 0d; + public double insulinFromTrend = 0d; // Result public Double calculatedTotalInsulin = 0d; @@ -57,7 +64,9 @@ public class BolusWizard { this.tempTarget = tempTarget; this.carbs = carbs; this.bg = bg; + this.cob = cob; this.correction = correction; + this.percentageCorrection = percentageCorrection; this.includeBolusIOB = includeBolusIOB; this.includeBasalIOB = includeBasalIOB; this.superBolus = superBolus; @@ -109,7 +118,7 @@ public class BolusWizard { if (superBolus) { insulinFromSuperBolus = specificProfile.getBasal(); long timeAfter1h = System.currentTimeMillis(); - timeAfter1h += 60L * 60 * 1000; + timeAfter1h += T.hours(1).msecs(); insulinFromSuperBolus += specificProfile.getBasal(timeAfter1h); } @@ -130,6 +139,45 @@ public class BolusWizard { double bolusStep = ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep; calculatedTotalInsulin = Round.roundTo(calculatedTotalInsulin, bolusStep); + log.debug(log()); + 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(); + } } diff --git a/app/src/main/res/xml/pref_loop.xml b/app/src/main/res/xml/pref_loop.xml index 5f22ce439a..16c5c94375 100644 --- a/app/src/main/res/xml/pref_loop.xml +++ b/app/src/main/res/xml/pref_loop.xml @@ -14,7 +14,7 @@ android:entryValues="@array/aps_modeValues"/>