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