reset autosens on site change

This commit is contained in:
Milos Kozak 2018-06-22 20:05:49 +02:00
parent 9360151100
commit 8237456030
5 changed files with 50 additions and 3 deletions

View file

@ -29,6 +29,7 @@ import info.nightscout.androidaps.plugins.Overview.OverviewFragment;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.T;
import info.nightscout.utils.Translator; import info.nightscout.utils.Translator;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_CAREPORTALEVENTS) @DatabaseTable(tableName = DatabaseHelper.DATABASE_CAREPORTALEVENTS)
@ -127,6 +128,19 @@ public class CareportalEvent implements DataPointWithLabelInterface {
return result; return result;
} }
public static boolean isEvent5minBack(List<CareportalEvent> list, long time) {
for (int i = 0; i < list.size(); i++) {
CareportalEvent event = list.get(i);
if (event.date <= time && event.date > (time - T.mins(5).msecs())) {
//log.debug("Found event for time: " + DateUtil.dateAndTimeString(time) + " " + event.toString());
return true;
}
}
//log.debug("WWWWWW No found event for time: " + DateUtil.dateAndTimeString(time));
return false;
}
// -------- DataPointWithLabelInterface ------- // -------- DataPointWithLabelInterface -------
@Override @Override

View file

@ -1249,7 +1249,23 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<>(); return new ArrayList<>();
} }
public List<CareportalEvent> getCareportalEventsFromTime(boolean ascending) { public List<CareportalEvent> getCareportalEventsFromTime(long mills, String type, boolean ascending) {
try {
List<CareportalEvent> careportalEvents;
QueryBuilder<CareportalEvent, Long> queryBuilder = getDaoCareportalEvents().queryBuilder();
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("date", mills).and().eq("eventType", type);
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
return careportalEvents;
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<>();
}
public List<CareportalEvent> getCareportalEvents(boolean ascending) {
try { try {
List<CareportalEvent> careportalEvents; List<CareportalEvent> careportalEvents;
QueryBuilder<CareportalEvent, Long> queryBuilder = getDaoCareportalEvents().queryBuilder(); QueryBuilder<CareportalEvent, Long> queryBuilder = getDaoCareportalEvents().queryBuilder();

View file

@ -14,6 +14,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
@ -81,6 +82,8 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt
} }
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
List<Double> deviationsArray = new ArrayList<>(); List<Double> deviationsArray = new ArrayList<>();
String pastSensitivity = ""; String pastSensitivity = "";
int index = 0; int index = 0;
@ -97,6 +100,12 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt
continue; continue;
} }
// reset deviations after site change
if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) {
deviationsArray.clear();
pastSensitivity += "(SITECHANGE)";
}
if (autosensData.time > toTime - hoursForDetection * 60 * 60 * 1000L) if (autosensData.time > toTime - hoursForDetection * 60 * 60 * 1000L)
deviationsArray.add(autosensData.validDeviation ? autosensData.deviation : 0d); deviationsArray.add(autosensData.validDeviation ? autosensData.deviation : 0d);
if (deviationsArray.size() > hoursForDetection * 60 / 5) if (deviationsArray.size() > hoursForDetection * 60 / 5)

View file

@ -14,6 +14,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.CareportalEvent;
import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
@ -72,6 +73,7 @@ public class SensitivityOref1Plugin extends PluginBase implements SensitivityInt
return new AutosensResult(); return new AutosensResult();
} }
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
List<Double> deviationsArray = new ArrayList<>(); List<Double> deviationsArray = new ArrayList<>();
String pastSensitivity = ""; String pastSensitivity = "";
@ -89,6 +91,12 @@ public class SensitivityOref1Plugin extends PluginBase implements SensitivityInt
continue; continue;
} }
// reset deviations after site change
if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) {
deviationsArray.clear();
pastSensitivity += "(SITECHANGE)";
}
deviationsArray.add(autosensData.validDeviation ? autosensData.deviation : 0d); deviationsArray.add(autosensData.validDeviation ? autosensData.deviation : 0d);
for (int i = 0; i < autosensData.extraDeviation.size(); i++) for (int i = 0; i < autosensData.extraDeviation.size(); i++)

View file

@ -136,7 +136,7 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
llm = new LinearLayoutManager(view.getContext()); llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm); recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getCareportalEventsFromTime(false)); RecyclerViewAdapter adapter = new RecyclerViewAdapter(MainApp.getDbHelper().getCareportalEvents(false));
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout); refreshFromNS = (Button) view.findViewById(R.id.careportal_refreshfromnightscout);
@ -185,7 +185,7 @@ public class TreatmentsCareportalFragment extends SubscriberFragment implements
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getCareportalEventsFromTime(false)), false); recyclerView.swapAdapter(new RecyclerViewAdapter(MainApp.getDbHelper().getCareportalEvents(false)), false);
} }
}); });
} }