diff --git a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java index d7895e518a..be3e981fb4 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java @@ -8,9 +8,8 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DecimalFormatter; @@ -30,12 +29,11 @@ public class GlucoseStatus { public long date = 0L; - @Override - public String toString() { - return MainApp.gs(R.string.glucose) + " " + DecimalFormatter.to0Decimal(glucose) + " mg/dl\n" + - MainApp.gs(R.string.delta) + " " + DecimalFormatter.to0Decimal(delta) + " mg/dl\n" + - MainApp.gs(R.string.short_avgdelta) + " " + DecimalFormatter.to2Decimal(short_avgdelta) + " mg/dl\n" + - MainApp.gs(R.string.long_avgdelta) + " " + DecimalFormatter.to2Decimal(long_avgdelta) + " mg/dl"; + public String log() { + return "Glucose: " + DecimalFormatter.to0Decimal(glucose) + " mg/dl " + + "Delta: " + DecimalFormatter.to0Decimal(delta) + " mg/dl" + + "Short avg. delta: " + " " + DecimalFormatter.to2Decimal(short_avgdelta) + " mg/dl " + + "Long avg. delta: " + DecimalFormatter.to2Decimal(long_avgdelta) + " mg/dl"; } public GlucoseStatus() { @@ -64,15 +62,22 @@ public class GlucoseStatus { List data = IobCobCalculatorPlugin.getPlugin().getBgReadings(); - if (data == null) + if (data == null) { + if (L.isEnabled(L.GLUCOSE)) + log.debug("data=null"); return null; + } int sizeRecords = data.size(); if (sizeRecords == 0) { + if (L.isEnabled(L.GLUCOSE)) + log.debug("sizeRecords==0"); return null; } if (data.get(0).date < DateUtil.now() - 7 * 60 * 1000L && !allowOldData) { + if (L.isEnabled(L.GLUCOSE)) + log.debug("olddata"); return null; } @@ -88,13 +93,15 @@ public class GlucoseStatus { status.long_avgdelta = 0d; status.avgdelta = 0d; // for OpenAPS MA status.date = now_date; + if (L.isEnabled(L.GLUCOSE)) + log.debug("sizeRecords==1"); return status.round(); } - ArrayList now_value_list = new ArrayList(); - ArrayList last_deltas = new ArrayList(); - ArrayList short_deltas = new ArrayList(); - ArrayList long_deltas = new ArrayList(); + ArrayList now_value_list = new ArrayList<>(); + ArrayList last_deltas = new ArrayList<>(); + ArrayList short_deltas = new ArrayList<>(); + ArrayList long_deltas = new ArrayList<>(); // Use the latest sgv value in the now calculations now_value_list.add(now.value); @@ -103,7 +110,7 @@ public class GlucoseStatus { if (data.get(i).value > 38) { BgReading then = data.get(i); long then_date = then.date; - double avgdelta = 0; + double avgdelta; long minutesago; minutesago = Math.round((now_date - then_date) / (1000d * 60)); @@ -111,6 +118,9 @@ public class GlucoseStatus { change = now.value - then.value; avgdelta = change / minutesago * 5; + if (L.isEnabled(L.GLUCOSE)) + log.debug(then.toString() + " minutesago=" + minutesago + " avgdelta=" + avgdelta); + // use the average of all data points in the last 2.5m for all further "now" calculations if (0 < minutesago && minutesago < 2.5) { // Keep and average all values within the last 2.5 minutes @@ -149,6 +159,8 @@ public class GlucoseStatus { status.long_avgdelta = average(long_deltas); status.avgdelta = status.short_avgdelta; // for OpenAPS MA + if (L.isEnabled(L.GLUCOSE)) + log.debug(status.log()); return status.round(); } 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 583969c739..f685bbd424 100644 --- a/app/src/main/java/info/nightscout/androidaps/logging/L.java +++ b/app/src/main/java/info/nightscout/androidaps/logging/L.java @@ -78,6 +78,7 @@ public class L { public static final String CORE = "CORE"; public static final String AUTOSENS = "AUTOSENS"; public static final String EVENTS = "EVENTS"; + public static final String GLUCOSE = "GLUCOSE"; public static final String BGSOURCE = "BGSOURCE"; public static final String OVERVIEW = "OVERVIEW"; public static final String NOTIFICATION = "NOTIFICATION"; @@ -102,6 +103,7 @@ public class L { logElements.add(new LogElement(APS, true)); logElements.add(new LogElement(AUTOSENS, false)); logElements.add(new LogElement(BGSOURCE, true)); + logElements.add(new LogElement(GLUCOSE, false)); logElements.add(new LogElement(CONFIGBUILDER, false)); logElements.add(new LogElement(CONSTRAINTS, true)); logElements.add(new LogElement(CORE, true)); diff --git a/app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java b/app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java index b7a1d8b0b2..8bcdf0ed26 100644 --- a/app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java +++ b/app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java @@ -36,7 +36,7 @@ public class GlucoseStatusTest { @Test public void toStringShouldBeOverloaded() { GlucoseStatus glucoseStatus = new GlucoseStatus(); - Assert.assertEquals(true, glucoseStatus.toString().contains("Delta")); + Assert.assertEquals(true, glucoseStatus.log().contains("Delta")); } @Test