Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fmegen/3.3.0.0 - Adding VeryHigh Overview Display Option #3678

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
2 changes: 2 additions & 0 deletions app/src/main/kotlin/app/aaps/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,10 @@ class MainApp : DaggerApplication() {
if (preferences.get(UnitDoubleKey.OverviewActivityTarget) == 0.0) preferences.remove(UnitDoubleKey.OverviewActivityTarget)
if (preferences.get(IntKey.OverviewHypoDuration) == 0) preferences.remove(IntKey.OverviewHypoDuration)
if (preferences.get(UnitDoubleKey.OverviewHypoTarget) == 0.0) preferences.remove(UnitDoubleKey.OverviewHypoTarget)
if (preferences.get(UnitDoubleKey.OverviewVeryLowMark) == 0.0) preferences.remove(UnitDoubleKey.OverviewVeryLowMark)
if (preferences.get(UnitDoubleKey.OverviewLowMark) == 0.0) preferences.remove(UnitDoubleKey.OverviewLowMark)
if (preferences.get(UnitDoubleKey.OverviewHighMark) == 0.0) preferences.remove(UnitDoubleKey.OverviewHighMark)
if (preferences.get(UnitDoubleKey.OverviewVeryHighMark) == 0.0) preferences.remove(UnitDoubleKey.OverviewVeryHighMark)
if (preferences.getIfExists(BooleanKey.GeneralSimpleMode) == null)
preferences.put(BooleanKey.GeneralSimpleMode, !preferences.get(BooleanKey.GeneralSetupWizardProcessed))
// Migrate from OpenAPSSMBDynamicISFPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ class InMemoryGlucoseValueDataPoint(
@ColorInt
override fun color(context: Context?): Int {
val units = profileFunction.getUnits()
val veryLowLine = preferences.get(UnitDoubleKey.OverviewVeryLowMark)
val lowLine = preferences.get(UnitDoubleKey.OverviewLowMark)
val highLine = preferences.get(UnitDoubleKey.OverviewHighMark)
val veryHighLine = preferences.get(UnitDoubleKey.OverviewVeryHighMark)
val color = when {
valueToUnits(units) < veryLowLine -> rh.gac(context, app.aaps.core.ui.R.attr.bgVeryLow)
valueToUnits(units) < lowLine -> rh.gac(context, app.aaps.core.ui.R.attr.bgLow)
valueToUnits(units) > veryHighLine -> rh.gac(context, app.aaps.core.ui.R.attr.veryHighColor)
valueToUnits(units) > highLine -> rh.gac(context, app.aaps.core.ui.R.attr.highColor)
else -> rh.gac(context, app.aaps.core.ui.R.attr.bgInRange)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ interface LastBgData {
*/
fun lastBg(): InMemoryGlucoseValue?

/**
* Is last value below display very low target?
*
* @return true if below
*/
fun isVeryLow(): Boolean

/**
* Is last value below display low target?
*
Expand All @@ -34,6 +41,13 @@ interface LastBgData {
*/
fun isHigh(): Boolean

/**
* Is last value above display high very target?
*
* @return true if above
*/
fun isVeryHigh(): Boolean

/**
* Evaluate color based on low - in - high
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ sealed class EventData : Event() {
val avgDeltaDetailed: String = "--",
val sgvLevel: Long = 0,
val sgv: Double,
val veryHigh: Double, // veryHighLine
val high: Double, // highLine
val low: Double, // lowLine
val veryLow: Double, // veryLowLine
val color: Int = 0,
val deltaMgdl: Double? = null,
val avgDeltaMgdl: Double? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ class EventDataTest {
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
}
EventData.SingleBg(dataset = 0, 1, sgv = 2.0, high = 3.0, low = 4.0).let {
EventData.SingleBg(dataset = 0, 1, sgv = 2.0, veryHigh = 5.0, high = 3.0, low = 4.0, veryLow = 6.0).let {
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
}
EventData.GraphData(arrayListOf(EventData.SingleBg(dataset = 0, 1, sgv = 2.0, high = 3.0, low = 4.0))).let {
EventData.GraphData(arrayListOf(EventData.SingleBg(dataset = 0, 1, sgv = 2.0, veryHigh = 5.0, high = 3.0, low = 4.0, veryLow = 6.0))).let {
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
}
EventData.TreatmentData(
arrayListOf(EventData.TreatmentData.TempBasal(1, 2.0, 3, 4.0, 5.0)),
arrayListOf(EventData.TreatmentData.Basal(1, 2, 3.0)),
arrayListOf(EventData.TreatmentData.Treatment(1, 2.0, 3.0, true, isValid = true)),
arrayListOf(EventData.SingleBg(dataset = 0, 1, sgv = 2.0, high = 3.0, low = 4.0))
arrayListOf(EventData.SingleBg(dataset = 0, 1, sgv = 2.0, veryHigh = 5.0, high = 3.0, low = 4.0, veryLow = 6.0))
).let {
assertThat(EventData.deserializeByte(it.serializeByte())).isEqualTo(it)
assertThat(EventData.deserialize(it.serialize())).isEqualTo(it)
Expand Down
2 changes: 2 additions & 0 deletions core/keys/src/main/kotlin/app/aaps/core/keys/UnitDoubleKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ enum class UnitDoubleKey(
OverviewEatingSoonTarget("eatingsoon_target", 90.0, 72, 160, defaultedBySM = true),
OverviewActivityTarget("activity_target", 140.0, 108, 180, defaultedBySM = true),
OverviewHypoTarget("hypo_target", 160.0, 108, 180, defaultedBySM = true),
OverviewVeryLowMark("very_low_mark", 55.0, 40, 80, showInNsClientMode = false),
OverviewLowMark("low_mark", 72.0, 25, 160, showInNsClientMode = false, hideParentScreenIfHidden = true),
OverviewHighMark("high_mark", 180.0, 90, 250, showInNsClientMode = false),
OverviewVeryHighMark("very_high_mark", 400.0, 200, 400, showInNsClientMode = false),
ApsLgsThreshold("lgsThreshold", 65.0, 60, 100, defaultedBySM = true, dependency = BooleanKey.ApsUseDynamicSensitivity)
}
4 changes: 3 additions & 1 deletion core/ui/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@
<item name="cgmDexColor">@color/byodaGray</item>
<item name="cgmXdripColor">@color/colorCalibrationButton</item>
<!---BG color-->
<item name="bgLow">@color/low</item>
<item name="bgVeryLow">@color/low</item>
<item name="bgLow">@color/high</item>
<item name="highColor">@color/high</item>
<item name="veryHighColor">@color/low</item>
<item name="bgInRange">@color/inRange</item>
<!---Profile Helper -->
<item name="helperProfileColor">@color/helperProfile</item>
Expand Down
2 changes: 2 additions & 0 deletions core/ui/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@
<attr name="cgmDexColor" format="reference|color" />
<attr name="cgmXdripColor" format="reference|color" />
<!---BG color-->
<attr name="bgVeryLow" format="reference|color" />
<attr name="bgLow" format="reference|color" />
<attr name="highColor" format="reference|color" />
<attr name="veryHighColor" format="reference|color" />
<attr name="bgInRange" format="reference|color" />
<!---Profile Helper -->
<attr name="helperProfileColor" format="reference|color" />
Expand Down
4 changes: 3 additions & 1 deletion core/ui/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,10 @@
we generate extra colornames only used for the widget
Colors for the widget are always taken from the default color.xml-->
<color name="widget_inrange">#00FF00</color>
<color name="widget_low">#FF0000</color>
<color name="widget_very_low">#FF0000</color>
<color name="widget_low">#FFFF00</color>
<color name="widget_high">#FFFF00</color>
<color name="widget_very_high">#FF0000</color>
<color name="widget_ribbonWarning">#f4d700</color>
<color name="widget_ribbonTextDefault">#FFFFFF</color>
<color name="widget_ribbonCritical">#ff0400</color>
Expand Down
4 changes: 3 additions & 1 deletion core/ui/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@
<item name="cgmDexColor">@color/byodaGray</item>
<item name="cgmXdripColor">@color/colorCalibrationButton</item>
<!---BG color-->
<item name="bgLow">@color/low</item>
<item name="bgVeryLow">@color/low</item>
<item name="bgLow">@color/high</item>
<item name="highColor">@color/high</item>
<item name="veryHighColor">@color/low</item>
<item name="bgInRange">@color/tempTargetConfirmation</item>
<!---Profile Helper -->
<item name="helperProfileColor">@color/helperProfile</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class LastBgDataImpl @Inject constructor(
iobCobCalculator.ads.bucketedData?.firstOrNull()
?: persistenceLayer.getLastGlucoseValue()?.let { InMemoryGlucoseValue.fromGv(it) }

override fun isVeryLow(): Boolean =
lastBg()?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) < preferences.get(UnitDoubleKey.OverviewVeryLowMark)
} == true

override fun isLow(): Boolean =
lastBg()?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) < preferences.get(UnitDoubleKey.OverviewLowMark)
Expand All @@ -41,10 +46,17 @@ class LastBgDataImpl @Inject constructor(
lastBg.valueToUnits(profileFunction.getUnits()) > preferences.get(UnitDoubleKey.OverviewHighMark)
} == true

override fun isVeryHigh(): Boolean =
lastBg()?.let { lastBg ->
lastBg.valueToUnits(profileFunction.getUnits()) > preferences.get(UnitDoubleKey.OverviewVeryHighMark)
} == true

@ColorInt
override fun lastBgColor(context: Context?): Int =
when {
isVeryLow() -> rh.gac(context, app.aaps.core.ui.R.attr.bgVeryLow)
isLow() -> rh.gac(context, app.aaps.core.ui.R.attr.bgLow)
isVeryHigh() -> rh.gac(context, app.aaps.core.ui.R.attr.veryHighColor)
isHigh() -> rh.gac(context, app.aaps.core.ui.R.attr.highColor)
else -> rh.gac(context, app.aaps.core.ui.R.attr.bgInRange)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ class SWDefinition @Inject constructor(
private val displaySettings
get() = SWScreen(injector, R.string.display_settings)
.skippable(false)
.add(
SWEditNumberWithUnits(injector, UnitDoubleKey.OverviewVeryLowMark.defaultValue * Constants.MGDL_TO_MMOLL, 3.0, 8.0)
.preference(UnitDoubleKey.OverviewVeryLowMark)
.updateDelay(5)
.label(R.string.very_low_mark)
.comment(R.string.very_low_mark_comment)
)
.add(SWBreak(injector))
.add(
SWEditNumberWithUnits(injector, UnitDoubleKey.OverviewLowMark.defaultValue * Constants.MGDL_TO_MMOLL, 3.0, 8.0)
.preference(UnitDoubleKey.OverviewLowMark)
Expand All @@ -148,6 +156,14 @@ class SWDefinition @Inject constructor(
.label(R.string.high_mark)
.comment(R.string.high_mark_comment)
)
.add(SWBreak(injector))
.add(
SWEditNumberWithUnits(injector, UnitDoubleKey.OverviewVeryHighMark.defaultValue * Constants.MGDL_TO_MMOLL, 5.0, 23.0)
.preference(UnitDoubleKey.OverviewVeryHighMark)
.updateDelay(5)
.label(R.string.very_high_mark)
.comment(R.string.very_high_mark_comment)
)

private val screenPermissionWindow
get() = SWScreen(injector, R.string.permission)
Expand Down
4 changes: 4 additions & 0 deletions plugins/configuration/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
<string name="end_user_license_agreement_text">MUST NOT BE USED TO MAKE MEDICAL DECISIONS. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.</string>
<string name="end_user_license_agreement_i_understand">I UNDERSTAND AND AGREE</string>
<string name="display_settings">Display Settings</string>
<string name="very_low_mark">VERY LOW mark</string>
<string name="low_mark">LOW mark</string>
<string name="high_mark">HIGH mark</string>
<string name="very_high_mark">VERY HIGH mark</string>
<string name="very_low_mark_comment">Very Low value of in range area (display only)</string>
<string name="low_mark_comment">Lower value of in range area (display only)</string>
<string name="high_mark_comment">Higher value of in range area (display only)</string>
<string name="very_high_mark_comment">Even Higher value of in range area (display only)</string>
<string name="permission">Permission</string>
<string name="need_system_window_permission">Application needs system window permission for notifications</string>
<string name="need_location_permission">Application needs location permission for BT scan and WiFi identification</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ class OverviewPlugin @Inject constructor(
.put(UnitDoubleKey.OverviewActivityTarget, preferences)
.put(IntKey.OverviewHypoDuration, preferences)
.put(UnitDoubleKey.OverviewHypoTarget, preferences)
.put(UnitDoubleKey.OverviewVeryLowMark, preferences)
.put(UnitDoubleKey.OverviewLowMark, preferences)
.put(UnitDoubleKey.OverviewHighMark, preferences)
.put(UnitDoubleKey.OverviewVeryHighMark, preferences)
.put(IntKey.OverviewCageWarning, preferences)
.put(IntKey.OverviewCageCritical, preferences)
.put(IntKey.OverviewIageWarning, preferences)
Expand Down Expand Up @@ -178,8 +180,10 @@ class OverviewPlugin @Inject constructor(
.store(UnitDoubleKey.OverviewActivityTarget, preferences)
.store(IntKey.OverviewHypoDuration, preferences)
.store(UnitDoubleKey.OverviewHypoTarget, preferences)
.store(UnitDoubleKey.OverviewVeryLowMark, preferences)
.store(UnitDoubleKey.OverviewLowMark, preferences)
.store(UnitDoubleKey.OverviewHighMark, preferences)
.store(UnitDoubleKey.OverviewVeryHighMark, preferences)
.store(IntKey.OverviewCageWarning, preferences)
.store(IntKey.OverviewCageCritical, preferences)
.store(IntKey.OverviewIageWarning, preferences)
Expand Down Expand Up @@ -258,8 +262,10 @@ class OverviewPlugin @Inject constructor(
key = "range_settings"
summary = rh.gs(R.string.prefs_range_summary)
title = rh.gs(R.string.prefs_range_title)
addPreference(AdaptiveUnitPreference(ctx = context, unitKey = UnitDoubleKey.OverviewVeryLowMark, title = R.string.very_low_mark))
addPreference(AdaptiveUnitPreference(ctx = context, unitKey = UnitDoubleKey.OverviewLowMark, title = R.string.low_mark))
addPreference(AdaptiveUnitPreference(ctx = context, unitKey = UnitDoubleKey.OverviewHighMark, title = R.string.high_mark))
addPreference(AdaptiveUnitPreference(ctx = context, unitKey = UnitDoubleKey.OverviewVeryHighMark, title = R.string.very_high_mark))
})
addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewShortTabTitles, title = R.string.short_tabtitles))
addPreference(AdaptiveSwitchPreference(ctx = context, booleanKey = BooleanKey.OverviewShowNotesInDialogs, title = R.string.overview_show_notes_field_in_dialogs_title))
Expand Down
2 changes: 2 additions & 0 deletions plugins/main/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,10 @@
<string name="button3">Button 3</string>
<string name="prefs_range_title">Range for visualization</string>
<string name="prefs_range_summary">High and low mark for the charts in Overview and Smartwatch</string>
<string name="very_low_mark">VERY LOW mark</string>
<string name="low_mark">LOW mark</string>
<string name="high_mark">HIGH mark</string>
<string name="very_high_mark">VERY HIGH mark</string>
<string name="short_tabtitles">Shorten tab titles</string>
<string name="overview_show_notes_field_in_dialogs_title">Show notes field in treatment dialogs</string>
<string name="deliverpartofboluswizard">Bolus wizard performs calculation but only this part of calculated insulin is delivered. Useful with SMB algorithm.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ class TizenPlugin @Inject constructor(
bundle.putString("slopeArrow", lastBG.trendArrow.text) // direction arrow as string
bundle.putDouble("deltaMgdl", glucoseStatus.delta) // bg delta in mgdl
bundle.putDouble("avgDeltaMgdl", glucoseStatus.shortAvgDelta) // average bg delta
bundle.putDouble("veryHigh", preferences.get(UnitDoubleKey.OverviewVeryHighMark)) // predefined topmost value of in range (yellow area)
bundle.putDouble("high", preferences.get(UnitDoubleKey.OverviewHighMark)) // predefined top value of in range (green area)
bundle.putDouble("low", preferences.get(UnitDoubleKey.OverviewLowMark)) // predefined bottom value of in range
bundle.putDouble("veryLow", preferences.get(UnitDoubleKey.OverviewVeryLowMark)) // predefined very bottom value of in range
}

private fun iobCob(bundle: Bundle) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1331,8 +1331,10 @@ class DataHandlerMobile @Inject constructor(
timeStamp = bg.timestamp,
glucoseUnits = GlucoseUnit.MGDL.asText,
sgv = bg.value,
veryHigh = 0.0,
high = 0.0,
low = 0.0,
veryLow = 0.0,
color = predictionColor(context, bg)
)
)
Expand Down Expand Up @@ -1466,8 +1468,10 @@ class DataHandlerMobile @Inject constructor(
private fun getSingleBG(glucoseValue: InMemoryGlucoseValue): EventData.SingleBg {
val glucoseStatus = glucoseStatusProvider.getGlucoseStatusData(true)
val units = profileFunction.getUnits()
val veryLowLine = profileUtil.convertToMgdl(preferences.get(UnitDoubleKey.OverviewVeryLowMark), units)
val lowLine = profileUtil.convertToMgdl(preferences.get(UnitDoubleKey.OverviewLowMark), units)
val highLine = profileUtil.convertToMgdl(preferences.get(UnitDoubleKey.OverviewHighMark), units)
val veryHighLine = profileUtil.convertToMgdl(preferences.get(UnitDoubleKey.OverviewVeryHighMark), units)

return EventData.SingleBg(
dataset = 0,
Expand All @@ -1479,10 +1483,18 @@ class DataHandlerMobile @Inject constructor(
deltaDetailed = glucoseStatus?.let { deltaStringDetailed(it.delta, it.delta * Constants.MGDL_TO_MMOLL, units) } ?: "--",
avgDelta = glucoseStatus?.let { deltaString(it.shortAvgDelta, it.shortAvgDelta * Constants.MGDL_TO_MMOLL, units) } ?: "--",
avgDeltaDetailed = glucoseStatus?.let { deltaStringDetailed(it.shortAvgDelta, it.shortAvgDelta * Constants.MGDL_TO_MMOLL, units) } ?: "--",
sgvLevel = if (glucoseValue.recalculated > highLine) 1L else if (glucoseValue.recalculated < lowLine) -1L else 0L,
sgvLevel = when {
glucoseValue.recalculated > veryHighLine -> 2L
glucoseValue.recalculated > highLine -> 1L
glucoseValue.recalculated < veryLowLine -> -2L
glucoseValue.recalculated < lowLine -> -1L
else -> 0L
},
sgv = glucoseValue.recalculated,
veryHigh = veryHighLine,
high = highLine,
low = lowLine,
veryLow = veryLowLine,
color = 0,
deltaMgdl = glucoseStatus?.delta,
avgDeltaMgdl = glucoseStatus?.shortAvgDelta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ internal class TizenPluginTest : TestBaseWithProfile() {
assertThat(bundle.containsKey("slopeArrow")).isTrue()
assertThat(bundle.containsKey("deltaMgdl")).isTrue()
assertThat(bundle.containsKey("avgDeltaMgdl")).isTrue()
assertThat(bundle.containsKey("veryHigh")).isTrue()
assertThat(bundle.containsKey("high")).isTrue()
assertThat(bundle.containsKey("low")).isTrue()
assertThat(bundle.containsKey("veryLow")).isTrue()
assertThat(bundle.containsKey("bolusIob")).isTrue()
assertThat(bundle.containsKey("basalIob")).isTrue()
assertThat(bundle.containsKey("iob")).isTrue()
Expand Down
Loading