run calculation after interval change
This commit is contained in:
parent
4cdadaf0c4
commit
bf6e3a9061
4 changed files with 48 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
package info.nightscout.androidaps;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
|
@ -8,6 +9,7 @@ import android.widget.CheckBox;
|
|||
import android.widget.SeekBar;
|
||||
|
||||
import com.jjoe64.graphview.GraphView;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -19,9 +21,11 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import butterknife.OnLongClick;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.events.EventCustomCalculationFinished;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.graphData.GraphData;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
@ -59,6 +63,8 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
EventCustomCalculationFinished eventCustomCalculationFinished = new EventCustomCalculationFinished();
|
||||
|
||||
public HistoryBrowseActivity() {
|
||||
iobCobCalculatorPlugin = new IobCobCalculatorPlugin();
|
||||
}
|
||||
|
@ -104,12 +110,16 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
void onClickLeft() {
|
||||
start -= rangeToDisplay * 60 * 60 * 1000L;
|
||||
updateGUI("left");
|
||||
iobCobCalculatorPlugin.clearCache();
|
||||
iobCobCalculatorPlugin.runCalculation("onClickLeft", start, true, eventCustomCalculationFinished);
|
||||
}
|
||||
|
||||
@OnClick(R.id.historybrowse_right)
|
||||
void onClickRight() {
|
||||
start += rangeToDisplay * 60 * 60 * 1000L;
|
||||
updateGUI("right");
|
||||
iobCobCalculatorPlugin.clearCache();
|
||||
iobCobCalculatorPlugin.runCalculation("onClickRight", start, true, eventCustomCalculationFinished);
|
||||
}
|
||||
|
||||
@OnClick(R.id.historybrowse_end)
|
||||
|
@ -122,6 +132,8 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
start = calendar.getTimeInMillis();
|
||||
updateGUI("resetToMidnight");
|
||||
iobCobCalculatorPlugin.clearCache();
|
||||
iobCobCalculatorPlugin.runCalculation("onClickEnd", start, true, eventCustomCalculationFinished);
|
||||
}
|
||||
|
||||
@OnClick(R.id.historybrowse_zoom)
|
||||
|
@ -141,6 +153,8 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
start = calendar.getTimeInMillis();
|
||||
updateGUI("resetToMidnight");
|
||||
iobCobCalculatorPlugin.clearCache();
|
||||
iobCobCalculatorPlugin.runCalculation("onLongClickZoom", start, true, eventCustomCalculationFinished);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -152,11 +166,23 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
void onClickDate(View view) {
|
||||
//((CheckBox) view).toggle();
|
||||
updateGUI("checkboxToggle");
|
||||
iobCobCalculatorPlugin.clearCache();
|
||||
iobCobCalculatorPlugin.runCalculation("onClickDate", start, true, eventCustomCalculationFinished);
|
||||
}
|
||||
|
||||
|
||||
void loadData() {
|
||||
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
||||
Activity activity = this;
|
||||
if (activity != null && e.cause == eventCustomCalculationFinished) {
|
||||
log.debug("EventAutosensCalculationFinished");
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateGUI("EventAutosensCalculationFinished");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void updateGUI(String from) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 13.02.2018.
|
||||
*/
|
||||
|
||||
public class EventCustomCalculationFinished extends Event {
|
||||
}
|
|
@ -484,7 +484,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return array;
|
||||
}
|
||||
|
||||
public IobTotal[] calculateIobArrayForSMB() {
|
||||
public IobTotal[] calculateIobArrayForSMB() {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
// predict IOB out to DIA plus 30m
|
||||
long time = System.currentTimeMillis();
|
||||
|
@ -549,7 +549,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
private void runCalculation(String from, long start, boolean bgDataReload, Event cause) {
|
||||
public void runCalculation(String from, long start, boolean bgDataReload, Event cause) {
|
||||
log.debug("Starting calculation thread: " + from);
|
||||
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||
thread = new IobCobThread(this, from, start, bgDataReload, cause);
|
||||
|
@ -661,6 +661,14 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
//log.debug("Releasing onNewHistoryData");
|
||||
}
|
||||
|
||||
public void clearCache() {
|
||||
synchronized (dataLock) {
|
||||
log.debug("Clearing cached data.");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
}
|
||||
|
||||
// From https://gist.github.com/IceCreamYou/6ffa1b18c4c8f6aeaad2
|
||||
// Returns the value at a given percentile in a sorted numeric array.
|
||||
// "Linear interpolation between closest ranks" method
|
||||
|
|
|
@ -21,6 +21,7 @@ import info.nightscout.androidaps.db.Treatment;
|
|||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.queue.QueueThread;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
/**
|
||||
* Created by mike on 23.01.2018.
|
||||
|
@ -231,6 +232,7 @@ public class IobCobThread extends Thread {
|
|||
|
||||
previous = autosensData;
|
||||
autosensDataTable.put(bgTime, autosensData);
|
||||
log.debug("Running detectSensitivity from: " + DateUtil.dateAndTimeString(oldestTimeWithData) + " to: " + DateUtil.dateAndTimeString(bgTime));
|
||||
autosensData.autosensRatio = iobCobCalculatorPlugin.detectSensitivity(oldestTimeWithData, bgTime).ratio;
|
||||
if (Config.logAutosensData)
|
||||
log.debug(autosensData.log(bgTime));
|
||||
|
|
Loading…
Reference in a new issue