carbs absorption settings

This commit is contained in:
Milos Kozak 2017-06-25 11:16:19 +02:00
parent ac98852f79
commit 3f641f9c30
8 changed files with 91 additions and 19 deletions

View file

@ -21,6 +21,7 @@ import info.nightscout.androidaps.plugins.NSClientInternal.NSClientInternalPlugi
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin; import info.nightscout.androidaps.plugins.PumpDanaRv2.DanaRv2Plugin;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin; import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.SensitivityMK.SensitivityMKPlugin;
import info.nightscout.androidaps.plugins.Wear.WearPlugin; import info.nightscout.androidaps.plugins.Wear.WearPlugin;
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin; import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
import info.nightscout.utils.LocaleHelper; import info.nightscout.utils.LocaleHelper;
@ -105,6 +106,8 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre
if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS)) if (MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class) != null && MainApp.getSpecificPlugin(OpenAPSAMAPlugin.class).isEnabled(PluginBase.APS))
addPreferencesFromResource(R.xml.pref_openapsama); addPreferencesFromResource(R.xml.pref_openapsama);
} }
if (MainApp.getSpecificPlugin(SensitivityMKPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityMKPlugin.class).isEnabled(PluginBase.SENSITIVITY))
addPreferencesFromResource(R.xml.pref_absorption);
if (Config.ALLPREFERENCES) { if (Config.ALLPREFERENCES) {
addPreferencesFromResource(R.xml.pref_profile); addPreferencesFromResource(R.xml.pref_profile);
} }

View file

