getLastAutosensData improvement and logging
This commit is contained in:
parent
5a00b68f68
commit
7fdc146b91
9 changed files with 55 additions and 15 deletions
|
@ -69,7 +69,7 @@ public class QuickWizardEntry {
|
||||||
return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo();
|
return Profile.secondsFromMidnight() >= validFrom() && Profile.secondsFromMidnight() <= validTo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BolusWizard doCalc(Profile profile, TempTarget tempTarget, BgReading lastBG) {
|
public BolusWizard doCalc(Profile profile, TempTarget tempTarget, BgReading lastBG, boolean _synchronized) {
|
||||||
BolusWizard wizard = new BolusWizard();
|
BolusWizard wizard = new BolusWizard();
|
||||||
|
|
||||||
//BG
|
//BG
|
||||||
|
@ -80,7 +80,12 @@ public class QuickWizardEntry {
|
||||||
|
|
||||||
// COB
|
// COB
|
||||||
double cob = 0d;
|
double cob = 0d;
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData();
|
AutosensData autosensData;
|
||||||
|
if (_synchronized)
|
||||||
|
autosensData = IobCobCalculatorPlugin.getLastAutosensDataSynchronized("QuickWizard COB");
|
||||||
|
else
|
||||||
|
autosensData = IobCobCalculatorPlugin.getLastAutosensData("QuickWizard COB");
|
||||||
|
|
||||||
if (autosensData != null && useCOB() == YES) {
|
if (autosensData != null && useCOB() == YES) {
|
||||||
cob = autosensData.cob;
|
cob = autosensData.cob;
|
||||||
}
|
}
|
||||||
|
|
|
@ -547,7 +547,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
} else {
|
} else {
|
||||||
if (time > now) {
|
if (time > now) {
|
||||||
// data may not be calculated yet, use last data
|
// data may not be calculated yet, use last data
|
||||||
return getLastAutosensData();
|
return getLastAutosensData("getAutosensData");
|
||||||
}
|
}
|
||||||
//log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString());
|
//log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString());
|
||||||
return null;
|
return null;
|
||||||
|
@ -556,13 +556,35 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static AutosensData getLastAutosensData() {
|
public static AutosensData getLastAutosensDataSynchronized(String reason) {
|
||||||
if (autosensDataTable.size() < 1)
|
synchronized (dataLock) {
|
||||||
|
return getLastAutosensData(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static AutosensData getLastAutosensData(String reason) {
|
||||||
|
if (autosensDataTable.size() < 1) {
|
||||||
|
log.debug("AUTOSENSDATA null: autosensDataTable empty (" + reason + ")");
|
||||||
return null;
|
return null;
|
||||||
AutosensData data = autosensDataTable.valueAt(autosensDataTable.size() - 1);
|
}
|
||||||
|
AutosensData data = null;
|
||||||
|
try {
|
||||||
|
data = autosensDataTable.valueAt(autosensDataTable.size() - 1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// data can be processed on the background
|
||||||
|
// in this rare case better return null and do not block UI
|
||||||
|
// APS plugin should use getLastAutosensDataSynchronized where the blocking is not an issue
|
||||||
|
log.debug("AUTOSENSDATA null: Exception catched (" + reason + ")");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
if (data.time < System.currentTimeMillis() - 11 * 60 * 1000) {
|
if (data.time < System.currentTimeMillis() - 11 * 60 * 1000) {
|
||||||
|
log.debug("AUTOSENSDATA null: data is old (" + reason + ")");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
|
if (data == null)
|
||||||
|
log.debug("AUTOSENSDATA null: data == null (" + " " + reason + ")");
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,7 @@ import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
|
@ -151,6 +152,18 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventAutosensCalculationFinished e) {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null)
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
calculateInsulin();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
final private TextWatcher textWatcher = new TextWatcher() {
|
final private TextWatcher textWatcher = new TextWatcher() {
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
|
@ -459,7 +472,7 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
|
||||||
// COB
|
// COB
|
||||||
Double c_cob = 0d;
|
Double c_cob = 0d;
|
||||||
if (cobCheckbox.isChecked()) {
|
if (cobCheckbox.isChecked()) {
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData();
|
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData("Wizard COB");
|
||||||
|
|
||||||
if(autosensData != null) {
|
if(autosensData != null) {
|
||||||
c_cob = autosensData.cob;
|
c_cob = autosensData.cob;
|
||||||
|
|
|
@ -640,7 +640,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
|
final QuickWizardEntry quickWizardEntry = OverviewPlugin.getPlugin().quickWizard.getActive();
|
||||||
if (quickWizardEntry != null && actualBg != null) {
|
if (quickWizardEntry != null && actualBg != null) {
|
||||||
quickWizardButton.setVisibility(View.VISIBLE);
|
quickWizardButton.setVisibility(View.VISIBLE);
|
||||||
final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg);
|
final BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, actualBg, true);
|
||||||
|
|
||||||
final JSONObject boluscalcJSON = new JSONObject();
|
final JSONObject boluscalcJSON = new JSONObject();
|
||||||
try {
|
try {
|
||||||
|
@ -1135,7 +1135,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
|
if (quickWizardEntry != null && lastBG != null && pump.isInitialized() && !pump.isSuspended()) {
|
||||||
quickWizardButton.setVisibility(View.VISIBLE);
|
quickWizardButton.setVisibility(View.VISIBLE);
|
||||||
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
String text = quickWizardEntry.buttonText() + "\n" + DecimalFormatter.to0Decimal(quickWizardEntry.carbs()) + "g";
|
||||||
BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, lastBG);
|
BolusWizard wizard = quickWizardEntry.doCalc(profile, tempTarget, lastBG, false);
|
||||||
text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U";
|
text += " " + DecimalFormatter.to2Decimal(wizard.calculatedTotalInsulin) + "U";
|
||||||
quickWizardButton.setText(text);
|
quickWizardButton.setText(text);
|
||||||
if (wizard.calculatedTotalInsulin <= 0)
|
if (wizard.calculatedTotalInsulin <= 0)
|
||||||
|
@ -1201,7 +1201,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
// cob
|
// cob
|
||||||
if (cobView != null) { // view must not exists
|
if (cobView != null) { // view must not exists
|
||||||
String cobText = "";
|
String cobText = "";
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData();
|
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData("Overview COB");
|
||||||
if (autosensData != null)
|
if (autosensData != null)
|
||||||
cobText = (int) autosensData.cob + " g";
|
cobText = (int) autosensData.cob + " g";
|
||||||
cobView.setText(cobText);
|
cobView.setText(cobText);
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class SensitivityAAPSPlugin implements PluginBase, SensitivityInterface{
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime);
|
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
log.debug("No autosens data available");
|
log.debug("No autosens data available");
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class SensitivityOref0Plugin implements PluginBase, SensitivityInterface
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
AutosensData current = IobCobCalculatorPlugin.getLastAutosensData();
|
AutosensData current = IobCobCalculatorPlugin.getLastAutosensData("SensitivityOref0"); // this is running inside lock already
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
log.debug("No current autosens data available");
|
log.debug("No current autosens data available");
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
|
|
|
@ -116,7 +116,7 @@ public class SensitivityWeightedAveragePlugin implements PluginBase, Sensitivity
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime);
|
AutosensData current = IobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
if (Config.logAutosensData)
|
if (Config.logAutosensData)
|
||||||
log.debug("No autosens data available");
|
log.debug("No autosens data available");
|
||||||
|
|
|
@ -251,7 +251,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData();
|
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensDataSynchronized("getMealData()");
|
||||||
if (autosensData != null) {
|
if (autosensData != null) {
|
||||||
result.mealCOB = autosensData.cob;
|
result.mealCOB = autosensData.cob;
|
||||||
}
|
}
|
||||||
|
|
|
@ -654,7 +654,7 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
private String generateCOBString() {
|
private String generateCOBString() {
|
||||||
|
|
||||||
String cobStringResult = "--";
|
String cobStringResult = "--";
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData();
|
AutosensData autosensData = IobCobCalculatorPlugin.getLastAutosensData("WatcherUpdaterService");
|
||||||
if (autosensData != null) {
|
if (autosensData != null) {
|
||||||
cobStringResult = (int) autosensData.cob + "g";
|
cobStringResult = (int) autosensData.cob + "g";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue