invalidate autosens on new profile

This commit is contained in:
Milos Kozak 2017-05-09 16:51:08 +02:00
parent 09fea02ed2
commit d781c69b94
4 changed files with 20 additions and 4 deletions

View file

@ -356,7 +356,7 @@ public class DataService extends IntentService {
String activeProfile = bundles.getString("activeprofile");
String profile = bundles.getString("profile");
NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile);
MainApp.bus().post(new EventNewBasalProfile(nsProfile));
MainApp.bus().post(new EventNewBasalProfile(nsProfile, "NSClient"));
PumpInterface pump = MainApp.getConfigBuilder();
if (pump != null) {

View file

@ -7,8 +7,10 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
*/
public class EventNewBasalProfile {
public NSProfile newNSProfile = null;
public String from = "";
public EventNewBasalProfile(NSProfile newProfile) {
public EventNewBasalProfile(NSProfile newProfile, String from) {
newNSProfile = newProfile;
this.from = from;
}
}

View file

@ -618,7 +618,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
if (pump != null) {
pump.setNewBasalProfile(nsProfile);
log.debug("Setting new profile: " + profile);
MainApp.bus().post(new EventNewBasalProfile(nsProfile));
MainApp.bus().post(new EventNewBasalProfile(nsProfile, "NewNSTreatmentDialog"));
} else {
log.error("No active pump selected");
}

View file

@ -156,7 +156,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
private void loadBgData() {
//log.debug("Locking loadBgData");
synchronized (dataLock) {
onNewProfile(new EventNewBasalProfile(null));
onNewProfile(new EventNewBasalProfile(null, "IobCobCalculator init"));
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia)), false);
log.debug("BG data loaded. Size: " + bgReadings.size());
}
@ -545,6 +545,20 @@ public class IobCobCalculatorPlugin implements PluginBase {
if (profile != null) {
dia = profile.getDia();
}
if (ev.newNSProfile == null) { // on init no need of reset
return;
}
synchronized (dataLock) {
log.debug("Invalidating cached data because of new profile from " + ev.from + ". IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
iobTable = new LongSparseArray<>();
autosensDataTable = new LongSparseArray<>();
}
sHandler.post(new Runnable() {
@Override
public void run() {
calculateSensitivityData();
}
});
}
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated