From 064a8915a0612ffce3be8c88634a82a6a2d12539 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Sat, 23 Jun 2018 14:05:12 +0200 Subject: [PATCH] downweight Autosens if not enough data --- .../interfaces/SensitivityInterface.java | 3 +++ .../Sensitivity/SensitivityAAPSPlugin.java | 12 +++++++++++- .../Sensitivity/SensitivityOref0Plugin.java | 12 +++++++++++- .../Sensitivity/SensitivityOref1Plugin.java | 12 +++++++++++- .../SensitivityWeightedAveragePlugin.java | 15 ++++++++++++--- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java index deb649c21f..44c6be9aa4 100644 --- a/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java +++ b/app/src/main/java/info/nightscout/androidaps/interfaces/SensitivityInterface.java @@ -7,5 +7,8 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult; */ public interface SensitivityInterface { + double MIN_HOURS = 1; + double MIN_HOURS_FULL_AUTOSENS = 4; + AutosensResult detectSensitivity(long fromTime, long toTime); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java index 990bafa6b9..cc239a4ec4 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityAAPSPlugin.java @@ -158,8 +158,18 @@ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInte ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7"))); ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2"))); + //If not-excluded data <= MIN_HOURS -> don't do Autosens + //If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens + //Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens + double autosensContrib = (Math.min(Math.max(MIN_HOURS, deviationsArray.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS); + ratio = autosensContrib * (ratio - 1) + 1; + + if (autosensContrib != 1d) { + ratioLimit += "(" + deviationsArray.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) "; + } + if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio; log.debug(ratioLimit); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java index 8910dfedb3..aa9330c4fd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref0Plugin.java @@ -170,8 +170,18 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7"))); ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2"))); + //If not-excluded data <= MIN_HOURS -> don't do Autosens + //If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens + //Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens + double autosensContrib = (Math.min(Math.max(MIN_HOURS, deviationsArray.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS); + ratio = autosensContrib * (ratio - 1) + 1; + + if (autosensContrib != 1d) { + ratioLimit += "(" + deviationsArray.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) "; + } + if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio; log.debug(ratioLimit); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java index 5c88b02c5e..13dd9837f9 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityOref1Plugin.java @@ -179,8 +179,18 @@ public class SensitivityOref1Plugin extends PluginBase implements SensitivityInt ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7"))); ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2"))); + //If not-excluded data <= MIN_HOURS -> don't do Autosens + //If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens + //Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens + double autosensContrib = (Math.min(Math.max(MIN_HOURS, deviationsArray.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS); + ratio = autosensContrib * (ratio - 1) + 1; + + if (autosensContrib != 1d) { + ratioLimit += "(" + deviationsArray.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) "; + } + if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; + ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio; log.debug(ratioLimit); } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java index 6ac86fbc5a..3e8fd4a6e1 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Sensitivity/SensitivityWeightedAveragePlugin.java @@ -180,10 +180,19 @@ public class SensitivityWeightedAveragePlugin extends PluginBase implements Sens ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7"))); ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2"))); + //If not-excluded data <= MIN_HOURS -> don't do Autosens + //If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens + //Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens + double autosensContrib = (Math.min(Math.max(MIN_HOURS, data.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS); + ratio = autosensContrib * (ratio - 1) + 1; + + if (autosensContrib != 1d) { + ratioLimit += "(" + data.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) "; + } + if (ratio != rawRatio) { - ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio; - if (Config.logAutosensData) - log.debug(ratioLimit); + ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio; + log.debug(ratioLimit); } if (Config.logAutosensData)