Merge branch 'dev' into insightfix

This commit is contained in:
Milos Kozak 2018-09-11 19:06:35 +02:00
commit 98b8d67e3b
10 changed files with 99 additions and 31 deletions

View file

@ -13,7 +13,7 @@ import info.nightscout.androidaps.logging.L;
*/
public class Constraint<T extends Comparable> {
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<T extends Comparable> {
public Constraint<T> set(T value) {
this.value = value;
this.originalValue = value;
if (L.isEnabled(L.CONSTRAINTS))
log.debug("Setting value " + value);
return this;
}
public Constraint<T> 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<T extends Comparable> {
public Constraint<T> 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<T extends Comparable> {
public Constraint<T> 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<T extends Comparable> {
public Constraint<T> 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<T extends Comparable> {
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<T extends Comparable> {
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<T extends Comparable> {
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();
}

View file

@ -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));

View file

@ -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");
}

View file

@ -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");

View file

@ -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";

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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();
}
}

View file

@ -14,7 +14,7 @@
android:entryValues="@array/aps_modeValues"/>
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="30"
android:defaultValue="20"
android:dialogMessage="@string/loop_openmode_min_change_summary"
android:digits="0123456789"
android:inputType="number"
@ -23,8 +23,8 @@
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/loop_openmode_min_change"
validate:maxNumber="80"
validate:minNumber="10"
validate:maxNumber="50"
validate:minNumber="0"
validate:testType="numericRange" />
</PreferenceCategory>