Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -418,11 +418,13 @@
}
}

private suspend fun doMigrations() {

Check failure on line 421 in app/src/main/kotlin/app/aaps/MainApp.kt

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 91 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=nightscout_AndroidAPS&issues=AZ3KmTE0IpdPHrNPiAnf&open=AZ3KmTE0IpdPHrNPiAnf&pullRequest=4768
// set values for different builds
// 3.3
if (preferences.get(UnitDoubleKey.OverviewLowMark) == 0.0) preferences.remove(UnitDoubleKey.OverviewLowMark)
if (preferences.get(UnitDoubleKey.OverviewVeryLowMark) == 0.0) preferences.remove(UnitDoubleKey.OverviewVeryLowMark)
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(BooleanNonKey.GeneralSetupWizardProcessed))
// Migrate from OpenAPSSMBDynamicISFPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,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 @@ -32,6 +39,13 @@ interface LastBgData {
*/
fun isHigh(): Boolean

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

/**
* Description for a11y
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import app.aaps.core.data.model.TrendArrow
*/
enum class BgRange {

VERY_HIGH, // Above very high mark
HIGH, // Above high mark
IN_RANGE, // Within target range
LOW // Below low mark
LOW, // Below low mark
VERY_LOW // Below very low mark
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,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 @@ -21,8 +21,10 @@ enum class UnitDoubleKey(
override val exportable: Boolean = true
) : UnitDoublePreferenceKey {

OverviewVeryLowMark(key = "very_low_mark", defaultValue = 72.0, minMgdl = 25, maxMgdl =100, titleResId = R.string.pref_title_very_low_mark, showInNsClientMode = false),
OverviewLowMark(key = "low_mark", defaultValue = 72.0, minMgdl = 25, maxMgdl = 160, titleResId = R.string.pref_title_low_mark, showInNsClientMode = false, hideParentScreenIfHidden = true),
OverviewHighMark(key = "high_mark", defaultValue = 180.0, minMgdl = 90, maxMgdl = 250, titleResId = R.string.pref_title_high_mark, showInNsClientMode = false),
OverviewVeryHighMark(key = "very_high_mark", defaultValue = 401.0, minMgdl =180, maxMgdl = 401, titleResId = R.string.pref_title_very_high_mark, showInNsClientMode = false),
ApsLgsThreshold(
key = "lgsThreshold",
defaultValue = 65.0,
Expand Down
2 changes: 2 additions & 0 deletions core/keys/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,10 @@
<string name="openapsama_smb_max_range_extension_summary">Default value: 1 This is another key OpenAPS safety cap, and specifies by what factor you can exceed the regular 120 maxSMB/maxUAM minutes. Increase this experimental value slowly and with caution.</string>

<!-- UnitDoubleKey: Overview preferences -->
<string name="pref_title_very_low_mark">Very Low BG mark</string>
<string name="pref_title_low_mark">Low BG mark</string>
<string name="pref_title_high_mark">High BG mark</string>
<string name="pref_title_very_high_mark">Very High BG mark</string>

<!-- UnitDoubleKey: APS preferences -->
<string name="pref_title_lgs_threshold">LGS threshold</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ val LightGeneralColors = GeneralColors(
bgInRange = Color(0xFF00FF00), // pure green for in-range BG (matches @color/inRange)
bgLow = Color(0xFFFF0000), // pure red for low BG (matches @color/low)
bgVeryLow = Color(0xFF8B0000), // dark red for very low BG (Dexcom TIR 5-range)
bgVeryHigh = Color(0xFFD84315), // deep orange-red for very high BG (Dexcom TIR 5-range)
bgVeryHigh = Color(0xFFFF0000), // red for very high BG (Dexcom TIR 5-range)
bgTargetRangeArea = Color(0x2800FF00), // green with ~16% alpha for target range area (matches @color/inRangeBackground)
originalBgValue = Color(0xFFFFFFFF), // white for regular CGM readings (matches originalBgValueColor attr)
iobPrediction = Color(0xFF1E88E5), // blue for IOB predictions (matches iobColor attr)
Expand Down Expand Up @@ -189,7 +189,7 @@ val DarkGeneralColors = GeneralColors(
bgInRange = Color(0xFF00FF00), // pure green for in-range BG (matches @color/inRange - same in both modes)
bgLow = Color(0xFFFF0000), // pure red for low BG (matches @color/low - same in both modes)
bgVeryLow = Color(0xFFB71C1C), // dark red for very low BG (dark mode, Dexcom TIR 5-range)
bgVeryHigh = Color(0xFFFB8C00), // orange for very high BG (dark mode, differentiates from yellow bgHigh)
bgVeryHigh = Color(0xFFFF0000), // red for very high BG (dark mode, differentiates from yellow bgHigh)
bgTargetRangeArea = Color(0x4000FF00), // green with ~25% alpha for target range area (matches @color/inRangeBackground in values-night)
originalBgValue = Color(0xFFFFFFFF), // white for regular CGM readings (same in both modes)
iobPrediction = Color(0xFF64B5F6), // lighter blue for IOB predictions (dark mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import app.aaps.core.ui.compose.dialogs.ValueInputDialog
import app.aaps.core.ui.compose.formatSliderDisplayValue
import java.text.DecimalFormat

private const val MAX_SLIDER_STEPS = 200.0
private const val MAX_SLIDER_STEPS = 260.0

/**
* Preference-row variant of [SliderWithButtons]. Forwards to [SliderWithButtons] when the
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 @@ -29,7 +29,9 @@

<!-- Widget runtime has no dark mode; these are always read from the default colors.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>

</resources>
2 changes: 2 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,10 @@
<string name="a11y_arrow_double_up">rising rapidly</string>
<string name="a11y_arrow_none">none</string>
<string name="a11y_arrow_unknown">unknown</string>
<string name="a11y_very_high">very high</string>
<string name="a11y_high">high</string>
<string name="a11y_inrange">in range</string>
<string name="a11y_very_low">very low</string>
<string name="a11y_low">low</string>
<string name="remove_label">Remove</string>
<string name="activate_profile">Activate profile</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ class LastBgDataImpl @Inject constructor(
iobCobCalculator.ads.bucketedData?.firstOrNull()
?: runBlocking { 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 @@ -40,9 +45,16 @@ 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

override fun lastBgDescription(): String =
when {
isVeryLow() -> rh.gs(app.aaps.core.ui.R.string.a11y_very_low)
isLow() -> rh.gs(app.aaps.core.ui.R.string.a11y_low)
isVeryHigh() -> rh.gs(app.aaps.core.ui.R.string.a11y_very_high)
isHigh() -> rh.gs(app.aaps.core.ui.R.string.a11y_high)
else -> rh.gs(app.aaps.core.ui.R.string.a11y_inrange)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ class SWDefinition @Inject constructor(
private val displaySettings
get() = swScreenProvider.get().with(R.string.display_settings)
.skippable(false)
.add(
swEditNumberWithUnitsProvider.get()
.preference(UnitDoubleKey.OverviewVeryLowMark)
.updateDelay(5)
.label(R.string.very_low_mark)
.comment(R.string.very_low_mark_comment)
)
.add(swBreakProvider.get())
.add(
swEditNumberWithUnitsProvider.get()
.preference(UnitDoubleKey.OverviewLowMark)
Expand All @@ -173,6 +181,14 @@ class SWDefinition @Inject constructor(
.label(R.string.high_mark)
.comment(R.string.high_mark_comment)
)
.add(swBreakProvider.get())
.add(
swEditNumberWithUnitsProvider.get()
.preference(UnitDoubleKey.OverviewVeryHighMark)
.updateDelay(5)
.label(R.string.very_high_mark)
.comment(R.string.very_high_mark_comment)
)

private val screenPermissions
get() = swScreenProvider.get().with(R.string.setupwizard_permissions)
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 @@ -11,10 +11,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="storedsettingsfound">Stored settings found</string>
<string name="master_password_summary">Master password is used for backup encryption and to override security in application. Remember it or store on a safe place.</string>
<!-- current_master_password moved to core/ui/protection.xml -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,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 @@ -1600,13 +1600,15 @@ class DataHandlerMobile @Inject constructor(
// Hoist out of the per-bucket map: getGlucoseStatusData copies the bucketed table and runs a polynomial fit on every call.
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)
val slopeArrow = (trendCalculator.getTrendArrow(iobCobCalculator.ads) ?: TrendArrow.NONE).symbol
rxBus.send(
EventMobileToWear(
EventData.GraphData(
ArrayList(bucketedData.map { buildSingleBg(it, glucoseStatus, units, lowLine, highLine, slopeArrow) })
ArrayList(bucketedData.map { buildSingleBg(it, glucoseStatus, units, veryLowLine, lowLine, highLine, veryHighLine, slopeArrow) })
)
)
)
Expand Down Expand Up @@ -1791,8 +1793,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(bg)
)
)
Expand Down Expand Up @@ -1933,18 +1937,22 @@ 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)
val slopeArrow = (trendCalculator.getTrendArrow(iobCobCalculator.ads) ?: TrendArrow.NONE).symbol
return buildSingleBg(glucoseValue, glucoseStatus, units, lowLine, highLine, slopeArrow)
return buildSingleBg(glucoseValue, glucoseStatus, units, veryLowLine, lowLine, highLine, veryHighLine, slopeArrow)
}

private fun buildSingleBg(
glucoseValue: InMemoryGlucoseValue,
glucoseStatus: GlucoseStatus?,
units: GlucoseUnit,
veryLowLine: Double,
lowLine: Double,
highLine: Double,
veryHighLine: Double,
slopeArrow: String
): EventData.SingleBg =
EventData.SingleBg(
Expand All @@ -1957,10 +1965,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 @@ -94,8 +94,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
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package app.aaps.shared.impl.weardata
enum class JsonKeys(val key: String) {
METADATA("metadata"),
ENABLESECOND("enableSecond"),
VERYHIGHCOLOR("veryhighColor"),
HIGHCOLOR("highColor"),
MIDCOLOR("midColor"),
LOWCOLOR("lowColor"),
VERYLOWCOLOR("veryLowColor"),
LOWBATCOLOR("lowBatColor"),
CARBCOLOR("carbColor"),
BASALBACKGROUNDCOLOR("basalBackgroundColor"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ private fun Separator() {

@Composable
private fun BgRange.toColor() = when (this) {
BgRange.HIGH -> AapsTheme.generalColors.bgHigh
BgRange.IN_RANGE -> AapsTheme.generalColors.bgInRange
BgRange.LOW -> AapsTheme.generalColors.bgLow
BgRange.VERY_HIGH -> AapsTheme.generalColors.bgVeryHigh
BgRange.HIGH -> AapsTheme.generalColors.bgHigh
BgRange.IN_RANGE -> AapsTheme.generalColors.bgInRange
BgRange.LOW -> AapsTheme.generalColors.bgLow
BgRange.VERY_LOW -> AapsTheme.generalColors.bgVeryLow
}
Loading