From 9fc84dbeebedd9afece8cb975507d34191de0f5d Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:09:31 +1200 Subject: [PATCH 1/8] Add required functions --- .../info/nightscout/androidaps/data/Profile.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/main/java/info/nightscout/androidaps/data/Profile.java b/core/src/main/java/info/nightscout/androidaps/data/Profile.java index 4aaa5848fb..972730ca3d 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/core/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -523,13 +523,28 @@ public class Profile { return ret; } + public double getTargetUnits() { + if (units.equals(Constants.MGDL)) { + return getTargetMgdl(secondsFromMidnight()); + } else { + return getTargetMmol(secondsFromMidnight()); + } + } + public double getTargetMgdl() { return getTargetMgdl(secondsFromMidnight()); } + public double getTargetMmol() { + return getTargetMmol(secondsFromMidnight()); + } + public double getTargetMgdl(int timeAsSeconds) { return toMgdl((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); } + public double getTargetMmol(int timeAsSeconds) { + return toMmol((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); + } public double getTargetLowMgdl() { return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight()), units); From 3c2d5ff3d6d67676a7a6fef22268be1609be51be Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:10:16 +1200 Subject: [PATCH 2/8] Add targetBG --- app/src/main/assets/OpenAPSSMB/determine-basal.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/OpenAPSSMB/determine-basal.js b/app/src/main/assets/OpenAPSSMB/determine-basal.js index 00a9c1d0a2..fbc0a4de9f 100644 --- a/app/src/main/assets/OpenAPSSMB/determine-basal.js +++ b/app/src/main/assets/OpenAPSSMB/determine-basal.js @@ -407,6 +407,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_ , 'bg': bg , 'tick': tick , 'eventualBG': eventualBG + , 'targetBG': target_bg , 'insulinReq': 0 , 'reservoir' : reservoir_data // The expected reservoir volume at which to deliver the microbolus (the reservoir volume from right before the last pumphistory run) , 'deliverAt' : deliverAt // The time at which the microbolus should be delivered From a20008c0dbb6035c025808257ad80fdd9bfed83c Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:10:51 +1200 Subject: [PATCH 3/8] Add TargetBG --- .../plugins/aps/openAPSSMB/DetermineBasalResultSMB.java | 3 +++ .../info/nightscout/androidaps/plugins/aps/loop/APSResult.java | 2 ++ 2 files changed, 5 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java index dae170d5d9..f8f72c6c87 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/aps/openAPSSMB/DetermineBasalResultSMB.java @@ -51,6 +51,9 @@ public class DetermineBasalResultSMB extends APSResult { } else { smb = 0d; } + if (result.has("targetBG")) { + targetBG = result.getDouble("targetBG"); + } if (result.has("deliverAt")) { String date = result.getString("deliverAt"); diff --git a/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java b/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java index 84ab8e5661..359ed88560 100644 --- a/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java +++ b/core/src/main/java/info/nightscout/androidaps/plugins/aps/loop/APSResult.java @@ -62,6 +62,7 @@ public class APSResult { public boolean hasPredictions = false; public double smb = 0d; // super micro bolus in units public long deliverAt = 0; + public double targetBG = 0d; public Constraint inputConstraints; @@ -184,6 +185,7 @@ public class APSResult { newResult.smbConstraint = smbConstraint; newResult.percent = percent; newResult.usePercent = usePercent; + newResult.targetBG = targetBG; } From 77a5af75e22f5115b637404606057b926361a16c Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 00:11:36 +1200 Subject: [PATCH 4/8] Display when Target BG is overidden --- .../general/overview/OverviewFragment.kt | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) 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 93c112f745..d3038090b6 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 @@ -646,6 +646,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } else { overview_apsmode_text?.visibility = View.GONE } + val lastRun = loopPlugin.lastRun // temp target val tempTarget = treatmentsPlugin.tempTargetFromHistory @@ -654,9 +655,27 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_temptarget?.text = Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end(), resourceHelper) } else { - overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) - overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) - overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) + //If the target is not the same as set in the profile then oref has overridden it + //show this change to the user if it exists + if (lastRun != null){ + var targetused = lastRun!!.constraintsProcessed!!.targetBG + if (units == Constants.MMOL) + targetused *= Constants.MGDL_TO_MMOLL + + if (profile.targetUnits != targetused) { + overview_temptarget?.text = targetused.toString() + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) + }else{ + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) + overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) + } + }else { + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) + overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) + } } // Basal, TBR @@ -741,7 +760,6 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } overview_cob?.text = cobText - val lastRun = loopPlugin.lastRun val predictionsAvailable = if (config.APS) lastRun?.request?.hasPredictions == true else config.NSCLIENT // pump status from ns From 723c0292289ee4c441ec5d9b94ac245cdb57ef1a Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 02:20:38 +1200 Subject: [PATCH 5/8] Deal with 0.0 if AMA is used --- .../plugins/general/overview/OverviewFragment.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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 d3038090b6..547dc3d85b 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 @@ -657,8 +657,8 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } else { //If the target is not the same as set in the profile then oref has overridden it //show this change to the user if it exists - if (lastRun != null){ - var targetused = lastRun!!.constraintsProcessed!!.targetBG + var targetused = lastRun?.constraintsProcessed?.targetBG + if (targetused != null && targetused != 0.0) { if (units == Constants.MMOL) targetused *= Constants.MGDL_TO_MMOLL @@ -666,12 +666,12 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_temptarget?.text = targetused.toString() overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) - }else{ + } else { overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) } - }else { + } else { overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) @@ -696,7 +696,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList if (activeTemp != null) overview_basebasal_icon.setImageResource(if (activeTemp.tempBasalConvertedToPercent(System.currentTimeMillis(), profile) > 100) R.drawable.icon_cp_basal_tbr_high else R.drawable.icon_cp_basal_tbr_low) else - overview_basebasal_icon.setImageResource( R.drawable.icon_cp_basal_no_tbr ) + overview_basebasal_icon.setImageResource(R.drawable.icon_cp_basal_no_tbr) // Extended bolus val extendedBolus = treatmentsPlugin.getExtendedBolusFromHistory(System.currentTimeMillis()) @@ -777,7 +777,7 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList // Sensitivity if (sp.getBoolean(R.string.key_openapsama_useautosens, false) && constraintChecker.isAutosensModeEnabled().value()) { overview_sensitivity_icon.setImageResource(R.drawable.ic_swap_vert_black_48dp_green) - }else { + } else { overview_sensitivity_icon.setImageResource(R.drawable.ic_x_swap_vert_48px_green) } From bf412ea798c85488fe28d62c7b69a312f3fae2a6 Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 04:19:22 +1200 Subject: [PATCH 6/8] refractor --- .../androidaps/plugins/general/overview/OverviewFragment.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 547dc3d85b..3891ba6b7e 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 @@ -659,11 +659,9 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList //show this change to the user if it exists var targetused = lastRun?.constraintsProcessed?.targetBG if (targetused != null && targetused != 0.0) { - if (units == Constants.MMOL) - targetused *= Constants.MGDL_TO_MMOLL - if (profile.targetUnits != targetused) { - overview_temptarget?.text = targetused.toString() + if (((profile.targetLowMgdl+profile.targetHighMgdl)/2)!= targetused) { + overview_temptarget?.text = Profile.toTargetRangeString(targetused, targetused, Constants.MGDL, units) overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) } else { From 06e97400f7fe07ddfbe327c0cef93316c0826d8f Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Wed, 20 May 2020 22:34:09 +0200 Subject: [PATCH 7/8] Simplify show-targets view logic --- .../general/overview/OverviewFragment.kt | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) 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 3891ba6b7e..c9ea872345 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 @@ -655,20 +655,13 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonWarning)) overview_temptarget?.text = Profile.toTargetRangeString(tempTarget.low, tempTarget.high, Constants.MGDL, units) + " " + DateUtil.untilString(tempTarget.end(), resourceHelper) } else { - //If the target is not the same as set in the profile then oref has overridden it - //show this change to the user if it exists - var targetused = lastRun?.constraintsProcessed?.targetBG - if (targetused != null && targetused != 0.0) { + // If the target is not the same as set in the profile then oref has overridden it + val targetUsed = lastRun?.constraintsProcessed?.targetBG ?: 0.0 - if (((profile.targetLowMgdl+profile.targetHighMgdl)/2)!= targetused) { - overview_temptarget?.text = Profile.toTargetRangeString(targetused, targetused, Constants.MGDL, units) - overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) - overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) - } else { - overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) - overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) - overview_temptarget?.text = Profile.toTargetRangeString(profile.targetLowMgdl, profile.targetHighMgdl, Constants.MGDL, units) - } + if (targetUsed != 0.0 && profile.targetMgdl != targetUsed) { + overview_temptarget?.text = Profile.toTargetRangeString(targetUsed, targetUsed, Constants.MGDL, units) + overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextWarning)) + overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.tempTargetBackground)) } else { overview_temptarget?.setTextColor(resourceHelper.gc(R.color.ribbonTextDefault)) overview_temptarget?.setBackgroundColor(resourceHelper.gc(R.color.ribbonDefault)) @@ -899,4 +892,4 @@ class OverviewFragment : DaggerFragment(), View.OnClickListener, OnLongClickList } } } -} \ No newline at end of file +} From 87782377a58f4b0f98d8e060e2deab31f4d2e930 Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Thu, 21 May 2020 10:21:37 +1200 Subject: [PATCH 8/8] Remove not needed functions --- .../info/nightscout/androidaps/data/Profile.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/core/src/main/java/info/nightscout/androidaps/data/Profile.java b/core/src/main/java/info/nightscout/androidaps/data/Profile.java index 972730ca3d..21eb288c09 100644 --- a/core/src/main/java/info/nightscout/androidaps/data/Profile.java +++ b/core/src/main/java/info/nightscout/androidaps/data/Profile.java @@ -523,29 +523,13 @@ public class Profile { return ret; } - public double getTargetUnits() { - if (units.equals(Constants.MGDL)) { - return getTargetMgdl(secondsFromMidnight()); - } else { - return getTargetMmol(secondsFromMidnight()); - } - } - public double getTargetMgdl() { return getTargetMgdl(secondsFromMidnight()); } - public double getTargetMmol() { - return getTargetMmol(secondsFromMidnight()); - } - public double getTargetMgdl(int timeAsSeconds) { return toMgdl((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); } - public double getTargetMmol(int timeAsSeconds) { - return toMmol((getTargetLowTimeFromMidnight(timeAsSeconds) + getTargetHighTimeFromMidnight(timeAsSeconds)) / 2, units); - } - public double getTargetLowMgdl() { return toMgdl(getTargetLowTimeFromMidnight(secondsFromMidnight()), units); }