From c13994298145f269a751b304f77d4bb02d7c4887 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Fri, 22 Jun 2018 20:11:45 +0200 Subject: [PATCH] reset autosens on site change (AAPS,WA) --- .../plugins/SensitivityAAPS/SensitivityAAPSPlugin.java | 9 +++++++++ .../SensitivityWeightedAveragePlugin.java | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java index bb215ad411..af9633e1d2 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityAAPS/SensitivityAAPSPlugin.java @@ -14,6 +14,7 @@ import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; @@ -80,6 +81,8 @@ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInte } + List siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true); + List deviationsArray = new ArrayList<>(); String pastSensitivity = ""; int index = 0; @@ -96,6 +99,12 @@ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInte continue; } + // reset deviations after site change + if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) { + deviationsArray.clear(); + pastSensitivity += "(SITECHANGE)"; + } + if (autosensData.time > toTime - hoursForDetection * 60 * 60 * 1000L) deviationsArray.add(autosensData.validDeviation ? autosensData.deviation : 0d); if (deviationsArray.size() > hoursForDetection * 60 / 5) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java index f4049568a0..b37c150213 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/SensitivityWeightedAverage/SensitivityWeightedAveragePlugin.java @@ -6,11 +6,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; +import java.util.List; import info.nightscout.androidaps.Config; import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import info.nightscout.androidaps.data.Profile; +import info.nightscout.androidaps.db.CareportalEvent; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginType; @@ -79,6 +81,8 @@ public class SensitivityWeightedAveragePlugin extends PluginBase implements Sens return new AutosensResult(); } + List siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true); + String pastSensitivity = ""; int index = 0; LongSparseArray data = new LongSparseArray<>(); @@ -101,6 +105,12 @@ public class SensitivityWeightedAveragePlugin extends PluginBase implements Sens continue; } + // reset deviations after site change + if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) { + data.clear(); + pastSensitivity += "(SITECHANGE)"; + } + //data.append(autosensData.time); long reverseWeight = (toTime - autosensData.time) / (5 * 60 * 1000L); data.append(reverseWeight, autosensData.validDeviation ? autosensData.deviation : 0d);