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 b74eb0c405..82db7e043c 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.iobCalcForTreatment(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.iobCalcForTreatment(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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java index 74c41b78f6..c3f0ad6fc1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaR/services/DanaRExecutionService.java @@ -531,7 +531,9 @@ public class DanaRExecutionService 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; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java index fe86ad458d..6b65095524 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/PumpDanaRKorean/services/DanaRKoreanExecutionService.java @@ -506,7 +506,7 @@ public class DanaRKoreanExecutionService 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;