Skip to content

Commit 19c120d

Browse files
authored
Merge pull request #3704 from Navid200/Navid_2024_08_28
Persistent High Alert Threshold
2 parents 23c06fc + da08471 commit 19c120d

File tree

5 files changed

+91
-34
lines changed

5 files changed

+91
-34
lines changed

app/src/main/java/com/eveningoutpost/dexdrip/evaluators/PersistentHigh.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,30 @@ public class PersistentHigh {
3030

3131
private static final String TAG = PersistentHigh.class.getSimpleName();
3232
private static final String PERSISTENT_HIGH_SINCE = "persistent_high_since";
33+
public static double persistentHighThreshold = Home.convertToMgDlIfMmol(JoH.tolerantParseDouble(Pref.getString("highValue", "170"))); // By default, the persistent High threshold is equal to the High Value
3334

3435
public static boolean checkForPersistentHigh() {
3536

37+
if (!Pref.getBoolean("high_value_is_persistent_high_threshold", true)) { // If the user has chosen not to use the High Value as the threshold
38+
persistentHighThreshold = Home.convertToMgDlIfMmol(JoH.tolerantParseDouble(Pref.getString("persistent_high_threshold", "170"))); // Set the threshold to the value chosen by the user
39+
}
40+
3641
// skip if not enabled
3742
if (!Pref.getBooleanDefaultFalse("persistent_high_alert_enabled")) return false;
3843

3944

4045
final List<BgReading> last = BgReading.latest(1);
4146
if ((last != null) && (last.size() > 0)) {
4247

43-
final double highMarkMgDl = Home.convertToMgDlIfMmol(
44-
JoH.tolerantParseDouble(Pref.getString("highValue", "170"), 170d));
45-
4648
final long now = JoH.tsl();
4749
final long since = now - last.get(0).timestamp;
4850
// only process if last reading <10 mins
4951
if (since < MINUTE_IN_MS * 10) {
50-
// check if exceeding high
51-
if (last.get(0).getDg_mgdl() > highMarkMgDl) {
52+
// check if exceeding persistent high threshold
53+
if (last.get(0).getDg_mgdl() > persistentHighThreshold) {
5254

5355
final double this_slope = last.get(0).getDg_slope() * MINUTE_IN_MS;
54-
Log.d(TAG, "CheckForPersistentHigh: Slope: " + JoH.qs(this_slope)+ " "+JoH.dateTimeText(last.get(0).timestamp));
56+
Log.d(TAG, "CheckForPersistentHigh: Slope: " + JoH.qs(this_slope) + " " + JoH.dateTimeText(last.get(0).timestamp));
5557

5658
// if not falling
5759
if (this_slope > 0 && !last.get(0).hide_slope) {
@@ -78,7 +80,7 @@ public static boolean checkForPersistentHigh() {
7880
return false;
7981
}
8082

81-
if (!dataQualityCheck(high_since, highMarkMgDl)) {
83+
if (!dataQualityCheck(high_since, persistentHighThreshold)) {
8284
Log.d(TAG, "Insufficient data quality to raise persistent high alert");
8385
return false;
8486
}

app/src/main/java/com/eveningoutpost/dexdrip/models/BgReading.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.eveningoutpost.dexdrip.models;
22

3+
import static com.eveningoutpost.dexdrip.evaluators.PersistentHigh.persistentHighThreshold;
34
import static com.eveningoutpost.dexdrip.g5model.Ob1G5StateMachine.shortTxId;
45
import static com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.NOT_COMPUTABLE;
56
import static com.eveningoutpost.dexdrip.importedlibraries.dexcom.Dex_Constants.TREND_ARROW_VALUES.getTrend;
@@ -1834,10 +1835,8 @@ public static boolean checkForPersistentHigh() {
18341835
final long since = now - last.get(0).timestamp;
18351836
// only process if last reading <10 mins
18361837
if (since < 600000) {
1837-
// check if exceeding high
1838-
if (last.get(0).calculated_value >
1839-
Home.convertToMgDlIfMmol(
1840-
JoH.tolerantParseDouble(Pref.getString("highValue", "170")))) {
1838+
// check if exceeding persistent high threshold
1839+
if (last.get(0).calculated_value > persistentHighThreshold) {
18411840

18421841
final double this_slope = last.get(0).calculated_value_slope * 60000;
18431842
//Log.d(TAG, "CheckForPersistentHigh: Slope: " + JoH.qs(this_slope));

app/src/main/java/com/eveningoutpost/dexdrip/utils/Preferences.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,19 @@ public boolean onPreferenceChange(Preference preference, Object value) {
748748
return false;
749749
}
750750
};
751+
752+
private static Preference.OnPreferenceChangeListener sBindNumericUnitizedPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() { // This listener adds glucose unit in addition to the value to the summary
753+
@Override
754+
public boolean onPreferenceChange(Preference preference, Object value) {
755+
String stringValue = value.toString();
756+
if (isNumeric(stringValue)) {
757+
final boolean domgdl = Pref.getString("units", "mgdl").equals("mgdl"); // Identify which unit is chosen
758+
preference.setSummary(stringValue + " " + (domgdl ? "mg/dl" : "mmol/l")); // Set the summary to show the value followed by the chosen unit
759+
return true;
760+
}
761+
return false;
762+
}
763+
};
751764
private static Preference.OnPreferenceChangeListener sBindPreferenceTitleAppendToValueListenerUpdateChannel = new Preference.OnPreferenceChangeListener() {
752765
@Override
753766
public boolean onPreferenceChange(Preference preference, Object value) {
@@ -996,6 +1009,13 @@ private static void bindPreferenceSummaryToValueAndEnsureNumeric(Preference pref
9961009
.getString(preference.getKey(), ""));
9971010
}
9981011

1012+
private static void bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(Preference preference) { // Use this to show the value as well as the corresponding glucose unit as the summary
1013+
preference.setOnPreferenceChangeListener(sBindNumericUnitizedPreferenceSummaryToValueListener);
1014+
sBindNumericUnitizedPreferenceSummaryToValueListener.onPreferenceChange(preference,
1015+
PreferenceManager
1016+
.getDefaultSharedPreferences(preference.getContext())
1017+
.getString(preference.getKey(), ""));
1018+
}
9991019

10001020
@RequiredArgsConstructor
10011021
public static class AllPrefsFragment extends PreferenceFragment {
@@ -1074,6 +1094,7 @@ public void onCreate(Bundle savedInstanceState) {
10741094
bindPreferenceSummaryToValue(findPreference("rising_bg_val"));
10751095
bindPreferenceSummaryToValue(findPreference("other_alerts_sound"));
10761096
bindPreferenceSummaryToValue(findPreference("bridge_battery_alert_level"));
1097+
bindPreferenceSummaryToUnitizedValueAndEnsureNumeric(findPreference("persistent_high_threshold"));
10771098

10781099
addPreferencesFromResource(R.xml.pref_data_source);
10791100

@@ -3057,6 +3078,7 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
30573078
final Double lowVal = Double.parseDouble(preferences.getString("lowValue", "0"));
30583079
final Double default_insulin_sensitivity = Double.parseDouble(preferences.getString("profile_insulin_sensitivity_default", "54"));
30593080
final Double default_target_glucose = Double.parseDouble(preferences.getString("plus_target_range", "100"));
3081+
final Double persistent_high_Val = Double.parseDouble(preferences.getString("persistent_high_threshold", "0"));
30603082

30613083

30623084
static_units = newValue.toString();
@@ -3068,6 +3090,11 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
30683090
preferences.edit().putString("plus_target_range", Long.toString(Math.round(default_target_glucose * Constants.MMOLL_TO_MGDL))).apply();
30693091
Profile.invalidateProfile();
30703092
}
3093+
if (persistent_high_Val < 36) {
3094+
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
3095+
preferences.edit().putString("persistent_high_threshold", Long.toString(Math.round(persistent_high_Val * Constants.MMOLL_TO_MGDL))).apply();
3096+
Profile.invalidateProfile();
3097+
}
30713098
if (lowVal < 36) {
30723099
ProfileEditor.convertData(Constants.MMOLL_TO_MGDL);
30733100
preferences.edit().putString("lowValue", Long.toString(Math.round(lowVal * Constants.MMOLL_TO_MGDL))).apply();
@@ -3084,6 +3111,11 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
30843111
preferences.edit().putString("plus_target_range", JoH.qs(default_target_glucose * Constants.MGDL_TO_MMOLL,1)).apply();
30853112
Profile.invalidateProfile();
30863113
}
3114+
if (persistent_high_Val > 35) {
3115+
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
3116+
preferences.edit().putString("persistent_high_threshold", JoH.qs(persistent_high_Val * Constants.MGDL_TO_MMOLL, 1)).apply();
3117+
Profile.invalidateProfile();
3118+
}
30873119
if (lowVal > 35) {
30883120
ProfileEditor.convertData(Constants.MGDL_TO_MMOLL);
30893121
preferences.edit().putString("lowValue", JoH.qs(lowVal * Constants.MGDL_TO_MMOLL, 1)).apply();
@@ -3096,6 +3128,7 @@ public static void handleUnitsChange(Preference preference, Object newValue, All
30963128
if (allPrefsFragment != null) {
30973129
allPrefsFragment.setSummary("highValue");
30983130
allPrefsFragment.setSummary("lowValue");
3131+
allPrefsFragment.setSummary("persistent_high_threshold");
30993132
}
31003133
if (profile_insulin_sensitivity_default != null) {
31013134
Log.d(TAG, "refreshing profile insulin sensitivity default display");

app/src/main/res/values/strings.xml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@
241241
<string name="other_alerts">Other Alerts</string>
242242
<string name="extra_alerts_xdrip_plus">Extra Alerts (xDrip+)</string>
243243
<string name="persistent_high_alert">Persistent High Alert</string>
244+
<string name="persistent_high_alert_enable">Enable</string>
245+
<string name="title_persistent_high_threshold">Threshold</string>
244246
<string name="forecasted_low_alert">Forecasted Low Alert</string>
245247
<string name="extrapolate_data_to_try_to_predict_lows">Extrapolate data to try to predict lows</string>
246248
<string name="alarm_at_forecasted_low_mins">Alarm at Forecasted Low mins</string>
@@ -436,15 +438,15 @@
436438
<string name="new_version_date_colon">"New Version date: "</string>
437439
<string name="old_version_date_colon">"Old Version date: "</string>
438440
<string name="speak_your_note_text">Speak your note text</string>
439-
<string name="alarm_if_above_high_value">Alarm if above high value</string>
441+
<string name="alarm_if_above_high_value">Notify if above threshold for longer than the time specified below</string>
440442
<string name="for_longer_than_minutes">for longer than (minutes)</string>
441-
<string name="choose_sound_used_for_persistent_high_alarm">Choose sound used for persistent high alarm.</string>
442-
<string name="persistent_high_sound">Persistent High Sound</string>
443+
<string name="choose_sound_used_for_persistent_high_alarm">Choose the sound used for the alarm.</string>
444+
<string name="persistent_high_sound">Alert Sound</string>
443445
<string name="forecast_lows">Forecast Lows</string>
444446
<string name="raise_alarm_on_forecast_low">Raise alarm on Forecast Low</string>
445447
<string name="notify_when_predicted_low_time_reaches_threshold">Notify when predicted low time reaches threshold</string>
446-
<string name="predicted_low_sound">Predicted Low Sound</string>
447-
<string name="choose_sound_used_for_predicted_low_alarm">Choose sound used for predicted low alarm.</string>
448+
<string name="predicted_low_sound">Alert Sound</string>
449+
<string name="choose_sound_used_for_predicted_low_alarm">Choose the sound used for the alarm.</string>
448450
<string name="notify_when_parakeet_device_stops_checking_in">Notify when Parakeet device stops checking in</string>
449451
<string name="parakeet_related_alerts">Parakeet related alerts</string>
450452
<string name="raise_parakeet_notification_silently_when_charging">Raise Parakeet notification silently when charging</string>
@@ -1509,7 +1511,9 @@
15091511
<string name="category_noisy_readings">Noisy Readings</string>
15101512
<string name="category_falling_rising_bg">Falling/Rising BG</string>
15111513
<string name="category_alert_prefs">Alert Preferences (for these alerts)</string>
1512-
<string name="summary_persistent_high_alert">When above High level for too long and not heading downwards</string>
1514+
<string name="summary_persistent_high_alert">When above threshold and not falling for long</string>
1515+
<string name="summary_persistent_high_threshold_link">When enabled, High Value is the threshold.\nWhen disabled, the threshold is the value specified below.</string>
1516+
<string name="title_persistent_high_threshold_link">Threshold: High Value</string>
15131517
<string name="note_search_button">SEARCH</string>
15141518
<string name="all_note_button">ALL</string>
15151519
<string name="title_full_screen_mode">Full Screen mode</string>
@@ -1861,7 +1865,8 @@
18611865
<string name="summary_ymax">Choose yMax for when there are no greater readings.</string>
18621866
<string name="wait_to_connect">Verify settings and wait for connectivity.</string>
18631867
<string name="summary_sens_expiry_notify">Raise notifications when the sensor gets close to expiry.</string>
1864-
<string name="title_sens_expiry_notify">Sensor expiry</string>
1868+
<string name="title_sens_expiry">Sensor Expiry Notifications</string>
1869+
<string name="title_sens_expiry_notify">Enable</string>
18651870
<string name="close">Close</string>
18661871
<string name="title_advanced_settings_4_Lib2">Advanced settings for Libre 2</string>
18671872
<string name="title_Lib2_show_raw_values">Show raw values in graph</string>

app/src/main/res/xml/pref_notifications.xml

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,26 @@
293293
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
294294
android:key="smart_alerts_screen"
295295
android:title="@string/extra_alerts_xdrip_plus">
296-
<PreferenceCategory
297-
android:summary="@string/summary_persistent_high_alert"
296+
<PreferenceScreen
297+
android:key="persistent_high_alert_page"
298298
android:title="@string/persistent_high_alert">
299299
<SwitchPreference
300300
android:defaultValue="false"
301301
android:key="persistent_high_alert_enabled"
302302
android:summary="@string/alarm_if_above_high_value"
303-
android:title="@string/persistent_high_alert" />
303+
android:title="@string/persistent_high_alert_enable" />
304+
<SwitchPreference
305+
android:defaultValue="true"
306+
android:disableDependentsState="true"
307+
android:key="high_value_is_persistent_high_threshold"
308+
android:summary="@string/summary_persistent_high_threshold_link"
309+
android:title="@string/title_persistent_high_threshold_link" />
310+
<EditTextPreference
311+
android:defaultValue="170"
312+
android:dependency="high_value_is_persistent_high_threshold"
313+
android:inputType="numberDecimal"
314+
android:key="persistent_high_threshold"
315+
android:title="@string/title_persistent_high_threshold" />
304316
<EditTextPreference
305317
android:defaultValue="60"
306318
android:dependency="persistent_high_alert_enabled"
@@ -323,9 +335,9 @@
323335
android:showSilent="true"
324336
android:summary="@string/choose_sound_used_for_persistent_high_alarm"
325337
android:title="@string/persistent_high_sound" />
326-
</PreferenceCategory>
327-
<PreferenceCategory
328-
android:summary="@string/momentum_indicates_low"
338+
</PreferenceScreen>
339+
<PreferenceScreen
340+
android:key="@string/forecasted_low_alert"
329341
android:title="@string/forecasted_low_alert">
330342
<SwitchPreference
331343
android:defaultValue="true"
@@ -354,8 +366,21 @@
354366
android:showSilent="true"
355367
android:summary="@string/choose_sound_used_for_predicted_low_alarm"
356368
android:title="@string/predicted_low_sound" />
357-
</PreferenceCategory>
358-
<PreferenceCategory android:title="@string/other_xdrip_plus_alerts">
369+
</PreferenceScreen>
370+
<PreferenceScreen
371+
android:key="@string/title_sens_expiry"
372+
android:title="@string/title_sens_expiry">
373+
<SwitchPreference
374+
android:defaultValue="false"
375+
android:key="alert_raise_for_sensor_expiry"
376+
android:summary="@string/summary_sens_expiry_notify"
377+
android:switchTextOff="@string/short_off_text_for_switches"
378+
android:switchTextOn="@string/short_on_text_for_switches"
379+
android:title="@string/title_sens_expiry_notify" />
380+
</PreferenceScreen>
381+
<PreferenceScreen
382+
android:key="@string/other_xdrip_plus_alerts"
383+
android:title="@string/other_xdrip_plus_alerts">
359384
<SwitchPreference
360385
android:defaultValue="true"
361386
android:key="bridge_battery_alerts"
@@ -369,13 +394,6 @@
369394
android:key="bridge_battery_alert_level"
370395
android:summary=""
371396
android:title="@string/low_battery_percentage" />
372-
<SwitchPreference
373-
android:defaultValue="false"
374-
android:switchTextOff="@string/short_off_text_for_switches"
375-
android:switchTextOn="@string/short_on_text_for_switches"
376-
android:key="alert_raise_for_sensor_expiry"
377-
android:summary="@string/summary_sens_expiry_notify"
378-
android:title="@string/title_sens_expiry_notify" />
379397
<SwitchPreference
380398
android:defaultValue="true"
381399
android:dependency="engineering_mode"
@@ -393,7 +411,7 @@
393411
android:key="follower_chime"
394412
android:summary="@string/notify_data_arrives_master"
395413
android:title="@string/follower_chime_new" />
396-
</PreferenceCategory>
414+
</PreferenceScreen>
397415
</PreferenceScreen>
398416
</PreferenceCategory>
399417
</PreferenceScreen>

0 commit comments

Comments
 (0)