is5minData detection improvement

This commit is contained in:
Milos Kozak 2018-08-25 18:13:32 +02:00
parent 324ba072bb
commit 8c4c5a291e
2 changed files with 30 additions and 6 deletions

View file

@ -135,18 +135,21 @@ public class IobCobCalculatorPlugin extends PluginBase {
long bgTime = bgReadings.get(i).date;
long lastbgTime = bgReadings.get(i - 1).date;
long diff = lastbgTime - bgTime;
diff %= T.mins(5).msecs();
if (diff > T.mins(2).plus(T.secs(30)).msecs())
diff = diff - T.mins(5).msecs();
totalDiff += diff;
if (diff > T.secs(30).msecs() && diff < T.secs(270).msecs()) { // 0:30 - 4:30
diff = Math.abs(diff);
if (diff > T.secs(30).msecs()) {
if (L.isEnabled(L.AUTOSENS))
log.debug("Interval detection: values: " + bgReadings.size() + " diff: " + (diff / 1000) + "sec is5minData: " + false);
log.debug("Interval detection: values: " + bgReadings.size() + " diff: " + (diff / 1000) + "[s] is5minData: " + false);
return false;
}
}
double intervals = totalDiff / (5 * 60 * 1000d);
double variability = Math.abs(intervals - Math.round(intervals));
boolean is5mindata = variability < 0.02;
double averageDiff = totalDiff / (bgReadings.size() -1) / 1000d;
boolean is5mindata = averageDiff < 10;
if (L.isEnabled(L.AUTOSENS))
log.debug("Interval detection: values: " + bgReadings.size() + " variability: " + variability + " is5minData: " + is5mindata);
log.debug("Interval detection: values: " + bgReadings.size() + " averageDiff: " + averageDiff + "[s] is5minData: " + is5mindata);
return is5mindata;
}
}

View file

@ -63,6 +63,27 @@ public class IobCobCalculatorPluginTest {
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
// too much shifted and missing data should return false
bgReadingList.clear();
bgReadingList.add(new BgReading().date(T.mins(83).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(78).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(73).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(68).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(63).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(58).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(53).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(48).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(43).plus(T.secs(40)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(38).plus(T.secs(33)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(33).plus(T.secs(1)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(28).plus(T.secs(0)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(23).plus(T.secs(0)).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(16).plus(T.secs(36)).msecs()).value(100));
iobCobCalculatorPlugin.setBgReadings(bgReadingList);
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData());
// slighly shifted data should return true
bgReadingList.clear();
bgReadingList.add(new BgReading().date(T.mins(20).msecs()).value(100));