From 3e9734188b548fa447cf6ae8e87805f7e9210823 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 11 Jul 2017 11:27:14 +0200 Subject: [PATCH] check for array size --- .../SensitivityWeightedAveragePlugin.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java index 708254ff44..b957e21bda 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java @@ -26,7 +26,7 @@ import info.nightscout.utils.SafeParse; * Created by mike on 24.06.2017. */ -public class SensitivityWeightedAveragePlugin implements PluginBase, SensitivityInterface{ +public class SensitivityWeightedAveragePlugin implements PluginBase, SensitivityInterface { private static Logger log = LoggerFactory.getLogger(SensitivityWeightedAveragePlugin.class); private static boolean fragmentEnabled = true; @@ -156,11 +156,15 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity index++; } + if (data.size() == 0) { + return new AutosensResult(); + } + double weightedsum = 0; double weights = 0; long hightestWeight = data.keyAt(data.size() - 1); - for (int i = 0 ; i < data.size(); i++) { + for (int i = 0; i < data.size(); i++) { long reversedWeigth = data.keyAt(i); double value = data.valueAt(i); double weight = (hightestWeight - reversedWeigth) / 2; @@ -177,7 +181,7 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity log.debug("Records: " + index + " " + pastSensitivity); - double average = weightedsum /weights; + double average = weightedsum / weights; double basalOff = average * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); double ratio = 1 + (basalOff / profile.getMaxDailyBasal());