From e8406320e0db8fd436bbf4e99a52fcc9dad851c6 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 11:48:00 +0200 Subject: [PATCH 01/12] COB settings --- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_absorption_aaps.xml | 4 ++-- app/src/main/res/xml/pref_absorption_oref0.xml | 13 +++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index abdb0e1160..8dcce74685 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -995,4 +995,6 @@ openapsmb_max_iob Maximum total IOB OpenAPS can\'t go over [U] This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value + Meal max absorption time [h] + Time at which any meal is considered absorbed. Remaining carbs will be cut off. diff --git a/app/src/main/res/xml/pref_absorption_aaps.xml b/app/src/main/res/xml/pref_absorption_aaps.xml index f86a21ec88..e5dab3128e 100644 --- a/app/src/main/res/xml/pref_absorption_aaps.xml +++ b/app/src/main/res/xml/pref_absorption_aaps.xml @@ -6,10 +6,10 @@ android:title="@string/absorptionsettings_title"> + + From 00c05c0e230591d7a3c5c2bfb092cca882897815 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 12:57:13 +0200 Subject: [PATCH 02/12] totalMinCarbsImpact depending on sensitivty plugin --- .../info/nightscout/androidaps/Constants.java | 1 + .../plugins/IobCobCalculator/AutosensData.java | 8 +++++--- .../plugins/IobCobCalculator/IobCobThread.java | 17 ++++++++++++++--- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/xml/pref_absorption_oref0.xml | 2 +- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/Constants.java b/app/src/main/java/info/nightscout/androidaps/Constants.java index aeb4977584..56fd2b6de9 100644 --- a/app/src/main/java/info/nightscout/androidaps/Constants.java +++ b/app/src/main/java/info/nightscout/androidaps/Constants.java @@ -59,6 +59,7 @@ public class Constants { //Autosens public static final double DEVIATION_TO_BE_EQUAL = 2.0; + public static final double DEFAULT_MAX_ABSORPTION_TIME = 6.0; // Pump public static final int PUMP_MAX_CONNECTION_TIME_IN_SECONDS = 120 - 1; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 397656306b..4fe46f3a80 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -7,9 +7,11 @@ import java.util.ArrayList; import java.util.Date; import java.util.List; +import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; @@ -34,14 +36,14 @@ public class AutosensData { carbs = t.carbs; remaining = t.carbs; if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) { - double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, 4d); + double maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME); Profile profile = MainApp.getConfigBuilder().getProfile(t.date); double sens = Profile.toMgdl(profile.getIsf(t.date), profile.getUnits()); double ic = profile.getIc(t.date); min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic; log.debug("Min 5m carbs impact for " + carbs + "g @" + new Date(t.date).toLocaleString() + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic); } else { - min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", 3.0); + min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact); } } } @@ -73,7 +75,7 @@ public class AutosensData { return (int) ((System.currentTimeMillis() - time) / 1000 / 60); } - // remove carbs older than 4h + // remove carbs older than timeframe public void removeOldCarbs(long toTime) { for (int i = 0; i < activeCarbsList.size(); i++) { CarbsInPast c = activeCarbsList.get(i); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index e3f12cbea6..7789f8a5a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -20,12 +20,17 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.FabricPrivacy; +import info.nightscout.utils.SP; /** * Created by mike on 23.01.2018. @@ -199,9 +204,15 @@ public class IobCobThread extends Thread { if (previous != null && previous.cob > 0) { // calculate sum of min carb impact from all active treatments double totalMinCarbsImpact = 0d; - for (int ii = 0; ii < autosensData.activeCarbsList.size(); ++ii) { - AutosensData.CarbsInPast c = autosensData.activeCarbsList.get(ii); - totalMinCarbsImpact += c.min5minCarbImpact; + if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) { + //when the impact depends on a max time, sum them up as smaller carb sizes make them smaller + for (int ii = 0; ii < autosensData.activeCarbsList.size(); ++ii) { + AutosensData.CarbsInPast c = autosensData.activeCarbsList.get(ii); + totalMinCarbsImpact += c.min5minCarbImpact; + } + } else { + //Oref sensitivity + totalMinCarbsImpact = SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact); } // figure out how many carbs that represents diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8dcce74685..c721b7adb5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -619,6 +619,8 @@ Sensitivity AAPS Absorption settings absorption_maxtime + absorption_cutoff + Meal max absorption time [h] Time in hours where is expected all carbs from meal will be absorbed rangetodisplay diff --git a/app/src/main/res/xml/pref_absorption_oref0.xml b/app/src/main/res/xml/pref_absorption_oref0.xml index bac14608c7..4cdd7fb8f0 100644 --- a/app/src/main/res/xml/pref_absorption_oref0.xml +++ b/app/src/main/res/xml/pref_absorption_oref0.xml @@ -28,7 +28,7 @@ android:maxLines="20" android:title="@string/absorption_cutoff_title" android:dialogMessage="@string/absorption_cutoff_summary" - android:key="@string/key_absorption_maxtime" /> + android:key="@string/key_absorption_cutoff" /> From f4dea97f3638f6387f98679afc3346e22d61c11d Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 13:04:21 +0200 Subject: [PATCH 03/12] cutoff at max absorption time --- .../plugins/IobCobCalculator/AutosensData.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 4fe46f3a80..b4013a7a3c 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -77,13 +77,19 @@ public class AutosensData { // remove carbs older than timeframe public void removeOldCarbs(long toTime) { + double maxAbsorptionHours = Constants.DEFAULT_MAX_ABSORPTION_TIME; + if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) { + maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME); + } else { + maxAbsorptionHours = SP.getDouble(R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME); + } for (int i = 0; i < activeCarbsList.size(); i++) { CarbsInPast c = activeCarbsList.get(i); - if (c.time + 4 * 60 * 60 * 1000L < toTime) { + if (c.time + maxAbsorptionHours * 60 * 60 * 1000L < toTime) { activeCarbsList.remove(i--); if (c.remaining > 0) cob -= c.remaining; - log.debug("Removing carbs at "+ new Date(toTime).toLocaleString() + " + after 4h :" + new Date(c.time).toLocaleString()); + log.debug("Removing carbs at "+ new Date(toTime).toLocaleString() + " + after "+ maxAbsorptionHours +"h :" + new Date(c.time).toLocaleString()); } } } From 09cc8c01b645ecfe89d27314fffcd0b9b05b0996 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 13:31:34 +0200 Subject: [PATCH 04/12] use min5min impact actually used for SMB --- .../java/info/nightscout/androidaps/data/MealData.java | 1 + .../plugins/IobCobCalculator/AutosensData.java | 2 ++ .../plugins/IobCobCalculator/IobCobThread.java | 1 + .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 8 ++++++-- .../plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java | 9 ++++++--- .../androidaps/plugins/Source/SourceXdripPlugin.java | 2 +- .../androidaps/plugins/Treatments/TreatmentsPlugin.java | 1 + 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/data/MealData.java b/app/src/main/java/info/nightscout/androidaps/data/MealData.java index 054c76d602..8acf4285bf 100644 --- a/app/src/main/java/info/nightscout/androidaps/data/MealData.java +++ b/app/src/main/java/info/nightscout/androidaps/data/MealData.java @@ -11,4 +11,5 @@ public class MealData { public double slopeFromMinDeviation = 999; public long lastBolusTime; public long lastCarbTime = 0L; + public double usedMinCarbsImpact = 0d; } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index b4013a7a3c..85dc6999a0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -65,6 +65,8 @@ public class AutosensData { public double autosensRatio = 1d; public double slopeFromMaxDeviation = 0; public double slopeFromMinDeviation = 999; + public double usedMinCarbsImpact = -0; + @Override public String toString() { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index 7789f8a5a6..60d315a070 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -222,6 +222,7 @@ public class IobCobThread extends Thread { // and add that to the running total carbsAbsorbed autosensData.cob = Math.max(previous.cob - autosensData.absorbed, 0d); autosensData.substractAbosorbedCarbs(); + autosensData.usedMinCarbsImpact = totalMinCarbsImpact; } autosensData.removeOldCarbs(bgTime); autosensData.cob += autosensData.carbsFromBolus; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 96e004d996..928987393d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -213,8 +213,12 @@ public class DetermineBasalAdapterAMAJS { mProfile.put("current_basal", basalrate); mProfile.put("temptargetSet", tempTargetSet); mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true)); - //TODO: align with max-absorption model in AMA sensitivity - mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); + //align with max-absorption model in AMA sensitivity + if(mealData.usedMinCarbsImpact >0){ + mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); + } else { + mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); + } if (units.equals(Constants.MMOL)) { mProfile.put("out_units", "mmol/L"); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java index 89bf8431f4..b28ce599f7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java @@ -243,9 +243,12 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("half_basal_exercise_target", SMBDefaults.half_basal_exercise_target); mProfile.put("maxCOB", SMBDefaults.maxCOB); mProfile.put("skip_neutral_temps", SMBDefaults.skip_neutral_temps); - //TODO: align with max-absorption model in AMA sensitivity - mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); - ; + //align with max-absorption model in AMA sensitivity + if(mealData.usedMinCarbsImpact >0){ + mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); + } else { + mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); + } mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap); mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false)); mProfile.put("A52_risk_enable", SMBDefaults.A52_risk_enable); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java index 0d33f529b3..bfc1a184ff 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -29,6 +29,6 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { @Override public boolean advancedFilteringSupported() { - return false; + return true; } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index 2f5135c0cb..c3198f752a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -235,6 +235,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface result.mealCOB = autosensData.cob; result.slopeFromMinDeviation = autosensData.slopeFromMinDeviation; result.slopeFromMaxDeviation = autosensData.slopeFromMaxDeviation; + result.usedMinCarbsImpact = autosensData.usedMinCarbsImpact; } result.lastBolusTime = getLastBolusTime(); return result; From d7bf3c563a72af08da7ca36a6c763d511fcd07bf Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 13:35:52 +0200 Subject: [PATCH 05/12] cleanup --- .../nightscout/androidaps/plugins/Source/SourceXdripPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java index bfc1a184ff..0d33f529b3 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Source/SourceXdripPlugin.java @@ -29,6 +29,6 @@ public class SourceXdripPlugin extends PluginBase implements BgSourceInterface { @Override public boolean advancedFilteringSupported() { - return true; + return false; } } From 8d94acb0515f9a8530fe25eadf59021bd7831d4c Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 13:44:06 +0200 Subject: [PATCH 06/12] more cleanups --- .../androidaps/plugins/IobCobCalculator/AutosensData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 85dc6999a0..11b86c5fc5 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -65,7 +65,7 @@ public class AutosensData { public double autosensRatio = 1d; public double slopeFromMaxDeviation = 0; public double slopeFromMinDeviation = 999; - public double usedMinCarbsImpact = -0; + public double usedMinCarbsImpact = 0d; @Override From d810be9b6a52ed108baf5a1ed3b93f74ec028d26 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 14:03:30 +0200 Subject: [PATCH 07/12] consider absorption time for carbs - not DIA --- .../plugins/Treatments/TreatmentsPlugin.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java index c3198f752a..feb99d5166 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Treatments/TreatmentsPlugin.java @@ -40,6 +40,8 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification; import info.nightscout.androidaps.plugins.Overview.notifications.Notification; +import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; +import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.NSUpload; import info.nightscout.utils.SP; @@ -211,22 +213,35 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface if (profile == null) return result; long now = System.currentTimeMillis(); - long dia_ago = now - (Double.valueOf(1.5d * profile.getDia() * T.hours(1).msecs())).longValue(); + long dia_ago = now - (Double.valueOf(profile.getDia() * T.hours(1).msecs())).longValue(); + + double maxAbsorptionHours = Constants.DEFAULT_MAX_ABSORPTION_TIME; + if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) { + maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME); + } else { + maxAbsorptionHours = SP.getDouble(R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME); + } + long absorptionTime_ago = now - (Double.valueOf(maxAbsorptionHours * T.hours(1).msecs())).longValue(); synchronized (treatments) { for (Treatment treatment : treatments) { if (!treatment.isValid) continue; long t = treatment.date; + if (t > dia_ago && t <= now) { - if (treatment.carbs >= 1) { - result.carbs += treatment.carbs; - result.lastCarbTime = t; - } if (treatment.insulin > 0 && treatment.mealBolus) { result.boluses += treatment.insulin; } } + + if (t > absorptionTime_ago && t <= now) { + if (treatment.carbs >= 1) { + result.carbs += treatment.carbs; + if(t > result.lastCarbTime) + result.lastCarbTime = t; + } + } } } From ed24a129ae2ff846513dcbaf43110a2f70fffaf8 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 19:32:50 +0200 Subject: [PATCH 08/12] unify Default in settings xml and constants --- app/src/main/res/xml/pref_absorption_oref0.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/xml/pref_absorption_oref0.xml b/app/src/main/res/xml/pref_absorption_oref0.xml index 4cdd7fb8f0..a194b754a9 100644 --- a/app/src/main/res/xml/pref_absorption_oref0.xml +++ b/app/src/main/res/xml/pref_absorption_oref0.xml @@ -8,7 +8,7 @@ validate:testType="floatNumericRange" validate:floatminNumber="0.1" validate:floatmaxNumber="12.0" - android:defaultValue="3.0" + android:defaultValue="8.0" android:selectAllOnFocus="true" android:singleLine="true" android:inputType="numberDecimal" From 9e9270bff7e38c16923b961845fbf5de2ab3bec2 Mon Sep 17 00:00:00 2001 From: AdrianLxM Date: Thu, 19 Apr 2018 19:34:38 +0200 Subject: [PATCH 09/12] cleanups --- .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 2 +- .../plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 928987393d..89739ef626 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -214,7 +214,7 @@ public class DetermineBasalAdapterAMAJS { mProfile.put("temptargetSet", tempTargetSet); mProfile.put("autosens_adjust_targets", SP.getBoolean("openapsama_autosens_adjusttargets", true)); //align with max-absorption model in AMA sensitivity - if(mealData.usedMinCarbsImpact >0){ + if(mealData.usedMinCarbsImpact > 0){ mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); } else { mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java index b28ce599f7..fe14147853 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java @@ -244,7 +244,7 @@ public class DetermineBasalAdapterSMBJS { mProfile.put("maxCOB", SMBDefaults.maxCOB); mProfile.put("skip_neutral_temps", SMBDefaults.skip_neutral_temps); //align with max-absorption model in AMA sensitivity - if(mealData.usedMinCarbsImpact >0){ + if(mealData.usedMinCarbsImpact > 0){ mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); } else { mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); From e1dc69cd4d8b5263ba47319d3fc1a255cabdaa61 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 19 Apr 2018 22:31:07 +0200 Subject: [PATCH 10/12] visualize min carbs absorption --- .../nightscout/androidaps/db/BgReading.java | 3 +- .../IobCobCalculator/AutosensData.java | 61 +++++++++++++++-- .../IobCobCalculator/IobCobThread.java | 6 +- .../plugins/Overview/graphData/GraphData.java | 7 ++ .../PointsWithLabelGraphSeries.java | 67 ++++++++++--------- 5 files changed, 103 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java index e842979ecb..20b9040065 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/BgReading.java +++ b/app/src/main/java/info/nightscout/androidaps/db/BgReading.java @@ -195,8 +195,7 @@ public class BgReading implements DataPointWithLabelInterface { @Override public float getSize() { - boolean isTablet = MainApp.sResources.getBoolean(R.bool.isTablet); - return isTablet ? 8 : 5; + return 1; } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 11b86c5fc5..97ea10b1a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -11,18 +11,20 @@ import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; -import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.Treatments.Treatment; import info.nightscout.utils.SP; /** * Created by mike on 25.04.2017. */ -public class AutosensData { +public class AutosensData implements DataPointWithLabelInterface { private static Logger log = LoggerFactory.getLogger(AutosensData.class); static class CarbsInPast { @@ -66,11 +68,11 @@ public class AutosensData { public double slopeFromMaxDeviation = 0; public double slopeFromMinDeviation = 999; public double usedMinCarbsImpact = 0d; - + public boolean failoverToMinAbsorbtionRate = false; @Override public String toString() { - return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " avgDelta=" + avgDelta + " Bgi=" + bgi + " Deviation=" + deviation + " avgDeviation=" + avgDeviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio + " slopeFromMaxDeviation=" + slopeFromMaxDeviation + " slopeFromMinDeviation =" + slopeFromMinDeviation ; + return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " avgDelta=" + avgDelta + " Bgi=" + bgi + " Deviation=" + deviation + " avgDeviation=" + avgDeviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio + " slopeFromMaxDeviation=" + slopeFromMaxDeviation + " slopeFromMinDeviation =" + slopeFromMinDeviation; } public int minOld() { @@ -91,7 +93,7 @@ public class AutosensData { activeCarbsList.remove(i--); if (c.remaining > 0) cob -= c.remaining; - log.debug("Removing carbs at "+ new Date(toTime).toLocaleString() + " + after "+ maxAbsorptionHours +"h :" + new Date(c.time).toLocaleString()); + log.debug("Removing carbs at " + new Date(toTime).toLocaleString() + " + after " + maxAbsorptionHours + "h :" + new Date(c.time).toLocaleString()); } } } @@ -108,4 +110,51 @@ public class AutosensData { } } + // ------- DataPointWithLabelInterface ------ + + @Override + public double getX() { + return time; + } + + @Override + public double getY() { + return cob; + } + + @Override + public void setY(double y) { + + } + + @Override + public String getLabel() { + return null; + } + + @Override + public long getDuration() { + return 0; + } + + @Override + public PointsWithLabelGraphSeries.Shape getShape() { + return PointsWithLabelGraphSeries.Shape.COBFAILOVER; + } + + @Override + public float getSize() { + return 1f; + } + + @Override + public int getColor() { + return MainApp.gc(R.color.cob); + } + + @Override + public int getSecondColor() { + return 0; + } + } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index 60d315a070..e1616112ab 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -20,13 +20,13 @@ import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; +import info.nightscout.androidaps.events.Event; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.Treatments.Treatment; -import info.nightscout.androidaps.events.Event; -import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished; import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin; import info.nightscout.utils.DateUtil; import info.nightscout.utils.FabricPrivacy; @@ -218,6 +218,8 @@ public class IobCobThread extends Thread { // figure out how many carbs that represents // but always assume at least 3mg/dL/5m (default) absorption per active treatment double ci = Math.max(deviation, totalMinCarbsImpact); + if (ci != deviation) + autosensData.failoverToMinAbsorbtionRate = true; autosensData.absorbed = ci * profile.getIc(bgTime) / sens; // and add that to the running total carbsAbsorbed autosensData.cob = Math.max(previous.cob - autosensData.absorbed, 0d); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index 9921d236a1..7cae0bd284 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -365,6 +365,7 @@ public class GraphData { // scale in % of vertical size (like 0.3) public void addCob(long fromTime, long toTime, boolean useForScale, double scale) { + List minFailoverActiveList = new ArrayList<>(); FixedLineGraphSeries cobSeries; List cobArray = new ArrayList<>(); Double maxCobValueFound = 0d; @@ -382,6 +383,8 @@ public class GraphData { maxCobValueFound = Math.max(maxCobValueFound, cob); lastCob = cob; } + if (autosensData.failoverToMinAbsorbtionRate) + minFailoverActiveList.add(autosensData); } } @@ -400,6 +403,10 @@ public class GraphData { cobScale.setMultiplier(maxY * scale / maxCobValueFound); addSeries(cobSeries); + + DataPointWithLabelInterface[] minFailover = new DataPointWithLabelInterface[minFailoverActiveList.size()]; + minFailover = minFailoverActiveList.toArray(minFailover); + addSeries(new PointsWithLabelGraphSeries<>(minFailover)); } // scale in % of vertical size (like 0.3) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java index 9c8e312fb6..8ac3be0ad8 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphExtensions/PointsWithLabelGraphSeries.java @@ -3,42 +3,46 @@ package info.nightscout.androidaps.plugins.Overview.graphExtensions; /** * GraphView * Copyright (C) 2014 Jonas Gehring - * + *

* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, * with the "Linking Exception", which can be found at the license.txt * file in this program. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * with the "Linking Exception" along with this program; if not, * write to the author Jonas Gehring . + *

+ * Added by mike */ /** * Added by mike */ +import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Point; import android.graphics.Rect; import android.graphics.Typeface; -import android.util.TypedValue; -// Added by Rumen for scalable text -import android.content.Context; -import info.nightscout.androidaps.MainApp; + import com.jjoe64.graphview.GraphView; import com.jjoe64.graphview.series.BaseSeries; import java.util.Iterator; +import info.nightscout.androidaps.MainApp; + +// Added by Rumen for scalable text + /** * Series that plots the data as points. * The points can be different shapes or a @@ -74,7 +78,8 @@ public class PointsWithLabelGraphSeries e OPENAPSOFFLINE, EXERCISE, GENERAL, - GENERALWITHDURATION + GENERALWITHDURATION, + COBFAILOVER } /** @@ -148,7 +153,7 @@ public class PointsWithLabelGraphSeries e float scaleX = (float) (graphWidth / diffX); - int i=0; + int i = 0; while (values.hasNext()) { E value = values.next(); @@ -182,7 +187,7 @@ public class PointsWithLabelGraphSeries e } /* Fix a bug that continue to show the DOT after Y axis */ - if(x < 0) { + if (x < 0) { overdraw = true; } @@ -197,10 +202,10 @@ public class PointsWithLabelGraphSeries e // draw data point if (!overdraw) { - if (value.getShape() == Shape.BG) { + if (value.getShape() == Shape.BG || value.getShape() == Shape.COBFAILOVER) { mPaint.setStyle(Paint.Style.FILL); mPaint.setStrokeWidth(0); - canvas.drawCircle(endX, endY, scaledPxSize, mPaint); + canvas.drawCircle(endX, endY, value.getSize() * scaledPxSize, mPaint); } else if (value.getShape() == Shape.PREDICTION) { mPaint.setColor(value.getColor()); mPaint.setStyle(Paint.Style.FILL); @@ -211,20 +216,20 @@ public class PointsWithLabelGraphSeries e mPaint.setStrokeWidth(0); canvas.drawCircle(endX, endY, scaledPxSize / 3, mPaint); } else if (value.getShape() == Shape.RECTANGLE) { - canvas.drawRect(endX-scaledPxSize, endY-scaledPxSize, endX+scaledPxSize, endY+scaledPxSize, mPaint); + canvas.drawRect(endX - scaledPxSize, endY - scaledPxSize, endX + scaledPxSize, endY + scaledPxSize, mPaint); } else if (value.getShape() == Shape.TRIANGLE) { mPaint.setStrokeWidth(0); Point[] points = new Point[3]; - points[0] = new Point((int)endX, (int)(endY-scaledPxSize)); - points[1] = new Point((int)(endX+scaledPxSize), (int)(endY+scaledPxSize*0.67)); - points[2] = new Point((int)(endX-scaledPxSize), (int)(endY+scaledPxSize*0.67)); + points[0] = new Point((int) endX, (int) (endY - scaledPxSize)); + points[1] = new Point((int) (endX + scaledPxSize), (int) (endY + scaledPxSize * 0.67)); + points[2] = new Point((int) (endX - scaledPxSize), (int) (endY + scaledPxSize * 0.67)); drawArrows(points, canvas, mPaint); } else if (value.getShape() == Shape.BOLUS) { mPaint.setStrokeWidth(0); Point[] points = new Point[3]; - points[0] = new Point((int)endX, (int)(endY-scaledPxSize)); - points[1] = new Point((int)(endX+scaledPxSize), (int)(endY+scaledPxSize*0.67)); - points[2] = new Point((int)(endX-scaledPxSize), (int)(endY+scaledPxSize*0.67)); + points[0] = new Point((int) endX, (int) (endY - scaledPxSize)); + points[1] = new Point((int) (endX + scaledPxSize), (int) (endY + scaledPxSize * 0.67)); + points[2] = new Point((int) (endX - scaledPxSize), (int) (endY + scaledPxSize * 0.67)); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); drawArrows(points, canvas, mPaint); if (value.getLabel() != null) { @@ -234,15 +239,15 @@ public class PointsWithLabelGraphSeries e mPaint.setStrokeWidth(2); Point[] points = new Point[3]; float size = value.getSize() * scaledPxSize; - points[0] = new Point((int)endX, (int)(endY-size)); - points[1] = new Point((int)(endX+size), (int)(endY+size*0.67)); - points[2] = new Point((int)(endX-size), (int)(endY+size*0.67)); + points[0] = new Point((int) endX, (int) (endY - size)); + points[1] = new Point((int) (endX + size), (int) (endY + size * 0.67)); + points[2] = new Point((int) (endX - size), (int) (endY + size * 0.67)); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); drawArrows(points, canvas, mPaint); } else if (value.getShape() == Shape.EXTENDEDBOLUS) { mPaint.setStrokeWidth(0); if (value.getLabel() != null) { - Rect bounds = new Rect((int)endX, (int)endY + 3, (int) (xpluslength), (int) endY + 8); + Rect bounds = new Rect((int) endX, (int) endY + 3, (int) (xpluslength), (int) endY + 8); mPaint.setStyle(Paint.Style.FILL_AND_STROKE); canvas.drawRect(bounds, mPaint); mPaint.setTextSize((float) (scaledTextSize)); @@ -254,7 +259,7 @@ public class PointsWithLabelGraphSeries e mPaint.setStrokeWidth(0); if (value.getLabel() != null) { //mPaint.setTextSize((int) (scaledPxSize * 3)); - mPaint.setTextSize((float) (scaledTextSize*1.2)); + mPaint.setTextSize((float) (scaledTextSize * 1.2)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.BOLD)); Rect bounds = new Rect(); mPaint.getTextBounds(value.getLabel(), 0, value.getLabel().length(), bounds); @@ -355,7 +360,7 @@ public class PointsWithLabelGraphSeries e * @param paint paint object */ private void drawArrows(Point[] point, Canvas canvas, Paint paint) { - float [] points = new float[8]; + float[] points = new float[8]; points[0] = point[0].x; points[1] = point[0].y; points[2] = point[1].x; @@ -368,10 +373,10 @@ public class PointsWithLabelGraphSeries e canvas.save(); canvas.drawVertices(Canvas.VertexMode.TRIANGLES, 8, points, 0, null, 0, null, 0, null, 0, 0, paint); Path path = new Path(); - path.moveTo(point[0].x , point[0].y); - path.lineTo(point[1].x,point[1].y); - path.lineTo(point[2].x,point[2].y); - canvas.drawPath(path,paint); + path.moveTo(point[0].x, point[0].y); + path.lineTo(point[1].x, point[1].y); + path.lineTo(point[2].x, point[2].y); + canvas.drawPath(path, paint); canvas.restore(); } @@ -381,7 +386,7 @@ public class PointsWithLabelGraphSeries e float py = endY + scaledPxSize; canvas.save(); canvas.rotate(-45, px, py); - mPaint.setTextSize((float) (scaledTextSize*0.8)); + mPaint.setTextSize((float) (scaledTextSize * 0.8)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)); mPaint.setFakeBoldText(true); mPaint.setTextAlign(Paint.Align.RIGHT); @@ -393,7 +398,7 @@ public class PointsWithLabelGraphSeries e float py = endY - scaledPxSize; canvas.save(); canvas.rotate(-45, px, py); - mPaint.setTextSize((float) (scaledTextSize*0.8)); + mPaint.setTextSize((float) (scaledTextSize * 0.8)); mPaint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.NORMAL)); mPaint.setFakeBoldText(true); canvas.drawText(value.getLabel(), px + scaledPxSize, py, mPaint); From 0ab04c4d959dc0396b02b3fa61997bdb20c32125 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 20 Apr 2018 12:28:07 +0200 Subject: [PATCH 11/12] fix cob scaling --- .../plugins/IobCobCalculator/AutosensData.java | 9 ++++++++- .../androidaps/plugins/Overview/graphData/GraphData.java | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 97ea10b1a7..7d23862cef 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -15,6 +15,7 @@ import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.plugins.OpenAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; +import info.nightscout.androidaps.plugins.Overview.graphExtensions.Scale; import info.nightscout.androidaps.plugins.SensitivityAAPS.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.SensitivityWeightedAverage.SensitivityWeightedAveragePlugin; import info.nightscout.androidaps.plugins.Treatments.Treatment; @@ -112,6 +113,12 @@ public class AutosensData implements DataPointWithLabelInterface { // ------- DataPointWithLabelInterface ------ + private Scale scale; + + public void setScale(Scale scale) { + this.scale = scale; + } + @Override public double getX() { return time; @@ -119,7 +126,7 @@ public class AutosensData implements DataPointWithLabelInterface { @Override public double getY() { - return cob; + return scale.transform(cob); } @Override diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java index 7cae0bd284..06ea2d6d65 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/Overview/graphData/GraphData.java @@ -383,8 +383,10 @@ public class GraphData { maxCobValueFound = Math.max(maxCobValueFound, cob); lastCob = cob; } - if (autosensData.failoverToMinAbsorbtionRate) + if (autosensData.failoverToMinAbsorbtionRate) { + autosensData.setScale(cobScale); minFailoverActiveList.add(autosensData); + } } } From 41b5636c1377962f6e421804f2d30d0073335c23 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 20 Apr 2018 12:44:19 +0200 Subject: [PATCH 12/12] clear autosens cache on new preferences change --- .../androidaps/plugins/IobCobCalculator/AutosensData.java | 2 +- .../plugins/IobCobCalculator/IobCobCalculatorPlugin.java | 6 ++++-- .../androidaps/plugins/IobCobCalculator/IobCobThread.java | 3 ++- .../plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java | 2 +- .../plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java | 2 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/pref_absorption_oref0.xml | 2 +- 7 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java index 7d23862cef..ea0ce7d4cb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/AutosensData.java @@ -46,7 +46,7 @@ public class AutosensData implements DataPointWithLabelInterface { min5minCarbImpact = t.carbs / (maxAbsorptionHours * 60 / 5) * sens / ic; log.debug("Min 5m carbs impact for " + carbs + "g @" + new Date(t.date).toLocaleString() + " for " + maxAbsorptionHours + "h calculated to " + min5minCarbImpact + " ISF: " + sens + " IC: " + ic); } else { - min5minCarbImpact = SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact); + min5minCarbImpact = SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact); } } } diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index f51c7f7a94..2241c256ac 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -74,7 +74,7 @@ public class IobCobCalculatorPlugin extends PluginBase { .neverVisible(true) .alwaysEnabled(true) ); - } + } @Override protected void onStart() { @@ -548,7 +548,9 @@ public class IobCobCalculatorPlugin extends PluginBase { } if (ev.isChanged(R.string.key_openapsama_autosens_period) || ev.isChanged(R.string.key_age) || - ev.isChanged(R.string.key_absorption_maxtime) + ev.isChanged(R.string.key_absorption_maxtime) || + ev.isChanged(R.string.key_openapsama_min_5m_carbimpact) || + ev.isChanged(R.string.key_absorption_cutoff) ) { stopCalculation("onEventPreferenceChange"); synchronized (dataLock) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java index e1616112ab..a41f12764d 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobThread.java @@ -17,6 +17,7 @@ import info.nightscout.androidaps.BuildConfig; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.db.BgReading; @@ -212,7 +213,7 @@ public class IobCobThread extends Thread { } } else { //Oref sensitivity - totalMinCarbsImpact = SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact); + totalMinCarbsImpact = SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact); } // figure out how many carbs that represents diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java index 89739ef626..ed0fa1f0bb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSAMA/DetermineBasalAdapterAMAJS.java @@ -217,7 +217,7 @@ public class DetermineBasalAdapterAMAJS { if(mealData.usedMinCarbsImpact > 0){ mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); } else { - mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); + mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)); } if (units.equals(Constants.MMOL)) { diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java index fe14147853..0c665c7f9f 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/OpenAPSSMB/DetermineBasalAdapterSMBJS.java @@ -247,7 +247,7 @@ public class DetermineBasalAdapterSMBJS { if(mealData.usedMinCarbsImpact > 0){ mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact); } else { - mProfile.put("min_5m_carbimpact", SP.getDouble("openapsama_min_5m_carbimpact", SMBDefaults.min_5m_carbimpact)); + mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact)); } mProfile.put("remainingCarbsCap", SMBDefaults.remainingCarbsCap); mProfile.put("enableUAM", SP.getBoolean(R.string.key_use_uam, false)); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a0c4363c01..1e8d21ac37 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1004,4 +1004,5 @@ Time show_notes_entry_dialogs Show notes field in treatment dialogs + openapsama_min_5m_carbimpact diff --git a/app/src/main/res/xml/pref_absorption_oref0.xml b/app/src/main/res/xml/pref_absorption_oref0.xml index a194b754a9..4c3b11d283 100644 --- a/app/src/main/res/xml/pref_absorption_oref0.xml +++ b/app/src/main/res/xml/pref_absorption_oref0.xml @@ -15,7 +15,7 @@ android:maxLines="20" android:title="@string/openapsama_min_5m_carbimpact" android:dialogMessage="@string/openapsama_min_5m_carbimpact_summary" - android:key="openapsama_min_5m_carbimpact" /> + android:key="@string/key_openapsama_min_5m_carbimpact" />