From 1fa3a2a6972fcaeff26a1f2225bdd3109cf3fffc Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Tue, 9 May 2017 23:23:37 +0200 Subject: [PATCH 1/4] bgi on watch status (optional) --- .../wearintegration/WatchUpdaterService.java | 88 +++++++++++-------- .../XDripStatusline/StatuslinePlugin.java | 10 +++ app/src/main/res/values/strings.xml | 2 + app/src/main/res/xml/pref_wear.xml | 6 ++ app/src/main/res/xml/pref_xdripstatus.xml | 5 ++ 5 files changed, 75 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java index 5df62fd4dd..2a2ef68156 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Wear/wearintegration/WatchUpdaterService.java @@ -7,6 +7,7 @@ import android.content.SharedPreferences; import android.os.BatteryManager; import android.os.Bundle; import android.preference.PreferenceManager; +import android.support.annotation.NonNull; import android.util.Log; import com.google.android.gms.common.ConnectionResult; @@ -503,42 +504,7 @@ public class WatchUpdaterService extends WearableListenerService implements private void sendStatus() { if (googleApiClient.isConnected()) { - String status = ""; - boolean shortString = true; - - LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); - - if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) { - status += getString(R.string.disabledloop) + "\n"; - lastLoopStatus = false; - } else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { - lastLoopStatus = true; - } - - //Temp basal - PumpInterface pump = MainApp.getConfigBuilder(); - - if (pump.isTempBasalInProgress()) { - TempBasal activeTemp = pump.getTempBasal(); - if (shortString) { - status += activeTemp.toStringShort(); - } else { - status += activeTemp.toStringMedium(); - } - } - - //IOB - MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB(); - IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round(); - MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB(); - IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round(); - status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); - - if (mPrefs.getBoolean("wear_detailediob", true)) { - status += "(" - + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" - + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; - } + String status = generateStatusString(); PutDataMapRequest dataMapRequest = PutDataMapRequest.create(NEW_STATUS_PATH); //unique content @@ -551,6 +517,56 @@ public class WatchUpdaterService extends WearableListenerService implements } } + @NonNull + private String generateStatusString() { + String status = ""; + boolean shortString = true; + + LoopPlugin activeloop = MainApp.getConfigBuilder().getActiveLoop(); + + if (activeloop != null && !activeloop.isEnabled(PluginBase.LOOP)) { + status += getString(R.string.disabledloop) + "\n"; + lastLoopStatus = false; + } else if (activeloop != null && activeloop.isEnabled(PluginBase.LOOP)) { + lastLoopStatus = true; + } + + //Temp basal + PumpInterface pump = MainApp.getConfigBuilder(); + + if (pump.isTempBasalInProgress()) { + TempBasal activeTemp = pump.getTempBasal(); + if (shortString) { + status += activeTemp.toStringShort(); + } else { + status += activeTemp.toStringMedium(); + } + } + + //IOB + MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOB(); + IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculation().round(); + MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOB(); + IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculation().round(); + status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob); + + if (mPrefs.getBoolean("wear_detailediob", true)) { + status += "(" + + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" + + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; + } + NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + if (!mPrefs.getBoolean("wear_showbgi", false) ||profile == null || profile.getIsf(NSProfile.secondsFromMidnight()) == null || profile.getIc(NSProfile.secondsFromMidnight()) == null) { + return status; + } + + double bgi = -(bolusIob.activity + basalIob.activity)*5*profile.getIsf(NSProfile.secondsFromMidnight()); + + status += " " + ((bgi>=0)?"+":"") + DecimalFormatter.to2Decimal(bgi); + + return status; + } + @Override public void onDestroy() { if (googleApiClient != null && googleApiClient.isConnected()) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java index 3cd1f8fe27..d7265bfa3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/XDripStatusline/StatuslinePlugin.java @@ -21,6 +21,7 @@ import info.nightscout.androidaps.events.EventTreatmentChange; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Loop.LoopPlugin; +import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; import info.nightscout.utils.DecimalFormatter; /** @@ -181,6 +182,15 @@ public class StatuslinePlugin implements PluginBase { + DecimalFormatter.to2Decimal(bolusIob.iob) + "|" + DecimalFormatter.to2Decimal(basalIob.basaliob) + ")"; } + NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile(); + if (!mPrefs.getBoolean("xdripstatus_showbgi", false) ||profile == null || profile.getIsf(NSProfile.secondsFromMidnight()) == null || profile.getIc(NSProfile.secondsFromMidnight()) == null) { + return status; + } + + double bgi = -(bolusIob.activity + basalIob.activity)*5*profile.getIsf(NSProfile.secondsFromMidnight()); + + status += " " + ((bgi>=0)?"+":"") + DecimalFormatter.to2Decimal(bgi); + return status; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4370d8f297..629830dac8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -603,4 +603,6 @@ xDrip Status (watch) xDrip Statusline (watch) xds + Show BGI + Add BGI to status line diff --git a/app/src/main/res/xml/pref_wear.xml b/app/src/main/res/xml/pref_wear.xml index bc5c475f9e..a2458f76f0 100644 --- a/app/src/main/res/xml/pref_wear.xml +++ b/app/src/main/res/xml/pref_wear.xml @@ -9,6 +9,12 @@ android:key="wear_detailediob" android:title="@string/wear_detailedIOB_title" android:summary="@string/wear_detailedIOB_summary"/> + + \ No newline at end of file diff --git a/app/src/main/res/xml/pref_xdripstatus.xml b/app/src/main/res/xml/pref_xdripstatus.xml index b11830df5d..959377ea7b 100644 --- a/app/src/main/res/xml/pref_xdripstatus.xml +++ b/app/src/main/res/xml/pref_xdripstatus.xml @@ -9,6 +9,11 @@ android:key="xdripstatus_detailediob" android:title="@string/wear_detailedIOB_title" android:summary="@string/wear_detailedIOB_summary"/> + \ No newline at end of file From fc85deb62d74fa36efabe5f9b514c05fc6f55eae Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 10 May 2017 01:18:27 +0200 Subject: [PATCH 2/4] move evaluation of always_use_shortavg setting to the OAPS plugins For the overview and the watch we still may use the standard delta, even if this setting is enabled. (Also good to check that it is the same as in xDrip e.g.) --- .../info/nightscout/androidaps/data/GlucoseStatus.java | 2 +- .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 9 ++++++++- .../plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java | 9 ++++++++- 3 files changed, 17 insertions(+), 3 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 ad9b0acecf..c4caf2f1af 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/data/GlucoseStatus.java @@ -131,7 +131,7 @@ public class GlucoseStatus { status.short_avgdelta = average(short_deltas); - if (prefs.getBoolean("always_use_shortavg", false) || last_deltas.isEmpty()) { + if (last_deltas.isEmpty()) { status.delta = status.short_avgdelta; } else { status.delta = average(last_deltas); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index e2c7f20284..5b69b61728 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.OpenAPSAMA; +import android.preference.PreferenceManager; + import com.eclipsesource.v8.JavaVoidCallback; import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8Array; @@ -243,7 +245,12 @@ public class DetermineBasalAdapterAMAJS { mGlucoseStatus = new V8Object(mV8rt); mGlucoseStatus.add("glucose", glucoseStatus.glucose); - mGlucoseStatus.add("delta", glucoseStatus.delta); + + if(PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).getBoolean("always_use_shortavg", false)){ + mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta); + } else { + mGlucoseStatus.add("delta", glucoseStatus.delta); + } mGlucoseStatus.add("short_avgdelta", glucoseStatus.short_avgdelta); mGlucoseStatus.add("long_avgdelta", glucoseStatus.long_avgdelta); mV8rt.add(PARAM_glucoseStatus, mGlucoseStatus); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index 75f87021c5..d51864aea3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -1,5 +1,7 @@ package info.nightscout.androidaps.plugins.OpenAPSMA; +import android.preference.PreferenceManager; + import com.eclipsesource.v8.JavaVoidCallback; import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8Array; @@ -13,6 +15,7 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import info.nightscout.androidaps.Config; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData; @@ -251,7 +254,11 @@ public class DetermineBasalAdapterMAJS { mIobData.add("hightempinsulin", iobData.hightempinsulin); mGlucoseStatus.add("glucose", glucoseStatus.glucose); - mGlucoseStatus.add("delta", glucoseStatus.delta); + if(PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).getBoolean("always_use_shortavg", false)){ + mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta); + } else { + mGlucoseStatus.add("delta", glucoseStatus.delta); + } mGlucoseStatus.add("avgdelta", glucoseStatus.avgdelta); mMealData.add("carbs", mealData.carbs); From b247b814282ec88a81cfd9c6031eb04441d55c18 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 10 May 2017 16:33:41 +0200 Subject: [PATCH 3/4] use helper class to query settings --- .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 2 +- .../plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 5b69b61728..6dcd4fe653 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -246,7 +246,7 @@ public class DetermineBasalAdapterAMAJS { mGlucoseStatus = new V8Object(mV8rt); mGlucoseStatus.add("glucose", glucoseStatus.glucose); - if(PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).getBoolean("always_use_shortavg", false)){ + if(SP.getBoolean("always_use_shortavg", false)){ mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta); } else { mGlucoseStatus.add("delta", glucoseStatus.delta); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index d51864aea3..bb6cc26157 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -22,6 +22,7 @@ import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.plugins.Loop.ScriptReader; import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile; +import info.nightscout.utils.SP; public class DetermineBasalAdapterMAJS { private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class); @@ -254,7 +255,7 @@ public class DetermineBasalAdapterMAJS { mIobData.add("hightempinsulin", iobData.hightempinsulin); mGlucoseStatus.add("glucose", glucoseStatus.glucose); - if(PreferenceManager.getDefaultSharedPreferences(MainApp.instance()).getBoolean("always_use_shortavg", false)){ + if(SP.getBoolean("always_use_shortavg", false)){ mGlucoseStatus.add("delta", glucoseStatus.short_avgdelta); } else { mGlucoseStatus.add("delta", glucoseStatus.delta); From 201d2df16bc824cb809e0fe3dd7cee9026a43a94 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 10 May 2017 16:37:11 +0200 Subject: [PATCH 4/4] cleanup imports --- .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 2 -- .../plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java | 3 --- 2 files changed, 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 6dcd4fe653..4ce3cd61b5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.OpenAPSAMA; -import android.preference.PreferenceManager; - import com.eclipsesource.v8.JavaVoidCallback; import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8Array; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java index bb6cc26157..ee0a00b802 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSMA/DetermineBasalAdapterMAJS.java @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.OpenAPSMA; -import android.preference.PreferenceManager; - import com.eclipsesource.v8.JavaVoidCallback; import com.eclipsesource.v8.V8; import com.eclipsesource.v8.V8Array; @@ -15,7 +13,6 @@ import org.slf4j.LoggerFactory; import java.io.IOException; import info.nightscout.androidaps.Config; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.GlucoseStatus; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.MealData;