From 3a43858948210b736d59d968ed1db65beeb8a4c5 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 24 Jan 2017 02:21:25 +0100 Subject: [PATCH] Settings for deltas --- .../nightscout/androidaps/data/GlucoseStatus.java | 14 +++++++++++++- app/src/main/res/values/strings.xml | 5 +++++ app/src/main/res/xml/pref_openapsma.xml | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java index 2ad8fedddf..c88d17ca38 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.data; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.support.annotation.Nullable; import android.text.Html; import android.text.Spanned; @@ -25,6 +27,7 @@ public class GlucoseStatus { public double short_avgdelta = 0d; public double long_avgdelta = 0d; + @Override public String toString() { return MainApp.sResources.getString(R.string.glucose) + " " + DecimalFormatter.to0Decimal(glucose) + " mg/dl\n" + @@ -54,6 +57,8 @@ public class GlucoseStatus { @Nullable public static GlucoseStatus getGlucoseStatusData() { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(MainApp.instance()); + // load 45min long fromtime = (long) (new Date().getTime() - 60 * 1000L * 45); List data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false); @@ -104,8 +109,15 @@ public class GlucoseStatus { GlucoseStatus status = new GlucoseStatus(); status.glucose = now.value; - status.delta = average(last_deltas); + status.short_avgdelta = average(short_deltas); + + if(prefs.getBoolean("always_use_shortavg",false) || (last_deltas.isEmpty() && prefs.getBoolean("default_to_shortavg",false))){ + status.delta = status.short_avgdelta; + } else { + status.delta = average(last_deltas); + } + status.long_avgdelta = average(long_deltas); status.avgdelta = status.short_avgdelta; // for OpenAPS MA diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0d033d715f..0045693f75 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -448,4 +448,9 @@ WEAR SMS Shorten tab titles + Delta Settings + Default to short average delta + Use short average delta when simple delta cannot be computed. + Always use short average delta instead of simple delta + Useful when data from unfiltered sources like xDrip gets noisy. diff --git a/app/src/main/res/xml/pref_openapsma.xml b/app/src/main/res/xml/pref_openapsma.xml index 1834822070..cddb62531b 100644 --- a/app/src/main/res/xml/pref_openapsma.xml +++ b/app/src/main/res/xml/pref_openapsma.xml @@ -30,6 +30,18 @@ android:key="openapsma_max_iob" android:numeric="decimal" android:title="@string/openapsma_maxiob_summary" /> + + + + - \ No newline at end of file