From e577e8555da8b19f40b564932aa4b9d86f0881ce Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 9 Sep 2018 12:15:44 +0200 Subject: [PATCH] openloop mode min change threshold configurable --- .../androidaps/plugins/Loop/APSResult.java | 9 +++--- .../androidaps/plugins/Loop/LoopPlugin.java | 3 +- app/src/main/res/values/strings.xml | 3 ++ app/src/main/res/xml/pref_closedmode.xml | 14 --------- app/src/main/res/xml/pref_loop.xml | 31 +++++++++++++++++++ .../plugins/Loop/LoopPluginTest.java | 2 +- 6 files changed, 41 insertions(+), 21 deletions(-) delete mode 100644 app/src/main/res/xml/pref_closedmode.xml create mode 100644 app/src/main/res/xml/pref_loop.xml diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java index cd7c0b9a0e..f886524dfb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/APSResult.java @@ -26,6 +26,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DecimalFormatter; +import info.nightscout.utils.SP; /** * Created by mike on 09.06.2016. @@ -377,11 +378,11 @@ public class APSResult { } // report change bigger than 30% if (activeTemp != null) { - double percentToBeSmallChange = 30; - percentToBeSmallChange /= 100; + double percentMinChangeChange = SP.getDouble(R.string.key_loop_openmode_min_change, 30d); + percentMinChangeChange /= 100; double change = rate / activeTemp.tempBasalConvertedToAbsolute(now, profile); - double lowThreshold = 1 - percentToBeSmallChange; - double highThreshold = 1 + percentToBeSmallChange; + double lowThreshold = 1 - percentMinChangeChange; + double highThreshold = 1 + percentMinChangeChange; if (change < lowThreshold || change > highThreshold) { if (L.isEnabled(L.APS)) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java index 832e095e81..6081845d32 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Loop/LoopPlugin.java @@ -33,7 +33,6 @@ import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.Source; import info.nightscout.androidaps.db.TemporaryBasal; -import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.events.EventNewBG; import info.nightscout.androidaps.interfaces.APSInterface; import info.nightscout.androidaps.interfaces.Constraint; @@ -106,7 +105,7 @@ public class LoopPlugin extends PluginBase { .fragmentClass(LoopFragment.class.getName()) .pluginName(R.string.loop) .shortName(R.string.loop_shortname) - .preferencesId(R.xml.pref_closedmode) + .preferencesId(R.xml.pref_loop) .description(R.string.description_loop) ); loopSuspendedTill = SP.getLong("loopSuspendedTill", 0L); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1330771548..0354ca5e12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1200,6 +1200,9 @@ Command error Speed error Insulin limit violation + loop_openmode_min_change + Minimal request change [%] + Loop will popup new change request only if change is bigger than this value. Default value is 30% %1$d day diff --git a/app/src/main/res/xml/pref_closedmode.xml b/app/src/main/res/xml/pref_closedmode.xml deleted file mode 100644 index 7d33941885..0000000000 --- a/app/src/main/res/xml/pref_closedmode.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/xml/pref_loop.xml b/app/src/main/res/xml/pref_loop.xml new file mode 100644 index 0000000000..5f22ce439a --- /dev/null +++ b/app/src/main/res/xml/pref_loop.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java index 4a457651ce..0a37ba5df5 100644 --- a/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/Loop/LoopPluginTest.java @@ -41,7 +41,7 @@ public class LoopPluginTest { Assert.assertEquals("LOOP", loopPlugin.getNameShort()); Assert.assertEquals(true, loopPlugin.hasFragment()); Assert.assertEquals(true, loopPlugin.showInList(PluginType.LOOP)); - Assert.assertEquals(R.xml.pref_closedmode, loopPlugin.getPreferencesId()); + Assert.assertEquals(R.xml.pref_loop, loopPlugin.getPreferencesId()); // Plugin is disabled by default Assert.assertEquals(false, loopPlugin.isEnabled(PluginType.LOOP));