check for null

This commit is contained in:
Milos Kozak 2017-05-03 18:15:10 +02:00
parent b80c382512
commit 037bb09d23
2 changed files with 18 additions and 6 deletions

View file

@ -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();

View file

@ -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);