From 3869b143c419deed93e2e17639f3770abd74edb0 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 16 May 2017 16:29:30 +0200 Subject: [PATCH 1/3] Workaround for DanaR truncation --- .../plugins/PumpDanaR/Services/ExecutionService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java index ffd16fefdf..3916b25bf9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/Services/ExecutionService.java @@ -531,7 +531,9 @@ public class ExecutionService extends Service { private double[] buildDanaRProfileRecord(NSProfile nsProfile) { double[] record = new double[24]; for (Integer hour = 0; hour < 24; hour++) { - double value = nsProfile.getBasal(hour * 60 * 60); + //Some values get truncated to the next lower one. + // -> round them to two decimals and make sure we are a small delta larger (that will get truncated) + double value = Math.round(100d * nsProfile.getBasal(hour * 60 * 60))/100d + 0.00001; if (Config.logDanaMessageDetail) log.debug("NS basal value for " + hour + ":00 is " + value); record[hour] = value; From a362c77afe8244959f74cc76ac03bdb474b13e1f Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 16 May 2017 17:57:18 +0200 Subject: [PATCH 2/3] fix temp basal netRatio display --- .../nightscout/androidaps/db/TempBasal.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java index 5ef0767c59..d5a6c01235 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java +++ b/app/src/main/java/info/nightscout/androidaps/db/TempBasal.java @@ -68,11 +68,10 @@ public class TempBasal { if (realDuration > 0) { Double netBasalRate = 0d; + Double dia_ago = time - profile.getDia() * 60 * 60 * 1000; int aboutFiveMinIntervals = (int) Math.ceil(realDuration / 5d); - - result.netRatio = netBasalRate; - double tempBolusSpacing = realDuration / aboutFiveMinIntervals; + for (Long j = 0L; j < aboutFiveMinIntervals; j++) { // find middle of the interval Long date = (long) (timeStart.getTime() + j * tempBolusSpacing * 60 * 1000 + 0.5d * tempBolusSpacing * 60 * 1000); @@ -91,23 +90,23 @@ public class TempBasal { } } - double tempBolusSize = netBasalRate * tempBolusSpacing / 60d; - netBasalAmount += tempBolusSize; - - Treatment tempBolusPart = new Treatment(insulinInterface); - tempBolusPart.insulin = tempBolusSize; - tempBolusPart.created_at = new Date(date); - - Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia()); - result.basaliob += aIOB.iobContrib; - result.activity += aIOB.activityContrib; - Double dia_ago = time - profile.getDia() * 60 * 60 * 1000; if (date > dia_ago && date <= time) { + double tempBolusSize = netBasalRate * tempBolusSpacing / 60d; + netBasalAmount += tempBolusSize; + + Treatment tempBolusPart = new Treatment(insulinInterface); + tempBolusPart.insulin = tempBolusSize; + tempBolusPart.created_at = new Date(date); + + Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia()); + result.basaliob += aIOB.iobContrib; + result.activity += aIOB.activityContrib; result.netbasalinsulin += tempBolusPart.insulin; if (tempBolusPart.insulin > 0) { result.hightempinsulin += tempBolusPart.insulin; } } + result.netRatio = netBasalRate; // ratio at the end of interval } } result.netInsulin = netBasalAmount; From 8d2e7a34ae7aa89148702b95260acf712d7f72c1 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 16 May 2017 17:58:18 +0200 Subject: [PATCH 3/3] same workaround for korean danar --- .../plugins/PumpDanaRKorean/Services/ExecutionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/Services/ExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/Services/ExecutionService.java index 83cae228f0..fff5a84eb3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/Services/ExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/Services/ExecutionService.java @@ -507,7 +507,7 @@ public class ExecutionService extends Service { private double[] buildDanaRProfileRecord(NSProfile nsProfile) { double[] record = new double[24]; for (Integer hour = 0; hour < 24; hour++) { - double value = nsProfile.getBasal(hour * 60 * 60); + double value = Math.round(100d * nsProfile.getBasal(hour * 60 * 60))/100d + 0.00001; if (Config.logDanaMessageDetail) log.debug("NS basal value for " + hour + ":00 is " + value); record[hour] = value;