From 037bb09d2379147c59271e89be4b90fbdc6617fe Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 3 May 2017 18:15:10 +0200 Subject: [PATCH] check for null --- .../IobCobCalculatorPlugin.java | 20 +++++++++++++++---- .../NSClientInternal/data/NSProfile.java | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 725cd69a1e..d15435c1c1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -447,8 +447,20 @@ public class IobCobCalculatorPlugin implements PluginBase { Double[] deviations = new Double[deviationsArray.size()]; deviations = deviationsArray.toArray(deviations); + if (ConfigBuilderPlugin.getActiveProfile() == null || ConfigBuilderPlugin.getActiveProfile().getProfile() == null) { + log.debug("No profile available"); + return new AutosensResult(); + } + NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile(); + Double sens = profile.getIsf(NSProfile.secondsFromMidnight()); + + if (sens == null || profile.getMaxDailyBasal() == 0) { + log.debug("No profile available"); + return new AutosensResult(); + } + double ratio = 1; String ratioLimit = ""; String sensResult = ""; @@ -467,10 +479,10 @@ public class IobCobCalculatorPlugin implements PluginBase { double basalOff = 0; if (pSensitive < 0) { // sensitive - basalOff = pSensitive * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()); + basalOff = pSensitive * (60 / 5) / NSProfile.toMgdl(sens, profile.getUnits()); sensResult = "Excess insulin sensitivity detected"; } else if (pResistant > 0) { // resistant - basalOff = pResistant * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()); + basalOff = pResistant * (60 / 5) / NSProfile.toMgdl(sens, profile.getUnits()); sensResult = "Excess insulin resistance detected"; } else { sensResult = "Sensitivity normal"; @@ -487,9 +499,9 @@ public class IobCobCalculatorPlugin implements PluginBase { log.debug(ratioLimit); } - double newisf = Math.round(NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()) / ratio); + double newisf = Math.round(NSProfile.toMgdl(sens, profile.getUnits()) / ratio); if (ratio != 1) { - log.debug("ISF adjusted from " + NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()) + " to " + newisf); + log.debug("ISF adjusted from " + NSProfile.toMgdl(sens, profile.getUnits()) + " to " + newisf); } AutosensResult output = new AutosensResult(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java index 9aee30e899..eb320ebfdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/NSClientInternal/data/NSProfile.java @@ -238,7 +238,7 @@ public class NSProfile { e.printStackTrace(); } } - return 0D; + return null; } public String getIsfList() { @@ -429,7 +429,7 @@ public class NSProfile { } } - public Double getMaxDailyBasal() { + public double getMaxDailyBasal() { Double max = 0d; for (Integer hour = 0; hour < 24; hour++) { double value = getBasal(hour * 60 * 60);