reset autosens on profileswitch with zero duration

This commit is contained in:
Milos Kozak 2018-09-06 16:30:57 +02:00
parent f5873f9f87
commit ecae6af151
7 changed files with 72 additions and 1 deletions

View file

@ -144,7 +144,6 @@ public class CareportalEvent implements DataPointWithLabelInterface, Interval {
return true;
}
}
//log.debug("No found event for time: " + DateUtil.dateAndTimeString(time));
return false;
}

View file

@ -1434,6 +1434,24 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<>();
}
public List<ProfileSwitch> getProfileSwitchEventsFromTime(long mills, boolean ascending) {
try {
Dao<ProfileSwitch, Long> daoProfileSwitch = getDaoProfileSwitch();
List<ProfileSwitch> profileSwitches;
QueryBuilder<ProfileSwitch, Long> queryBuilder = daoProfileSwitch.queryBuilder();
queryBuilder.orderBy("date", ascending);
queryBuilder.limit(100L);
Where where = queryBuilder.where();
where.ge("date", mills);
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
profileSwitches = daoProfileSwitch.query(preparedQuery);
return profileSwitches;
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<>();
}
public boolean createOrUpdate(ProfileSwitch profileSwitch) {
try {
ProfileSwitch old;

View file

@ -11,6 +11,7 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Objects;
import info.nightscout.androidaps.MainApp;
@ -25,6 +26,7 @@ import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
import info.nightscout.androidaps.plugins.ProfileLocal.LocalProfilePlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.T;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_PROFILESWITCHES)
public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
@ -218,6 +220,26 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
MainApp.bus().post(new EventNewNotification(notification));
}
public static boolean isEvent5minBack(List<ProfileSwitch> list, long time, boolean zeroDurationOnly) {
for (int i = 0; i < list.size(); i++) {
ProfileSwitch event = list.get(i);
if (event.date <= time && event.date > (time - T.mins(5).msecs())) {
if (zeroDurationOnly) {
if (event.durationInMinutes == 0) {
if (L.isEnabled(L.DATABASE))
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeFullString(time) + " " + event.toString());
return true;
}
} else {
if (L.isEnabled(L.DATABASE))
log.debug("Found ProfileSwitch event for time: " + DateUtil.dateAndTimeFullString(time) + " " + event.toString());
return true;
}
}
}
return false;
}
// -------- Interval interface end ---------
// ----------------- DataPointInterface --------------------

View file

@ -14,6 +14,7 @@ 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.db.ProfileSwitch;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
@ -82,6 +83,7 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
List<ProfileSwitch> profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true);
List<Double> deviationsArray = new ArrayList<>();
String pastSensitivity = "";
@ -105,6 +107,12 @@ public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
pastSensitivity += "(SITECHANGE)";
}
// reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) {
deviationsArray.clear();
pastSensitivity += "(PROFILESWITCH)";
}
double deviation = autosensData.deviation;
//set positive deviations to zero if bg < 80

View file

@ -14,6 +14,7 @@ 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.db.ProfileSwitch;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
@ -77,6 +78,7 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
List<ProfileSwitch> profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true);
List<Double> deviationsArray = new ArrayList<>();
String pastSensitivity = "";
@ -100,6 +102,12 @@ public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
pastSensitivity += "(SITECHANGE)";
}
// reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) {
deviationsArray.clear();
pastSensitivity += "(PROFILESWITCH)";
}
double deviation = autosensData.deviation;
//set positive deviations to zero if bg < 80

View file

@ -14,6 +14,7 @@ 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.db.ProfileSwitch;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
@ -76,6 +77,7 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
}
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
List<ProfileSwitch> profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true);
List<Double> deviationsArray = new ArrayList<>();
String pastSensitivity = "";
@ -99,6 +101,12 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
pastSensitivity += "(SITECHANGE)";
}
// reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) {
deviationsArray.clear();
pastSensitivity += "(PROFILESWITCH)";
}
double deviation = autosensData.deviation;
//set positive deviations to zero if bg < 80

View file

@ -12,6 +12,7 @@ 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.db.ProfileSwitch;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.logging.L;
@ -80,6 +81,7 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
}
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
List<ProfileSwitch> profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true);
String pastSensitivity = "";
int index = 0;
@ -109,6 +111,12 @@ public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin
pastSensitivity += "(SITECHANGE)";
}
// reset deviations after profile switch
if (ProfileSwitch.isEvent5minBack(profileSwitches, autosensData.time, true)) {
data.clear();
pastSensitivity += "(PROFILESWITCH)";
}
double deviation = autosensData.deviation;
//set positive deviations to zero if bg < 80