@ -7,7 +7,12 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Treatment; import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.plugins.SensitivityMK.SensitivityMKPlugin;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
/** /**
@ -27,9 +32,18 @@ public class AutosensData {
time = t.date; time = t.date;
carbs = t.carbs; carbs = t.carbs;
remaining = t.carbs; remaining = t.carbs;
if (MainApp.getSpecificPlugin(SensitivityMKPlugin.class) != null && MainApp.getSpecificPlugin(SensitivityMKPlugin.class).isEnabled(PluginBase.SENSITIVITY)) {
double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d);
Profile profile = MainApp.getConfigBuilder().getProfile(t.date);
double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits());
double ic = profile.getIc(t.date);
min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic;
log.debug("Min 5m carbs impact for " + carbs + "g @" + new Date(t.date).toLocaleString() + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic);
} else {
min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", 3.0); min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", 3.0);
} }
} }
}
public long time = 0L; public long time = 0L;
public String pastSensitivity = ""; public String pastSensitivity = "";

View file

@ -599,7 +599,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
@Subscribe @Subscribe
public void onStatusEvent(EventPreferenceChange ev) { public void onStatusEvent(EventPreferenceChange ev) {
if (ev.isChanged(R.string.key_openapsama_autosens_period) || if (ev.isChanged(R.string.key_openapsama_autosens_period) ||
ev.isChanged(R.string.key_age) ev.isChanged(R.string.key_age) ||
ev.isChanged(R.string.key_absorption_maxtime)
) { ) {
synchronized (dataLock) { synchronized (dataLock) {
log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records"); log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");

View file

@ -305,11 +305,14 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50); iobGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
iobGraph.getGridLabelRenderer().setNumVerticalLabels(5); iobGraph.getGridLabelRenderer().setNumVerticalLabels(5);
rangeToDisplay = SP.getInt(R.string.key_rangetodisplay, 6);
bgGraph.setOnLongClickListener(new View.OnLongClickListener() { bgGraph.setOnLongClickListener(new View.OnLongClickListener() {
@Override @Override
public boolean onLongClick(View v) { public boolean onLongClick(View v) {
rangeToDisplay += 6; rangeToDisplay += 6;
rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay; rangeToDisplay = rangeToDisplay > 24 ? 6 : rangeToDisplay;
SP.putInt(R.string.key_rangetodisplay, rangeToDisplay);
updateGUI("rangeChange"); updateGUI("rangeChange");
return false; return false;
} }

View file

@ -49,12 +49,20 @@ public class SP {
} }
static public int getInt(int resourceID, Integer defaultValue) { static public int getInt(int resourceID, Integer defaultValue) {
try {
return sharedPreferences.getInt(MainApp.sResources.getString(resourceID), defaultValue);
} catch (Exception e) {
return SafeParse.stringToInt(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString())); return SafeParse.stringToInt(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString()));
} }
}
static public int getInt(String key, Integer defaultValue) { static public int getInt(String key, Integer defaultValue) {
try {
return sharedPreferences.getInt(key, defaultValue);
} catch (Exception e) {
return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString())); return SafeParse.stringToInt(sharedPreferences.getString(key, defaultValue.toString()));
} }
}
static public long getLong(int resourceID, Long defaultValue) { static public long getLong(int resourceID, Long defaultValue) {
return SafeParse.stringToLong(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString())); return SafeParse.stringToLong(sharedPreferences.getString(MainApp.sResources.getString(resourceID), defaultValue.toString()));
@ -92,6 +100,24 @@ public class SP {
editor.apply(); editor.apply();
} }
static public void putLong(int resourceID, long value) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putLong(MainApp.sResources.getString(resourceID), value);
editor.apply();
}
static public void putInt(String key, int value) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(key, value);
editor.apply();
}
static public void putInt(int resourceID, int value) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(MainApp.sResources.getString(resourceID), value);
editor.apply();
}
static public void putString(int resourceID, String value) { static public void putString(int resourceID, String value) {
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(MainApp.sResources.getString(resourceID), value); editor.putString(MainApp.sResources.getString(resourceID), value);

View file

@ -657,4 +657,9 @@
<string name="sensitivity_shortname">SENS</string> <string name="sensitivity_shortname">SENS</string>
<string name="sensitivityoref0">Sensitivity Oref0</string> <string name="sensitivityoref0">Sensitivity Oref0</string>
<string name="sensitivitymk">Sensitivity MK</string> <string name="sensitivitymk">Sensitivity MK</string>
<string name="absorptionsettings_title">Absorption settings</string>
<string name="key_absorption_maxtime" translatable="false">absorption_maxtime</string>
<string name="absorption_maxtime_title">Meal max absorption time</string>
<string name="absorption_maxtime_summary">Time in hours where is expected all carbs from meal will be absorbed</string>
<string name="key_rangetodisplay" translatable="false">rangetodisplay</string>
</resources> </resources>

View file

@ -0,0 +1,35 @@
<?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="absorption"
android:title="@string/absorptionsettings_title">
<com.andreabaccega.widget.ValidatingEditTextPreference
validate:testType="numericRange"
validate:minNumber="1"
validate:maxNumber="10"
android:digits="0123456789.,"
android:defaultValue="3"
android:selectAllOnFocus="true"
android:inputType="number"
android:maxLines="20"
android:title="@string/absorption_maxtime_title"
android:dialogMessage="@string/absorption_maxtime_summary"
android:key="@string/key_absorption_maxtime" />
<com.andreabaccega.widget.ValidatingEditTextPreference
validate:maxNumber="24"
validate:minNumber="4"
validate:testType="numericRange"
android:defaultValue="24"
android:dialogMessage="@string/openapsama_autosens_period_summary"
android:digits="0123456789"
android:inputType="number"
android:key="@string/key_openapsama_autosens_period"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/openapsama_autosens_period" />
</PreferenceCategory>
</PreferenceScreen>

View file

@ -10,21 +10,6 @@
android:key="openapsama_useautosens" android:key="openapsama_useautosens"
android:title="@string/openapsama_useautosens" /> android:title="@string/openapsama_useautosens" />
<com.andreabaccega.widget.ValidatingEditTextPreference
validate:maxNumber="24"
validate:minNumber="4"
validate:testType="numericRange"
android:defaultValue="24"
android:dependency="openapsama_useautosens"
android:dialogMessage="@string/openapsama_autosens_period_summary"
android:digits="0123456789"
android:inputType="number"
android:key="@string/key_openapsama_autosens_period"
android:maxLines="20"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/openapsama_autosens_period" />
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>