From b38cb58338752473df4c7b3cc22eb46d40a503ae Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 21 Sep 2022 16:42:07 +0200 Subject: [PATCH] NSC: show variable sensitivity --- .../general/nsclient/data/NSDeviceStatus.kt | 2 ++ .../general/overview/OverviewFragment.kt | 35 ++++++++++--------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt index 88bbbce04c..7a42d9efdd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/nsclient/data/NSDeviceStatus.kt @@ -54,6 +54,8 @@ import javax.inject.Singleton "predBGs": { "IOB": [116, 114, 112, 110, 109, 107, 106, 105, 105, 104, 104, 104, 104, 104, 104, 104, 104, 105, 105, 105, 105, 105, 106, 106, 106, 106, 106, 107] }, + "sensitivityRatio": 0.81, + "variable_sens": 137.3, "COB": 0, "IOB": -0.035, "reason": "COB: 0, Dev: -18, BGI: 0.43, ISF: 216, Target: 99; Eventual BG 105 > 99 but Min. Delta -2.60 < Exp. Delta 0.1; setting current basal of 0.4 as temp. Suggested rate is same as profile rate, no temp basal is active, doing nothing", diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt index 8df6ec5512..139e51f67d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/overview/OverviewFragment.kt @@ -67,6 +67,7 @@ import info.nightscout.androidaps.skins.SkinProvider import info.nightscout.androidaps.utils.DateUtil import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.utils.FabricPrivacy +import info.nightscout.androidaps.utils.JsonHelper import info.nightscout.androidaps.utils.ToastUtils import info.nightscout.androidaps.utils.TrendCalculator import info.nightscout.androidaps.utils.alertDialogs.OKDialog @@ -602,7 +603,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList private fun processAps() { val pump = activePlugin.activePump - val profile = profileFunction.getProfile() // aps mode val closedLoopEnabled = constraintChecker.isClosedLoopAllowed() @@ -681,21 +681,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList binding.infoLayout.apsModeText.visibility = View.GONE } } - // Show variable sensitivity - val request = loop.lastRun?.request - if (request is DetermineBasalResultSMB) { - val isfMgdl = profile?.getIsfMgdl() - val variableSens = request.variableSens - if (variableSens != isfMgdl && variableSens != null && isfMgdl != null) { - binding.infoLayout.variableSensitivity.text = - String.format( - Locale.getDefault(), "%1$.1f→%2$.1f", - Profile.toUnits(isfMgdl, isfMgdl * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()), - Profile.toUnits(variableSens, variableSens * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) - ) - binding.infoLayout.variableSensitivity.visibility = View.VISIBLE - } else binding.infoLayout.variableSensitivity.visibility = View.GONE - } else binding.infoLayout.variableSensitivity.visibility = View.GONE } else { //nsclient binding.infoLayout.apsMode.visibility = View.GONE @@ -1094,6 +1079,24 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overviewData.lastAutosensData(iobCobCalculator)?.let { autosensData -> String.format(Locale.ENGLISH, "%.0f%%", autosensData.autosensResult.ratio * 100) } ?: "" + // Show variable sensitivity + val profile = profileFunction.getProfile() + val request = loop.lastRun?.request + val isfMgdl = profile?.getIsfMgdl() + val variableSens = + if (config.APS && request is DetermineBasalResultSMB) request.variableSens ?: 0.0 + else if (config.NSCLIENT) JsonHelper.safeGetDouble(nsDeviceStatus.getAPSResult(injector).json, "variable_sens") + else 0.0 + + if (variableSens != isfMgdl && variableSens != 0.0 && isfMgdl != null) { + binding.infoLayout.variableSensitivity.text = + String.format( + Locale.getDefault(), "%1$.1f→%2$.1f", + Profile.toUnits(isfMgdl, isfMgdl * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()), + Profile.toUnits(variableSens, variableSens * Constants.MGDL_TO_MMOLL, profileFunction.getUnits()) + ) + binding.infoLayout.variableSensitivity.visibility = View.VISIBLE + } else binding.infoLayout.variableSensitivity.visibility = View.GONE } private fun updatePumpStatus() {