openloop mode min change threshold configurable

This commit is contained in:
Milos Kozak 2018-09-09 12:15:44 +02:00
parent a83ffb60dd
commit e577e8555d
6 changed files with 41 additions and 21 deletions

View file

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

View file

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

View file

@ -1200,6 +1200,9 @@
<string name="commanderror">Command error</string>
<string name="speederror">Speed error</string>
<string name="insulinlimitviolation">Insulin limit violation</string>
<string name="key_loop_openmode_min_change" translatable="false">loop_openmode_min_change</string>
<string name="loop_openmode_min_change">Minimal request change [%]</string>
<string name="loop_openmode_min_change_summary">Loop will popup new change request only if change is bigger than this value. Default value is 30%</string>
<plurals name="objective_days">
<item quantity="one">%1$d day</item>

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory
android:key="aps_general"
android:title="@string/loop">
<ListPreference
android:title="@string/apsmode_title"
android:key="@string/key_aps_mode"
android:defaultValue="open"
android:entries="@array/aps_modeArray"
android:entryValues="@array/aps_modeValues"/>
</PreferenceCategory>
</PreferenceScreen>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:validate="http://schemas.android.com/apk/res-auto">
<PreferenceCategory
android:key="aps_general"
android:title="@string/loop">
<ListPreference
android:title="@string/apsmode_title"
android:key="@string/key_aps_mode"
android:defaultValue="open"
android:entries="@array/aps_modeArray"
android:entryValues="@array/aps_modeValues"/>
<com.andreabaccega.widget.ValidatingEditTextPreference
android:defaultValue="30"
android:dialogMessage="@string/loop_openmode_min_change_summary"
android:digits="0123456789"
android:inputType="number"
android:key="@string/key_loop_openmode_min_change"
android:maxLines="1"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/loop_openmode_min_change"
validate:maxNumber="80"
validate:minNumber="10"
validate:testType="numericRange" />
</PreferenceCategory>
</PreferenceScreen>

View file

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