fix bucketed data

This commit is contained in:
Milos Kozak 2018-08-25 20:03:48 +02:00
parent a9262d8374
commit e5d96e5c17
2 changed files with 3 additions and 2 deletions

View file

@ -284,7 +284,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
} }
// Normalize bucketed data // Normalize bucketed data
for (int i = bucketed_data.size() - 2; i > 0; i--) { for (int i = bucketed_data.size() - 2; i >= 0; i--) {
BgReading current = bucketed_data.get(i); BgReading current = bucketed_data.get(i);
BgReading previous = bucketed_data.get(i + 1); BgReading previous = bucketed_data.get(i + 1);
long msecDiff = current.date - previous.date; long msecDiff = current.date - previous.date;

View file

@ -146,11 +146,12 @@ public class IobCobCalculatorPluginTest {
bgReadingList.add(new BgReading().date(T.mins(15).msecs() + T.secs(10).msecs()).value(100)); bgReadingList.add(new BgReading().date(T.mins(15).msecs() + T.secs(10).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(10).msecs() + T.secs(10).msecs()).value(100)); bgReadingList.add(new BgReading().date(T.mins(10).msecs() + T.secs(10).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(5).msecs() - T.secs(10).msecs()).value(100)); bgReadingList.add(new BgReading().date(T.mins(5).msecs() - T.secs(10).msecs()).value(100));
bgReadingList.add(new BgReading().date(T.mins(0).msecs()).value(100));
iobCobCalculatorPlugin.setBgReadings(bgReadingList); iobCobCalculatorPlugin.setBgReadings(bgReadingList);
iobCobCalculatorPlugin.createBucketedData(); iobCobCalculatorPlugin.createBucketedData();
Assert.assertEquals(false, iobCobCalculatorPlugin.isAbout5minData()); // too much drift Assert.assertEquals(true, iobCobCalculatorPlugin.isAbout5minData());
Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.getBucketedData().get(0).date); Assert.assertEquals(T.mins(20).msecs(), iobCobCalculatorPlugin.getBucketedData().get(0).date);
Assert.assertEquals(T.mins(15).msecs(), iobCobCalculatorPlugin.getBucketedData().get(1).date); Assert.assertEquals(T.mins(15).msecs(), iobCobCalculatorPlugin.getBucketedData().get(1).date);
Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.getBucketedData().get(2).date); Assert.assertEquals(T.mins(10).msecs(), iobCobCalculatorPlugin.getBucketedData().get(2).date);