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

Overview add Sensitivity OKDialog #3580

Merged
merged 8 commits into from
Jan 7, 2025
Merged
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
9 changes: 9 additions & 0 deletions _docs/icons/as_above.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions _docs/icons/as_below.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions _docs/icons/x_as_above.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions _docs/icons/x_as_below.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ interface APS : ConfigExportImport {
*/
fun supportsDynamicIc(): Boolean = false

/**
* Dedicated string for Sensitivity OKDialog in overview on ISF calculation ?
* @return string or null if nothing to show
*/
fun getSensitivityOverviewString(): String? = null

/**
* Calculate current ISF
* @param profile Actual profile to get multiplier form [ProfileSealed.EPS]
Expand Down
9 changes: 9 additions & 0 deletions core/objects/src/main/res/drawable/ic_as_above.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="48dp"
android:width="48dp"
android:viewportHeight="24"
android:viewportWidth="24">

<path android:fillColor="#008585" android:pathData="M12,5.654l-4.615,4.604h3.461v8.088h2.308v-8.088h3.461L12,5.654z"/>

</vector>
9 changes: 9 additions & 0 deletions core/objects/src/main/res/drawable/ic_as_below.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="48dp"
android:width="48dp"
android:viewportHeight="24"
android:viewportWidth="24">

<path android:fillColor="#008585" android:pathData="M13.154,13.742V5.654h-2.308v8.088H7.385L12,18.346l4.615,-4.604H13.154z"/>

</vector>
13 changes: 13 additions & 0 deletions core/objects/src/main/res/drawable/ic_x_as_above.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="48dp"
android:width="48dp"
android:viewportHeight="24"
android:viewportWidth="24">

<path android:fillColor="#008585" android:pathData="M15.375,6.5l-4,3.99h3v7.01h2v-7.01h3L15.375,6.5z"/>

<path android:fillColor="#008585" android:pathData="M2.756,15.271c-0.128,0 -0.256,-0.049 -0.354,-0.146c-0.195,-0.195 -0.195,-0.512 0,-0.707l5.514,-5.515c0.196,-0.195 0.512,-0.196 0.708,0c0.195,0.195 0.195,0.512 0,0.708L3.11,15.124C3.012,15.222 2.884,15.271 2.756,15.271z"/>

<path android:fillColor="#008585" android:pathData="M8.271,15.271c-0.128,0 -0.256,-0.049 -0.354,-0.146L2.403,9.61c-0.196,-0.196 -0.196,-0.512 0,-0.708c0.195,-0.196 0.512,-0.196 0.708,0l5.514,5.515c0.196,0.195 0.196,0.512 0,0.707C8.527,15.222 8.399,15.271 8.271,15.271z"/>

</vector>
13 changes: 13 additions & 0 deletions core/objects/src/main/res/drawable/ic_x_as_below.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="48dp"
android:width="48dp"
android:viewportHeight="24"
android:viewportWidth="24">

<path android:fillColor="#008585" android:pathData="M16.375,13.51V6.5h-2v7.01h-3l4,3.99l4,-3.99H16.375z"/>

<path android:fillColor="#008585" android:pathData="M2.756,15.271c-0.128,0 -0.256,-0.049 -0.354,-0.146c-0.195,-0.195 -0.195,-0.512 0,-0.707l5.514,-5.515c0.196,-0.195 0.512,-0.196 0.708,0c0.195,0.195 0.195,0.512 0,0.708L3.11,15.124C3.012,15.222 2.884,15.271 2.756,15.271z"/>

<path android:fillColor="#008585" android:pathData="M8.271,15.271c-0.128,0 -0.256,-0.049 -0.354,-0.146L2.403,9.61c-0.196,-0.196 -0.196,-0.512 0,-0.708c0.195,-0.196 0.512,-0.196 0.708,0l5.514,5.515c0.196,0.195 0.196,0.512 0,0.707C8.527,15.222 8.399,15.271 8.271,15.271z"/>

</vector>
6 changes: 6 additions & 0 deletions core/ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@
<string name="formatPercent">%1$.0f%%</string>
<string name="basal">Basal</string>
<string name="basalpct">Basal %</string>
<string name="sensitivity">Sensitivity</string>
<string name="isf_for_carbs">ISF for Calculator and Carbs Absorption: %1$.1f</string>
<string name="autosens_long">Autosens Value: %.0f%%</string>
<string name="autosens_short">AS: %.0f%%</string>
<string name="algorithm_long">Autosens in algorithm: %.0f%%</string>
<string name="algorithm_short">Alg: %.0f%%</string>
<string name="a11y_file">file</string>
<string name="a11y_user">user</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ open class OpenAPSAutoISFPlugin @Inject constructor(
return sensitivity
}

override fun getSensitivityOverviewString(): String? = null // placeholder for Auto ISF Detailed information for overview

override fun specialEnableCondition(): Boolean {
return config.isEngineeringMode() && config.isDev() &&
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import app.aaps.core.interfaces.utils.DecimalFormatter
import app.aaps.core.interfaces.utils.TrendCalculator
import app.aaps.core.interfaces.utils.fabric.FabricPrivacy
import app.aaps.core.keys.BooleanKey
import app.aaps.core.keys.DoubleKey
import app.aaps.core.keys.Preferences
import app.aaps.core.keys.UnitDoubleKey
import app.aaps.core.objects.constraints.ConstraintObject
Expand Down Expand Up @@ -1133,18 +1134,34 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
private fun updateSensitivity() {
_binding ?: return
val lastAutosensData = iobCobCalculator.ads.getLastAutosensData("Overview", aapsLogger, dateUtil)
val lastAutosensRatio = lastAutosensData?.let { it.autosensResult.ratio * 100 }
if (config.AAPSCLIENT && sp.getBoolean(app.aaps.core.utils.R.string.key_used_autosens_on_main_phone, false) ||
!config.AAPSCLIENT && constraintChecker.isAutosensModeEnabled().value()
) {
binding.infoLayout.sensitivityIcon.setImageResource(app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green)
binding.infoLayout.sensitivityIcon.setImageResource(
lastAutosensRatio?.let {
when {
it > 100.0 -> app.aaps.core.objects.R.drawable.ic_as_above
it < 100.0 -> app.aaps.core.objects.R.drawable.ic_as_below
else -> app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
}
}
?: app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
)
} else {
binding.infoLayout.sensitivityIcon.setImageResource(app.aaps.core.objects.R.drawable.ic_x_swap_vert)
binding.infoLayout.sensitivityIcon.setImageResource(
lastAutosensRatio?.let {
when {
it > 100.0 -> app.aaps.core.objects.R.drawable.ic_x_as_above
it < 100.0 -> app.aaps.core.objects.R.drawable.ic_x_as_below
else -> app.aaps.core.objects.R.drawable.ic_x_swap_vert
}
}
?: app.aaps.core.objects.R.drawable.ic_x_swap_vert
)
}

binding.infoLayout.sensitivity.text =
lastAutosensData?.let {
String.format(Locale.ENGLISH, "AS: %.0f%%", it.autosensResult.ratio * 100)
} ?: ""

// Show variable sensitivity
val profile = profileFunction.getProfile()
val request = loop.lastRun?.request
Expand All @@ -1157,16 +1174,45 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList
val ratioUsed = request?.autosensResult?.ratio ?: 1.0

if (variableSens != isfMgdl && variableSens != 0.0 && isfMgdl != null) {
var text = if (ratioUsed != 1.0 && ratioUsed != lastAutosensData?.autosensResult?.ratio) String.format(Locale.getDefault(), "Alg: %.0f%%\n", ratioUsed * 100) else ""
text += String.format(
Locale.getDefault(), "%1$.1f→%2$.1f (%3$.1f)",
profileUtil.fromMgdlToUnits(isfMgdl, profileFunction.getUnits()),
profileUtil.fromMgdlToUnits(variableSens, profileFunction.getUnits()),
profileUtil.fromMgdlToUnits(isfForCarbs ?: 0.0, profileFunction.getUnits())
val okDialogText: ArrayList<String> = ArrayList()
val overViewText: ArrayList<String> = ArrayList()
val autoSensHiddenRange = 0.0 //Hide Autosens value if equals 100%
val autoSensMax = 100.0 + (preferences.get(DoubleKey.AutosensMax) - 1.0) * autoSensHiddenRange * 100.0
val autoSensMin = 100.0 + (preferences.get(DoubleKey.AutosensMin) - 1.0) * autoSensHiddenRange * 100.0
lastAutosensRatio?.let {
if(it < autoSensMin || it > autoSensMax)
overViewText.add(rh.gs(app.aaps.core.ui.R.string.autosens_short, it))
okDialogText.add(rh.gs(app.aaps.core.ui.R.string.autosens_long, it))
}
overViewText.add(
String.format(
Locale.getDefault(), "%1$.1f→%2$.1f",
profileUtil.fromMgdlToUnits(isfMgdl, profileFunction.getUnits()),
profileUtil.fromMgdlToUnits(variableSens, profileFunction.getUnits())
)
)
binding.infoLayout.variableSensitivity.text = text
binding.infoLayout.variableSensitivity.visibility = View.VISIBLE
} else binding.infoLayout.variableSensitivity.visibility = View.GONE
binding.infoLayout.sensitivity.text = overViewText.joinToString("\n")
binding.infoLayout.sensitivity.visibility = View.VISIBLE
binding.infoLayout.variableSensitivity.visibility = View.GONE
if (ratioUsed != 1.0 && ratioUsed != lastAutosensData?.autosensResult?.ratio)
okDialogText.add(rh.gs(app.aaps.core.ui.R.string.algorithm_long, ratioUsed * 100))
okDialogText.add(rh.gs(app.aaps.core.ui.R.string.isf_for_carbs, profileUtil.fromMgdlToUnits(isfForCarbs ?: 0.0, profileFunction.getUnits())))
if (config.APS) {
val aps = activePlugin.activeAPS
aps.getSensitivityOverviewString()?.let {
okDialogText.add("$it")
}
}
binding.infoLayout.asLayout.setOnClickListener { activity?.let { OKDialog.show(it, rh.gs(app.aaps.core.ui.R.string.sensitivity), okDialogText.joinToString("\n")) } }

} else {
binding.infoLayout.sensitivity.text =
lastAutosensData?.let {
rh.gs(app.aaps.core.ui.R.string.autosens_short,it.autosensResult.ratio * 100)
} ?: ""
binding.infoLayout.variableSensitivity.visibility = View.GONE
binding.infoLayout.sensitivity.visibility = View.VISIBLE
}
}

private fun updatePumpStatus() {
Expand Down
44 changes: 35 additions & 9 deletions ui/src/main/kotlin/app/aaps/ui/widget/Widget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ import app.aaps.core.interfaces.ui.UiInteraction
import app.aaps.core.interfaces.utils.DateUtil
import app.aaps.core.interfaces.utils.DecimalFormatter
import app.aaps.core.interfaces.utils.TrendCalculator
import app.aaps.core.keys.DoubleKey
import app.aaps.core.objects.extensions.directionToIcon
import app.aaps.core.objects.extensions.displayText
import app.aaps.core.objects.extensions.round
import app.aaps.core.objects.profile.ProfileSealed
import app.aaps.core.ui.dialogs.OKDialog
import app.aaps.core.ui.extensions.toVisibility
import app.aaps.core.ui.extensions.toVisibilityKeepSpace
import app.aaps.ui.R
Expand Down Expand Up @@ -279,12 +281,33 @@ class Widget : AppWidgetProvider() {

private fun updateSensitivity(views: RemoteViews) {
val lastAutosensData = iobCobCalculator.ads.getLastAutosensData("Widget", aapsLogger, dateUtil)
val lastAutosensRatio = lastAutosensData?.let { it.autosensResult.ratio * 100 }
if (constraintChecker.isAutosensModeEnabled().value())
views.setImageViewResource(R.id.sensitivity_icon, app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green)
views.setImageViewResource(
R.id.sensitivity_icon,
lastAutosensRatio?.let {
when {
it > 100.0 -> app.aaps.core.objects.R.drawable.ic_as_above
it < 100.0 -> app.aaps.core.objects.R.drawable.ic_as_below
else -> app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
}
}
?: app.aaps.core.objects.R.drawable.ic_swap_vert_black_48dp_green
)
else
views.setImageViewResource(R.id.sensitivity_icon, app.aaps.core.objects.R.drawable.ic_x_swap_vert)
views.setImageViewResource(
R.id.sensitivity_icon,
lastAutosensRatio?.let {
when {
it > 100.0 -> app.aaps.core.objects.R.drawable.ic_x_as_above
it < 100.0 -> app.aaps.core.objects.R.drawable.ic_x_as_below
else -> app.aaps.core.objects.R.drawable.ic_x_swap_vert
}
}
?: app.aaps.core.objects.R.drawable.ic_x_swap_vert
)
views.setTextViewText(R.id.sensitivity, lastAutosensData?.let {
String.format(Locale.ENGLISH, "%.0f%%", it.autosensResult.ratio * 100)
rh.gs(app.aaps.core.ui.R.string.autosens_short, it.autosensResult.ratio * 100)
} ?: "")

// Show variable sensitivity
Expand All @@ -296,13 +319,16 @@ class Widget : AppWidgetProvider() {
else 0.0
val ratioUsed = request?.autosensResult?.ratio ?: 1.0
if (variableSens != isfMgdl && variableSens != 0.0 && isfMgdl != null) {
var text = if (ratioUsed != 1.0 && ratioUsed != lastAutosensData?.autosensResult?.ratio) String.format(Locale.getDefault(), "%.0f%%\n", ratioUsed * 100) else ""
text += String.format(
Locale.getDefault(), "%1$.1f→%2$.1f",
profileUtil.fromMgdlToUnits(isfMgdl, profileFunction.getUnits()),
profileUtil.fromMgdlToUnits(variableSens, profileFunction.getUnits())
val overViewText: ArrayList<String> = ArrayList()
if (ratioUsed != 1.0 && ratioUsed != lastAutosensData?.autosensResult?.ratio) overViewText.add(rh.gs(app.aaps.core.ui.R.string.algorithm_short,ratioUsed * 100))
overViewText.add(
String.format(
Locale.getDefault(), "%1$.1f→%2$.1f",
profileUtil.fromMgdlToUnits(isfMgdl, profileFunction.getUnits()),
profileUtil.fromMgdlToUnits(variableSens, profileFunction.getUnits())
)
)
views.setTextViewText(R.id.variable_sensitivity, text)
views.setTextViewText(R.id.variable_sensitivity, overViewText.joinToString("\n"))
views.setViewVisibility(R.id.variable_sensitivity, View.VISIBLE)
} else views.setViewVisibility(R.id.variable_sensitivity, View.GONE)
}
Expand Down