IobCobPlugin specify loading time
This commit is contained in:
parent
31d493d8ae
commit
4cdadaf0c4
2 changed files with 39 additions and 13 deletions
|
@ -169,9 +169,9 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
return rouded;
|
return rouded;
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadBgData() {
|
void loadBgData(long start) {
|
||||||
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)), false);
|
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (start - 60 * 60 * 1000L * (24 + dia)), false);
|
||||||
log.debug("BG data loaded. Size: " + bgReadings.size());
|
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isAbout5minData() {
|
private boolean isAbout5minData() {
|
||||||
|
@ -521,13 +521,21 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventAppInitialized(EventAppInitialized ev) {
|
public void onEventAppInitialized(EventAppInitialized ev) {
|
||||||
runCalculation("onEventAppInitialized", true, ev);
|
if (this != getPlugin()) {
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventNewBG(EventNewBG ev) {
|
public void onEventNewBG(EventNewBG ev) {
|
||||||
|
if (this != getPlugin()) {
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
stopCalculation("onEventNewBG");
|
stopCalculation("onEventNewBG");
|
||||||
runCalculation("onEventNewBG", true, ev);
|
runCalculation("onEventNewBG", System.currentTimeMillis(), true, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopCalculation(String from) {
|
private void stopCalculation(String from) {
|
||||||
|
@ -541,16 +549,20 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void runCalculation(String from, boolean bgDataReload, Event cause) {
|
private void runCalculation(String from, long start, boolean bgDataReload, Event cause) {
|
||||||
log.debug("Starting calculation thread: " + from);
|
log.debug("Starting calculation thread: " + from);
|
||||||
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||||
thread = new IobCobThread(this, from, bgDataReload, cause);
|
thread = new IobCobThread(this, from, start, bgDataReload, cause);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onNewProfile(EventNewBasalProfile ev) {
|
public void onNewProfile(EventNewBasalProfile ev) {
|
||||||
|
if (this != getPlugin()) {
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (MainApp.getConfigBuilder() == null)
|
if (MainApp.getConfigBuilder() == null)
|
||||||
return; // app still initializing
|
return; // app still initializing
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||||
|
@ -566,11 +578,15 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
iobTable = new LongSparseArray<>();
|
iobTable = new LongSparseArray<>();
|
||||||
autosensDataTable = new LongSparseArray<>();
|
autosensDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onNewProfile", false, ev);
|
runCalculation("onNewProfile", System.currentTimeMillis(), false, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventPreferenceChange(EventPreferenceChange ev) {
|
public void onEventPreferenceChange(EventPreferenceChange ev) {
|
||||||
|
if (this != getPlugin()) {
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (ev.isChanged(R.string.key_openapsama_autosens_period) ||
|
if (ev.isChanged(R.string.key_openapsama_autosens_period) ||
|
||||||
ev.isChanged(R.string.key_age) ||
|
ev.isChanged(R.string.key_age) ||
|
||||||
ev.isChanged(R.string.key_absorption_maxtime)
|
ev.isChanged(R.string.key_absorption_maxtime)
|
||||||
|
@ -581,24 +597,32 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
iobTable = new LongSparseArray<>();
|
iobTable = new LongSparseArray<>();
|
||||||
autosensDataTable = new LongSparseArray<>();
|
autosensDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onEventPreferenceChange", false, ev);
|
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, ev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventConfigBuilderChange(EventConfigBuilderChange ev) {
|
public void onEventConfigBuilderChange(EventConfigBuilderChange ev) {
|
||||||
|
if (this != getPlugin()) {
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
stopCalculation("onEventConfigBuilderChange");
|
stopCalculation("onEventConfigBuilderChange");
|
||||||
synchronized (dataLock) {
|
synchronized (dataLock) {
|
||||||
log.debug("Invalidating cached data because of configuration change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
log.debug("Invalidating cached data because of configuration change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||||
iobTable = new LongSparseArray<>();
|
iobTable = new LongSparseArray<>();
|
||||||
autosensDataTable = new LongSparseArray<>();
|
autosensDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onEventConfigBuilderChange", false, ev);
|
runCalculation("onEventConfigBuilderChange", System.currentTimeMillis(), false, ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onEventNewHistoryData(EventNewHistoryData ev) {
|
public void onEventNewHistoryData(EventNewHistoryData ev) {
|
||||||
|
if (this != getPlugin()) {
|
||||||
|
log.debug("Ignoring event for non default instance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
//log.debug("Locking onNewHistoryData");
|
//log.debug("Locking onNewHistoryData");
|
||||||
stopCalculation("onEventNewHistoryData");
|
stopCalculation("onEventNewHistoryData");
|
||||||
synchronized (dataLock) {
|
synchronized (dataLock) {
|
||||||
|
@ -633,7 +657,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
runCalculation("onEventNewHistoryData", false, ev);
|
runCalculation("onEventNewHistoryData", System.currentTimeMillis(), false, ev);
|
||||||
//log.debug("Releasing onNewHistoryData");
|
//log.debug("Releasing onNewHistoryData");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,16 +33,18 @@ public class IobCobThread extends Thread {
|
||||||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||||
private boolean bgDataReload;
|
private boolean bgDataReload;
|
||||||
private String from;
|
private String from;
|
||||||
|
private long start;
|
||||||
|
|
||||||
private PowerManager.WakeLock mWakeLock;
|
private PowerManager.WakeLock mWakeLock;
|
||||||
|
|
||||||
public IobCobThread(IobCobCalculatorPlugin plugin, String from, boolean bgDataReload, Event cause) {
|
public IobCobThread(IobCobCalculatorPlugin plugin, String from, long start, boolean bgDataReload, Event cause) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.iobCobCalculatorPlugin = plugin;
|
this.iobCobCalculatorPlugin = plugin;
|
||||||
this.bgDataReload = bgDataReload;
|
this.bgDataReload = bgDataReload;
|
||||||
this.from = from;
|
this.from = from;
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
|
this.start = start;
|
||||||
|
|
||||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
|
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
|
||||||
|
@ -68,7 +70,7 @@ public class IobCobThread extends Thread {
|
||||||
|
|
||||||
synchronized (dataLock) {
|
synchronized (dataLock) {
|
||||||
if (bgDataReload) {
|
if (bgDataReload) {
|
||||||
iobCobCalculatorPlugin.loadBgData();
|
iobCobCalculatorPlugin.loadBgData(start);
|
||||||
iobCobCalculatorPlugin.createBucketedData();
|
iobCobCalculatorPlugin.createBucketedData();
|
||||||
}
|
}
|
||||||
List<BgReading> bucketed_data = iobCobCalculatorPlugin.getBucketedData();
|
List<BgReading> bucketed_data = iobCobCalculatorPlugin.getBucketedData();
|
||||||
|
|
Loading…
Add table
Reference in a new issue