Merge branch 'dev' into smb-wear2
This commit is contained in:
commit
a23c76f473
24 changed files with 181 additions and 77 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,8 +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;
|
||||
|
@ -56,6 +61,14 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
private int rangeToDisplay = 24; // for graph
|
||||
private long start;
|
||||
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
EventCustomCalculationFinished eventCustomCalculationFinished = new EventCustomCalculationFinished();
|
||||
|
||||
public HistoryBrowseActivity() {
|
||||
iobCobCalculatorPlugin = new IobCobCalculatorPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -97,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)
|
||||
|
@ -115,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)
|
||||
|
@ -134,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;
|
||||
}
|
||||
|
||||
|
@ -145,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) {
|
||||
|
@ -195,7 +228,7 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
|
||||
// ------------------ 1st graph
|
||||
|
||||
final GraphData graphData = new GraphData(bgGraph);
|
||||
final GraphData graphData = new GraphData(bgGraph, IobCobCalculatorPlugin.getPlugin());
|
||||
|
||||
// **** In range Area ****
|
||||
graphData.addInRangeArea(fromTime, toTime, lowLine, highLine);
|
||||
|
@ -223,7 +256,7 @@ public class HistoryBrowseActivity extends AppCompatActivity {
|
|||
|
||||
// ------------------ 2nd graph
|
||||
|
||||
final GraphData secondGraphData = new GraphData(iobGraph);
|
||||
final GraphData secondGraphData = new GraphData(iobGraph, iobCobCalculatorPlugin);
|
||||
|
||||
boolean useIobForScale = false;
|
||||
boolean useCobForScale = false;
|
||||
|
|
|
@ -600,7 +600,8 @@ public class DataService extends IntentService {
|
|||
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.ANNOUNCEMENT)) {
|
||||
long date = trJson.getLong("mills");
|
||||
long now = System.currentTimeMillis();
|
||||
if (date > now - 15 * 60 * 1000L && trJson.has("notes")) {
|
||||
if (date > now - 15 * 60 * 1000L && trJson.has("notes")
|
||||
&& !(trJson.has("enteredBy") && trJson.getString("enteredBy").equals(SP.getString("careportal_enteredby", "AndroidAPS")))) {
|
||||
Notification announcement = new Notification(Notification.NSANNOUNCEMENT, trJson.getString("notes"), Notification.ANNOUNCEMENT, 60);
|
||||
MainApp.bus().post(new EventNewNotification(announcement));
|
||||
}
|
||||
|
|
|
@ -82,9 +82,9 @@ public class QuickWizardEntry {
|
|||
double cob = 0d;
|
||||
AutosensData autosensData;
|
||||
if (_synchronized)
|
||||
autosensData = IobCobCalculatorPlugin.getLastAutosensDataSynchronized("QuickWizard COB");
|
||||
autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("QuickWizard COB");
|
||||
else
|
||||
autosensData = IobCobCalculatorPlugin.getLastAutosensData("QuickWizard COB");
|
||||
autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("QuickWizard COB");
|
||||
|
||||
if (autosensData != null && useCOB() == YES) {
|
||||
cob = autosensData.cob;
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.graphics.Color;
|
|||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -184,7 +185,7 @@ public class CareportalEvent implements DataPointWithLabelInterface {
|
|||
try {
|
||||
JSONObject object = new JSONObject(json);
|
||||
if (object.has("notes"))
|
||||
return object.getString("notes");
|
||||
return StringUtils.abbreviate(object.getString("notes"), 40);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package info.nightscout.androidaps.events;
|
||||
|
||||
/**
|
||||
* Created by mike on 13.02.2018.
|
||||
*/
|
||||
|
||||
public class EventCustomCalculationFinished extends Event {
|
||||
}
|
|
@ -41,19 +41,19 @@ import info.nightscout.utils.DateUtil;
|
|||
public class IobCobCalculatorPlugin implements PluginBase {
|
||||
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
|
||||
|
||||
private static LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private static LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private static LongSparseArray<BasalData> basalDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||
private LongSparseArray<BasalData> basalDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||
|
||||
private static volatile List<BgReading> bgReadings = null; // newest at index 0
|
||||
private static volatile List<BgReading> bucketed_data = null;
|
||||
private volatile List<BgReading> bgReadings = null; // newest at index 0
|
||||
private volatile List<BgReading> bucketed_data = null;
|
||||
|
||||
private static double dia = Constants.defaultDIA;
|
||||
private double dia = Constants.defaultDIA;
|
||||
|
||||
static final Object dataLock = new Object();
|
||||
final Object dataLock = new Object();
|
||||
|
||||
boolean stopCalculationTrigger = false;
|
||||
IobCobThread thread = null;
|
||||
private IobCobThread thread = null;
|
||||
|
||||
private static IobCobCalculatorPlugin plugin = null;
|
||||
|
||||
|
@ -63,11 +63,11 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return plugin;
|
||||
}
|
||||
|
||||
public static LongSparseArray<AutosensData> getAutosensDataTable() {
|
||||
public LongSparseArray<AutosensData> getAutosensDataTable() {
|
||||
return autosensDataTable;
|
||||
}
|
||||
|
||||
public static List<BgReading> getBucketedData() {
|
||||
public List<BgReading> getBucketedData() {
|
||||
return bucketed_data;
|
||||
}
|
||||
|
||||
|
@ -131,12 +131,12 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return -1;
|
||||
}
|
||||
|
||||
private IobCobCalculatorPlugin() {
|
||||
public IobCobCalculatorPlugin() {
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static List<BgReading> getBucketedData(long fromTime) {
|
||||
public List<BgReading> getBucketedData(long fromTime) {
|
||||
//log.debug("Locking getBucketedData");
|
||||
synchronized (dataLock) {
|
||||
if (bucketed_data == null) {
|
||||
|
@ -154,7 +154,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
private static int indexNewerThan(long time) {
|
||||
private int indexNewerThan(long time) {
|
||||
for (int index = 0; index < bucketed_data.size(); index++) {
|
||||
if (bucketed_data.get(index).date < time)
|
||||
return index - 1;
|
||||
|
@ -169,9 +169,9 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return rouded;
|
||||
}
|
||||
|
||||
void loadBgData() {
|
||||
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + dia)), false);
|
||||
log.debug("BG data loaded. Size: " + bgReadings.size());
|
||||
void loadBgData(long start) {
|
||||
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (start - 60 * 60 * 1000L * (24 + dia)), false);
|
||||
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
|
||||
}
|
||||
|
||||
private boolean isAbout5minData() {
|
||||
|
@ -332,13 +332,13 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return getBGDataFrom;
|
||||
}
|
||||
|
||||
public static IobTotal calculateFromTreatmentsAndTempsSynchronized(long time) {
|
||||
public IobTotal calculateFromTreatmentsAndTempsSynchronized(long time) {
|
||||
synchronized (dataLock) {
|
||||
return calculateFromTreatmentsAndTemps(time);
|
||||
}
|
||||
}
|
||||
|
||||
public static IobTotal calculateFromTreatmentsAndTemps(long time) {
|
||||
public IobTotal calculateFromTreatmentsAndTemps(long time) {
|
||||
long now = System.currentTimeMillis();
|
||||
time = roundUpTime(time);
|
||||
if (time < now && iobTable.get(time) != null) {
|
||||
|
@ -373,7 +373,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private static Long findPreviousTimeFromBucketedData(long time) {
|
||||
private Long findPreviousTimeFromBucketedData(long time) {
|
||||
if (bucketed_data == null)
|
||||
return null;
|
||||
for (int index = 0; index < bucketed_data.size(); index++) {
|
||||
|
@ -383,7 +383,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static BasalData getBasalData(long time) {
|
||||
public BasalData getBasalData(long time) {
|
||||
long now = System.currentTimeMillis();
|
||||
time = roundUpTime(time);
|
||||
BasalData retval = basalDataTable.get(time);
|
||||
|
@ -409,7 +409,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public static AutosensData getAutosensData(long time) {
|
||||
public AutosensData getAutosensData(long time) {
|
||||
synchronized (dataLock) {
|
||||
long now = System.currentTimeMillis();
|
||||
if (time > now)
|
||||
|
@ -434,7 +434,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public static AutosensData getLastAutosensDataSynchronized(String reason) {
|
||||
public AutosensData getLastAutosensDataSynchronized(String reason) {
|
||||
synchronized (dataLock) {
|
||||
return getLastAutosensData(reason);
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
|
||||
|
||||
@Nullable
|
||||
public static AutosensData getLastAutosensData(String reason) {
|
||||
public AutosensData getLastAutosensData(String reason) {
|
||||
if (autosensDataTable.size() < 1) {
|
||||
log.debug("AUTOSENSDATA null: autosensDataTable empty (" + reason + ")");
|
||||
return null;
|
||||
|
@ -467,7 +467,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
public static IobTotal[] calculateIobArrayInDia() {
|
||||
public IobTotal[] calculateIobArrayInDia() {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
// predict IOB out to DIA plus 30m
|
||||
long time = System.currentTimeMillis();
|
||||
|
@ -484,7 +484,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return array;
|
||||
}
|
||||
|
||||
public static IobTotal[] calculateIobArrayForSMB() {
|
||||
public IobTotal[] calculateIobArrayForSMB() {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
// predict IOB out to DIA plus 30m
|
||||
long time = System.currentTimeMillis();
|
||||
|
@ -501,7 +501,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
return array;
|
||||
}
|
||||
|
||||
public static AutosensResult detectSensitivityWithLock(long fromTime, long toTime) {
|
||||
public AutosensResult detectSensitivityWithLock(long fromTime, long toTime) {
|
||||
synchronized (dataLock) {
|
||||
return detectSensitivity(fromTime, toTime);
|
||||
}
|
||||
|
@ -521,13 +521,21 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
|
||||
@Subscribe
|
||||
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
|
||||
public void onEventNewBG(EventNewBG ev) {
|
||||
if (this != getPlugin()) {
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
stopCalculation("onEventNewBG");
|
||||
runCalculation("onEventNewBG", true, ev);
|
||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, ev);
|
||||
}
|
||||
|
||||
private void stopCalculation(String from) {
|
||||
|
@ -541,16 +549,20 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
private void runCalculation(String from, 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, bgDataReload, cause);
|
||||
thread = new IobCobThread(this, from, start, bgDataReload, cause);
|
||||
thread.start();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onNewProfile(EventNewBasalProfile ev) {
|
||||
if (this != getPlugin()) {
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (MainApp.getConfigBuilder() == null)
|
||||
return; // app still initializing
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
@ -566,11 +578,15 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onNewProfile", false, ev);
|
||||
runCalculation("onNewProfile", System.currentTimeMillis(), false, ev);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
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) ||
|
||||
ev.isChanged(R.string.key_age) ||
|
||||
ev.isChanged(R.string.key_absorption_maxtime)
|
||||
|
@ -581,24 +597,32 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
runCalculation("onEventPreferenceChange", false, ev);
|
||||
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, ev);
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEventConfigBuilderChange(EventConfigBuilderChange ev) {
|
||||
if (this != getPlugin()) {
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
stopCalculation("onEventConfigBuilderChange");
|
||||
synchronized (dataLock) {
|
||||
log.debug("Invalidating cached data because of configuration change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
iobTable = 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
|
||||
@Subscribe
|
||||
public void onEventNewHistoryData(EventNewHistoryData ev) {
|
||||
if (this != getPlugin()) {
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
//log.debug("Locking onNewHistoryData");
|
||||
stopCalculation("onEventNewHistoryData");
|
||||
synchronized (dataLock) {
|
||||
|
@ -633,10 +657,18 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
runCalculation("onEventNewHistoryData", false, ev);
|
||||
runCalculation("onEventNewHistoryData", System.currentTimeMillis(), false, ev);
|
||||
//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,10 +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 static info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin.getBucketedData;
|
||||
import static info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin.oldestDataAvailable;
|
||||
import static info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin.roundUpTime;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
/**
|
||||
* Created by mike on 23.01.2018.
|
||||
|
@ -37,16 +34,18 @@ public class IobCobThread extends Thread {
|
|||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
private boolean bgDataReload;
|
||||
private String from;
|
||||
private long start;
|
||||
|
||||
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();
|
||||
|
||||
this.iobCobCalculatorPlugin = plugin;
|
||||
this.bgDataReload = bgDataReload;
|
||||
this.from = from;
|
||||
this.cause = cause;
|
||||
this.start = start;
|
||||
|
||||
PowerManager powerManager = (PowerManager) MainApp.instance().getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||
mWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "iobCobThread");
|
||||
|
@ -68,14 +67,14 @@ public class IobCobThread extends Thread {
|
|||
|
||||
Object dataLock = iobCobCalculatorPlugin.dataLock;
|
||||
|
||||
long oldestTimeWithData = oldestDataAvailable();
|
||||
long oldestTimeWithData = iobCobCalculatorPlugin.oldestDataAvailable();
|
||||
|
||||
synchronized (dataLock) {
|
||||
if (bgDataReload) {
|
||||
iobCobCalculatorPlugin.loadBgData();
|
||||
iobCobCalculatorPlugin.loadBgData(start);
|
||||
iobCobCalculatorPlugin.createBucketedData();
|
||||
}
|
||||
List<BgReading> bucketed_data = getBucketedData();
|
||||
List<BgReading> bucketed_data = iobCobCalculatorPlugin.getBucketedData();
|
||||
LongSparseArray<AutosensData> autosensDataTable = iobCobCalculatorPlugin.getAutosensDataTable();
|
||||
|
||||
if (bucketed_data == null || bucketed_data.size() < 3) {
|
||||
|
@ -83,7 +82,7 @@ public class IobCobThread extends Thread {
|
|||
return;
|
||||
}
|
||||
|
||||
long prevDataTime = roundUpTime(bucketed_data.get(bucketed_data.size() - 3).date);
|
||||
long prevDataTime = iobCobCalculatorPlugin.roundUpTime(bucketed_data.get(bucketed_data.size() - 3).date);
|
||||
log.debug("Prev data time: " + new Date(prevDataTime).toLocaleString());
|
||||
AutosensData previous = autosensDataTable.get(prevDataTime);
|
||||
// start from oldest to be able sub cob
|
||||
|
@ -95,7 +94,7 @@ public class IobCobThread extends Thread {
|
|||
}
|
||||
// check if data already exists
|
||||
long bgTime = bucketed_data.get(i).date;
|
||||
bgTime = roundUpTime(bgTime);
|
||||
bgTime = iobCobCalculatorPlugin.roundUpTime(bgTime);
|
||||
if (bgTime > System.currentTimeMillis())
|
||||
continue;
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile(bgTime);
|
||||
|
@ -233,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));
|
||||
|
|
|
@ -183,7 +183,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
|||
|
||||
Date start = new Date();
|
||||
Date startPart = new Date();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.calculateIobArrayInDia();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia();
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = new Date();
|
||||
|
@ -222,7 +222,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
|||
|
||||
startPart = new Date();
|
||||
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
||||
lastAutosensResult = IobCobCalculatorPlugin.detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||
} else {
|
||||
lastAutosensResult = new AutosensResult();
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
|||
|
||||
Date start = new Date();
|
||||
Date startPart = new Date();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.calculateIobArrayForSMB();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB();
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = new Date();
|
||||
|
@ -224,7 +224,7 @@ public class OpenAPSSMBPlugin implements PluginBase, APSInterface {
|
|||
|
||||
startPart = new Date();
|
||||
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
||||
lastAutosensResult = IobCobCalculatorPlugin.detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||
} else {
|
||||
lastAutosensResult = new AutosensResult();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,10 @@ package info.nightscout.androidaps.plugins.Overview.Dialogs;
|
|||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
public class ErrorHelperActivity extends AppCompatActivity {
|
||||
public ErrorHelperActivity() {
|
||||
super();
|
||||
|
@ -17,5 +21,9 @@ public class ErrorHelperActivity extends AppCompatActivity {
|
|||
errorDialog.setSound(getIntent().getIntExtra("soundid", 0));
|
||||
errorDialog.setTitle(getIntent().getStringExtra("title"));
|
||||
errorDialog.show(this.getSupportFragmentManager(), "Error");
|
||||
|
||||
if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
||||
NSUpload.uploadError(getIntent().getStringExtra("status"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -476,7 +476,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
|||
// COB
|
||||
Double c_cob = 0d;
|
||||
if (cobCheckbox.isChecked()) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData("Wizard COB");
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Wizard COB");
|
||||
|
||||
if(autosensData != null) {
|
||||
c_cob = autosensData.cob;
|
||||
|
|
|
@ -1276,7 +1276,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
// cob
|
||||
if (cobView != null) { // view must not exists
|
||||
String cobText = "";
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData("Overview COB");
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Overview COB");
|
||||
if (autosensData != null)
|
||||
cobText = (int) autosensData.cob + " g";
|
||||
cobView.setText(cobText);
|
||||
|
@ -1362,7 +1362,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
// ------------------ 1st graph
|
||||
Profiler.log(log, from + " - 1st graph - START", updateGUIStart);
|
||||
|
||||
final GraphData graphData = new GraphData(bgGraph);
|
||||
final GraphData graphData = new GraphData(bgGraph, IobCobCalculatorPlugin.getPlugin());
|
||||
|
||||
// **** In range Area ****
|
||||
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
||||
|
@ -1393,7 +1393,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
|||
// ------------------ 2nd graph
|
||||
Profiler.log(log, from + " - 2nd graph - START", updateGUIStart);
|
||||
|
||||
final GraphData secondGraphData = new GraphData(iobGraph);
|
||||
final GraphData secondGraphData = new GraphData(iobGraph, IobCobCalculatorPlugin.getPlugin());
|
||||
|
||||
boolean useIobForScale = false;
|
||||
boolean useCobForScale = false;
|
||||
|
|
|
@ -53,9 +53,12 @@ public class GraphData {
|
|||
private String units;
|
||||
private List<Series> series = new ArrayList<>();
|
||||
|
||||
public GraphData(GraphView graph) {
|
||||
private IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
public GraphData(GraphView graph, IobCobCalculatorPlugin iobCobCalculatorPlugin) {
|
||||
units = MainApp.getConfigBuilder().getProfileUnits();
|
||||
this.graph = graph;
|
||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
||||
}
|
||||
|
||||
public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, APSResult apsResult) {
|
||||
|
@ -129,7 +132,7 @@ public class GraphData {
|
|||
double lastBaseBasal = 0;
|
||||
double lastTempBasal = 0;
|
||||
for (long time = fromTime; time < toTime; time += 60 * 1000L) {
|
||||
BasalData basalData = IobCobCalculatorPlugin.getBasalData(time);
|
||||
BasalData basalData = IobCobCalculatorPlugin.getPlugin().getBasalData(time);
|
||||
double baseBasalValue = basalData.basal;
|
||||
double absoluteLineValue = baseBasalValue;
|
||||
double tempBasalValue = 0;
|
||||
|
@ -335,7 +338,7 @@ public class GraphData {
|
|||
Scale iobScale = new Scale();
|
||||
|
||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||
double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob;
|
||||
double iob = IobCobCalculatorPlugin.getPlugin().calculateFromTreatmentsAndTempsSynchronized(time).iob;
|
||||
if (Math.abs(lastIob - iob) > 0.02) {
|
||||
if (Math.abs(lastIob - iob) > 0.2)
|
||||
iobArray.add(new ScaledDataPoint(time, lastIob, iobScale));
|
||||
|
@ -370,7 +373,7 @@ public class GraphData {
|
|||
Scale cobScale = new Scale();
|
||||
|
||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time);
|
||||
if (autosensData != null) {
|
||||
int cob = (int) autosensData.cob;
|
||||
if (cob != lastCob) {
|
||||
|
@ -417,7 +420,7 @@ public class GraphData {
|
|||
Scale devScale = new Scale();
|
||||
|
||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time);
|
||||
if (autosensData != null) {
|
||||
int color = Color.BLACK; // "="
|
||||
if (autosensData.pastSensitivity.equals("C")) color = Color.GRAY;
|
||||
|
@ -455,7 +458,7 @@ public class GraphData {
|
|||
Scale ratioScale = new Scale(-1d);
|
||||
|
||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time);
|
||||
if (autosensData != null) {
|
||||
ratioArray.add(new ScaledDataPoint(time, autosensData.autosensRatio, ratioScale));
|
||||
maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio));
|
||||
|
@ -489,7 +492,7 @@ public class GraphData {
|
|||
Scale dsMinScale = new Scale();
|
||||
|
||||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time);
|
||||
if (autosensData != null) {
|
||||
dsMaxArray.add(new ScaledDataPoint(time, autosensData.slopeFromMaxDeviation, dsMaxScale));
|
||||
dsMinArray.add(new ScaledDataPoint(time, autosensData.slopeFromMinDeviation, dsMinScale));
|
||||
|
|
|
@ -105,7 +105,7 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{
|
|||
|
||||
@Override
|
||||
public AutosensResult detectSensitivity(long fromTime, long toTime) {
|
||||
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getAutosensDataTable();
|
||||
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();
|
||||
|
||||
String age = SP.getString(R.string.key_age, "");
|
||||
int defaultHours = 24;
|
||||
|
@ -119,7 +119,7 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{
|
|||
return new AutosensResult();
|
||||
}
|
||||
|
||||
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already
|
||||
AutosensData current = IobCobCalculatorPlugin.getPlugin().getAutosensData(toTime); // this is running inside lock already
|
||||
if (current == null) {
|
||||
log.debug("No autosens data available");
|
||||
return new AutosensResult();
|
||||
|
|
|
@ -104,7 +104,7 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface
|
|||
|
||||
@Override
|
||||
public AutosensResult detectSensitivity(long fromTime, long toTime) {
|
||||
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getAutosensDataTable();
|
||||
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();
|
||||
|
||||
String age = SP.getString(R.string.key_age, "");
|
||||
int defaultHours = 24;
|
||||
|
@ -120,7 +120,7 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface
|
|||
return new AutosensResult();
|
||||
}
|
||||
|
||||
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already
|
||||
AutosensData current = IobCobCalculatorPlugin.getPlugin().getAutosensData(toTime); // this is running inside lock already
|
||||
if (current == null) {
|
||||
log.debug("No current autosens data available");
|
||||
return new AutosensResult();
|
||||
|
|
|
@ -101,7 +101,7 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
|
||||
@Override
|
||||
public AutosensResult detectSensitivity(long fromTime, long toTime) {
|
||||
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getAutosensDataTable();
|
||||
LongSparseArray<AutosensData> autosensDataTable = IobCobCalculatorPlugin.getPlugin().getAutosensDataTable();
|
||||
|
||||
String age = SP.getString(R.string.key_age, "");
|
||||
int defaultHours = 24;
|
||||
|
@ -116,7 +116,7 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
|||
return new AutosensResult();
|
||||
}
|
||||
|
||||
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already
|
||||
AutosensData current = IobCobCalculatorPlugin.getPlugin().getAutosensData(toTime); // this is running inside lock already
|
||||
if (current == null) {
|
||||
if (Config.logAutosensData)
|
||||
log.debug("No autosens data available");
|
||||
|
|
|
@ -252,7 +252,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
|||
}
|
||||
}
|
||||
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensDataSynchronized("getMealData()");
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("getMealData()");
|
||||
if (autosensData != null) {
|
||||
result.mealCOB = autosensData.cob;
|
||||
result.slopeFromMinDeviation = autosensData.slopeFromMinDeviation;
|
||||
|
|
|
@ -663,7 +663,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
|||
private String generateCOBString() {
|
||||
|
||||
String cobStringResult = "--";
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData("WatcherUpdaterService");
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("WatcherUpdaterService");
|
||||
if (autosensData != null) {
|
||||
cobStringResult = (int) autosensData.cob + "g";
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
|
||||
/**
|
||||
* Created by adrian on 17/12/17.
|
||||
|
@ -42,6 +43,9 @@ public class LocalAlertUtils {
|
|||
n.soundId = R.raw.alarm;
|
||||
SP.putLong("nextPumpDisconnectedAlarm", System.currentTimeMillis() + pumpUnreachableThreshold());
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
||||
NSUpload.uploadError(n.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,6 +95,9 @@ public class LocalAlertUtils {
|
|||
n.soundId = R.raw.alarm;
|
||||
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + missedReadingsThreshold());
|
||||
MainApp.bus().post(new EventNewNotification(n));
|
||||
if (SP.getBoolean(R.string.key_ns_create_announcements_from_errors, true)) {
|
||||
NSUpload.uploadError(n.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -399,6 +399,7 @@ public class NSUpload {
|
|||
try {
|
||||
data.put("eventType", "Announcement");
|
||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
||||
data.put("enteredBy", SP.getString("careportal_enteredby", MainApp.gs(R.string.app_name)));
|
||||
data.put("notes", error);
|
||||
data.put("isAnnouncement", true);
|
||||
} catch (JSONException e) {
|
||||
|
|
|
@ -179,7 +179,8 @@
|
|||
<com.jjoe64.graphview.GraphView
|
||||
android:id="@+id/historyybrowse_bggraph"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="160dip" />
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<com.jjoe64.graphview.GraphView
|
||||
android:id="@+id/historybrowse_iobgraph"
|
||||
|
|
|
@ -685,7 +685,7 @@
|
|||
<string name="unsupportedfirmware">"Firmware pompe incompatible "</string>
|
||||
<string name="dexcomg5_xdripupload_title">Transmettre les données G sur xDrip+</string>
|
||||
<string name="dexcomg5_xdripupload_summary">Dans xDrip+ veuillez séléctionner 640g/Eversense comme source de données</string>
|
||||
<string name="nsclientbg">"G NSClient "</string>
|
||||
<string name="nsclientbg">"Glycémie NSClient"</string>
|
||||
<string name="minimalbasalvaluereplaced">"Valeur du basal remplacée par la valeur minimale supportée "</string>
|
||||
<string name="overview_editquickwizard_usebg">Calcul de G</string>
|
||||
<string name="overview_editquickwizard_usebolusiob">Calcul IR du Bolus</string>
|
||||
|
|
|
@ -931,5 +931,8 @@
|
|||
<string name="nav_historybrowser">History browser</string>
|
||||
<string name="wear_notifysmb_title">Notify on SMB</string>
|
||||
<string name="wear_notifysmb_summary">Show SMB on the watch like a standard bolus.</string>
|
||||
<string name="key_ns_create_announcements_from_errors">ns_create_announcements_from_errors</string>
|
||||
<string name="ns_create_announcements_from_errors_title">Create announcements from errors</string>
|
||||
<string name="ns_create_announcements_from_errors_summary">Create Nightscout announcement for error dialogs and local alerts (also viewable in Careportal under Treatments)</string>
|
||||
</resources>
|
||||
|
||||
|
|
|
@ -27,6 +27,12 @@
|
|||
android:key="@string/key_ns_logappstartedevent"
|
||||
android:title="@string/ns_logappstartedevent" />
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_ns_create_announcements_from_errors"
|
||||
android:title="@string/ns_create_announcements_from_errors_title"
|
||||
android:summary="@string/ns_create_announcements_from_errors_summary"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/key_ns_localbroadcasts"
|
||||
|
|
Loading…
Reference in a new issue