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 activeProfile = bundles.getString("activeprofile");
String profile = bundles.getString("profile"); String profile = bundles.getString("profile");
NSProfile nsProfile = new NSProfile(new JSONObject(profile), activeProfile); 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(); PumpInterface pump = MainApp.getConfigBuilder();
if (pump != null) { if (pump != null) {

View file

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

View file

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

View file

@ -156,7 +156,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
private void loadBgData() { private void loadBgData() {
//log.debug("Locking loadBgData"); //log.debug("Locking loadBgData");
synchronized (dataLock) { 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); bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia)), false);
log.debug("BG data loaded. Size: " + bgReadings.size()); log.debug("BG data loaded. Size: " + bgReadings.size());
} }
@ -545,6 +545,20 @@ public class IobCobCalculatorPlugin implements PluginBase {
if (profile != null) { if (profile != null) {
dia = profile.getDia(); 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 // When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated