From e134b94f13fba7ccc576a472849b0aa71503f26b Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Mon, 12 Mar 2018 21:13:48 +0100 Subject: [PATCH] fix deviation slope calculations --- app/src/main/java/info/nightscout/androidaps/Config.java | 2 +- .../androidaps/plugins/IobCobCalculator/IobCobThread.java | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Config.java b/app/src/main/java/info/nightscout/androidaps/Config.java index 00c314787b..6775b8dac6 100644 --- a/app/src/main/java/info/nightscout/androidaps/Config.java +++ b/app/src/main/java/info/nightscout/androidaps/Config.java @@ -24,7 +24,7 @@ public class Config { public static final boolean SMSCOMMUNICATORENABLED = !BuildConfig.NSCLIENTOLNY && !BuildConfig.G5UPLOADER; - public static final boolean displayDeviationSlope = false; + public static final boolean displayDeviationSlope = true; public static final boolean detailedLog = true; public static final boolean logFunctionCalls = true; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index ba0475a26f..e2e97715f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -145,7 +145,6 @@ public class IobCobThread extends Thread { double deviation = delta - bgi; double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000; - double currentDeviation; double slopeFromMaxDeviation = 0; double slopeFromMinDeviation = 999; double maxDeviation = 0; @@ -156,19 +155,18 @@ public class IobCobThread extends Thread { long hourago = bgTime + 10 * 1000 - 60 * 60 * 1000L; AutosensData hourAgoData = iobCobCalculatorPlugin.getAutosensData(hourago); if (hourAgoData != null) { - currentDeviation = hourAgoData.avgDeviation; int initialIndex = autosensDataTable.indexOfKey(hourAgoData.time); for (int past = 1; past < 12; past++) { AutosensData ad = autosensDataTable.valueAt(initialIndex + past); - double deviationSlope = (ad.avgDeviation - currentDeviation) / (ad.time - bgTime) * 1000 * 60 * 5; + double deviationSlope = (ad.avgDeviation - avgDeviation) / (ad.time - bgTime) * 1000 * 60 * 5; if (ad.avgDeviation > maxDeviation) { slopeFromMaxDeviation = Math.min(0, deviationSlope); maxDeviation = ad.avgDeviation; } - if (avgDeviation < minDeviation) { + if (ad.avgDeviation < minDeviation) { slopeFromMinDeviation = Math.max(0, deviationSlope); - minDeviation = avgDeviation; + minDeviation = ad.avgDeviation; } //if (Config.logAutosensData)