APS logging
This commit is contained in:
parent
5ef9bc7948
commit
ce9e5b9165
20 changed files with 298 additions and 354 deletions
|
@ -24,7 +24,6 @@ public class Config {
|
|||
|
||||
|
||||
public static boolean logFunctionCalls = true;
|
||||
public static boolean logAPSResult = true;
|
||||
public static boolean logPrefsChange = true;
|
||||
public static boolean logConfigBuilder = true;
|
||||
public static boolean logCongigBuilderActions = true;
|
||||
|
@ -44,5 +43,6 @@ public class Config {
|
|||
public static boolean logPump = true;
|
||||
public static boolean logPumpComm = true;
|
||||
public static boolean logPumpBtComm = false;
|
||||
public static boolean logAps = true;
|
||||
|
||||
}
|
||||
|
|
|
@ -84,4 +84,5 @@ public class Constants {
|
|||
public static final String PUMPQUEUE = "PUMPQUEUE";
|
||||
public static final String PUMPCOMM = "PUMPCOMM";
|
||||
public static final String PUMPBTCOMM = "PUMPBTCOMM";
|
||||
public static final String APS = "APS";
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.slf4j.LoggerFactory;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
|
@ -25,7 +26,7 @@ import info.nightscout.utils.DecimalFormatter;
|
|||
* Created by mike on 09.06.2016.
|
||||
*/
|
||||
public class APSResult {
|
||||
private static Logger log = LoggerFactory.getLogger(APSResult.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
public long date = 0;
|
||||
public String reason;
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "576cfd15217b0bed77d63641",
|
||||
|
@ -363,7 +365,7 @@ import org.slf4j.LoggerFactory;
|
|||
*/
|
||||
|
||||
public class DeviceStatus {
|
||||
private static Logger log = LoggerFactory.getLogger(DeviceStatus.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
public String device = null;
|
||||
public JSONObject pump = null;
|
||||
|
|
|
@ -28,8 +28,6 @@ import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
|||
import info.nightscout.utils.FabricPrivacy;
|
||||
|
||||
public class LoopFragment extends SubscriberFragment {
|
||||
private static Logger log = LoggerFactory.getLogger(LoopFragment.class);
|
||||
|
||||
@BindView(R.id.loop_run)
|
||||
Button runNowButton;
|
||||
@BindView(R.id.loop_lastrun)
|
||||
|
|
|
@ -43,24 +43,24 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensC
|
|||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopSetLastRunGui;
|
||||
import info.nightscout.androidaps.plugins.Loop.events.EventLoopUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.Loop.events.EventNewOpenLoopNotification;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.androidaps.queue.commands.Command;
|
||||
import info.nightscout.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.utils.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class LoopPlugin extends PluginBase {
|
||||
private static Logger log = LoggerFactory.getLogger(LoopPlugin.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
public static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
||||
private static final String CHANNEL_ID = "AndroidAPS-Openloop";
|
||||
|
||||
long lastBgTriggeredRun = 0;
|
||||
private long lastBgTriggeredRun = 0;
|
||||
|
||||
protected static LoopPlugin loopPlugin;
|
||||
private static LoopPlugin loopPlugin;
|
||||
|
||||
@NonNull
|
||||
public static LoopPlugin getPlugin() {
|
||||
|
@ -137,7 +137,7 @@ public class LoopPlugin extends PluginBase {
|
|||
* has current data to work with. However, autosens calculation can be triggered by multiple
|
||||
* sources and currently only a new BG should trigger a loop run. Hence we return early if
|
||||
* the event causing the calculation is not EventNewBg.
|
||||
*
|
||||
* <p>
|
||||
* Callers of {@link info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin#runCalculation(String, long, boolean, Event)}
|
||||
* are sources triggering a calculation which triggers this method upon completion.
|
||||
*/
|
||||
|
@ -254,12 +254,13 @@ public class LoopPlugin extends PluginBase {
|
|||
|
||||
public synchronized void invoke(String initiator, boolean allowNotification, boolean tempBasalFallback) {
|
||||
try {
|
||||
if (Config.logFunctionCalls)
|
||||
if (Config.logAps)
|
||||
log.debug("invoke from " + initiator);
|
||||
Constraint<Boolean> loopEnabled = MainApp.getConstraintChecker().isLoopInvokationAllowed();
|
||||
|
||||
if (!loopEnabled.value()) {
|
||||
String message = MainApp.gs(R.string.loopdisabled) + "\n" + loopEnabled.getReasons();
|
||||
if (Config.logAps)
|
||||
log.debug(message);
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(message));
|
||||
return;
|
||||
|
@ -273,6 +274,7 @@ public class LoopPlugin extends PluginBase {
|
|||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (!MainApp.getConfigBuilder().isProfileValid("Loop")) {
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected)));
|
||||
return;
|
||||
|
@ -303,6 +305,7 @@ public class LoopPlugin extends PluginBase {
|
|||
// safety check for multiple SMBs
|
||||
long lastBolusTime = TreatmentsPlugin.getPlugin().getLastBolusTime();
|
||||
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
|
||||
if (Config.logAps)
|
||||
log.debug("SMB requsted but still in 3 min interval");
|
||||
resultAfterConstraints.smb = 0;
|
||||
}
|
||||
|
@ -318,12 +321,14 @@ public class LoopPlugin extends PluginBase {
|
|||
NSUpload.uploadDeviceStatus();
|
||||
|
||||
if (isSuspended()) {
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.loopsuspended));
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.loopsuspended)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pump.isSuspended()) {
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.pumpsuspended));
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.pumpsuspended)));
|
||||
return;
|
||||
|
@ -411,7 +416,7 @@ public class LoopPlugin extends PluginBase {
|
|||
|
||||
MainApp.bus().post(new EventLoopUpdateGui());
|
||||
} finally {
|
||||
if (Config.logFunctionCalls)
|
||||
if (Config.logAps)
|
||||
log.debug("invoke end");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.javascript.Callable;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Function;
|
||||
import org.mozilla.javascript.NativeJSON;
|
||||
|
@ -35,7 +34,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
|||
import info.nightscout.utils.SP;
|
||||
|
||||
public class DetermineBasalAdapterAMAJS {
|
||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterAMAJS.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
|
||||
private ScriptReader mScriptReader = null;
|
||||
|
@ -56,13 +55,13 @@ public class DetermineBasalAdapterAMAJS {
|
|||
|
||||
private String scriptDebug = "";
|
||||
|
||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) throws IOException {
|
||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) {
|
||||
mScriptReader = scriptReader;
|
||||
}
|
||||
|
||||
public DetermineBasalResultAMA invoke() {
|
||||
|
||||
|
||||
if (Config.logAps) {
|
||||
log.debug(">>> Invoking detemine_basal <<<");
|
||||
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||
|
@ -73,6 +72,7 @@ public class DetermineBasalAdapterAMAJS {
|
|||
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||
else
|
||||
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
||||
}
|
||||
|
||||
DetermineBasalResultAMA determineBasalResultAMA = null;
|
||||
|
||||
|
@ -119,7 +119,7 @@ public class DetermineBasalAdapterAMAJS {
|
|||
|
||||
// Parse the jsResult object to a JSON-String
|
||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug("Result: " + result);
|
||||
try {
|
||||
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result));
|
||||
|
@ -127,17 +127,13 @@ public class DetermineBasalAdapterAMAJS {
|
|||
log.error("Unhandled exception", e);
|
||||
}
|
||||
} else {
|
||||
log.debug("Problem loading JS Functions");
|
||||
log.error("Problem loading JS Functions");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.debug("IOException");
|
||||
log.error("IOException");
|
||||
} catch (RhinoException e) {
|
||||
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error(e.toString());
|
||||
} catch (InstantiationException e) {
|
||||
log.error(e.toString());
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
log.error(e.toString());
|
||||
} finally {
|
||||
Context.exit();
|
||||
|
@ -265,31 +261,21 @@ public class DetermineBasalAdapterAMAJS {
|
|||
}
|
||||
|
||||
|
||||
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||
private Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||
|
||||
if (jsonObject == null) return Undefined.instance;
|
||||
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
|
||||
@Override
|
||||
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||
return objects[1];
|
||||
}
|
||||
});
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), (context, scriptable, scriptable1, objects) -> objects[1]);
|
||||
return param;
|
||||
}
|
||||
|
||||
public Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
|
||||
private Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
|
||||
//Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() {
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() {
|
||||
@Override
|
||||
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||
return objects[1];
|
||||
}
|
||||
});
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), (context, scriptable, scriptable1, objects) -> objects[1]);
|
||||
return param;
|
||||
}
|
||||
|
||||
public String readFile(String filename) throws IOException {
|
||||
private String readFile(String filename) throws IOException {
|
||||
byte[] bytes = mScriptReader.readFile(filename);
|
||||
String string = new String(bytes, "UTF-8");
|
||||
if (string.startsWith("#!/usr/bin/env node")) {
|
||||
|
|
|
@ -6,11 +6,12 @@ import org.mozilla.javascript.NativeObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
public class DetermineBasalResultAMA extends APSResult {
|
||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalResultAMA.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
private double eventualBG;
|
||||
private double snoozeBG;
|
||||
|
@ -47,7 +48,7 @@ public class DetermineBasalResultAMA extends APSResult {
|
|||
bolusRequested = false;
|
||||
}
|
||||
|
||||
public DetermineBasalResultAMA() {
|
||||
private DetermineBasalResultAMA() {
|
||||
hasPredictions = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -17,6 +16,7 @@ import org.json.JSONException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||
|
@ -26,7 +26,7 @@ import info.nightscout.utils.FabricPrivacy;
|
|||
import info.nightscout.utils.JSONFormatter;
|
||||
|
||||
public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAFragment.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
Button run;
|
||||
TextView lastRunView;
|
||||
|
@ -43,7 +43,6 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
try {
|
||||
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
|
||||
|
||||
run = (Button) view.findViewById(R.id.openapsma_run);
|
||||
|
@ -61,11 +60,6 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
|
||||
updateGUI();
|
||||
return view;
|
||||
} catch (Exception e) {
|
||||
FabricPrivacy.logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,9 +87,7 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.runOnUiThread(() -> {
|
||||
DetermineBasalResultAMA lastAPSResult = OpenAPSAMAPlugin.getPlugin().lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
|
@ -122,16 +114,13 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
|
||||
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void updateResultGUI(final String text) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.runOnUiThread(() -> {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
|
@ -142,7 +131,6 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
scriptdebugView.setText("");
|
||||
requestView.setText("");
|
||||
lastRunView.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package info.nightscout.androidaps.plugins.OpenAPSAMA;
|
||||
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
|
@ -23,6 +22,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
|
|||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
|
@ -39,7 +39,7 @@ import info.nightscout.utils.Round;
|
|||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSAMAPlugin.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
private static OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||
|
||||
|
@ -91,15 +91,11 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||
if (Config.logAps)
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
||||
try {
|
||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
@ -107,21 +103,21 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (profile == null) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEnabled(PluginType.APS)) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.openapsma_disabled));
|
||||
return;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
return;
|
||||
}
|
||||
|
@ -139,10 +135,12 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
Date start = new Date();
|
||||
Date startPart = new Date();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = new Date();
|
||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "getMealData()", startPart);
|
||||
|
||||
double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
||||
|
@ -163,7 +161,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (!HardLimits.checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA))
|
||||
return;
|
||||
if (!HardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||
if (!HardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||
return;
|
||||
if (!HardLimits.checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
||||
return;
|
||||
|
@ -184,7 +182,9 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
lastAutosensResult = new AutosensResult();
|
||||
lastAutosensResult.sensResult = "autosens disabled";
|
||||
}
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "AMA data gathering", start);
|
||||
|
||||
start = new Date();
|
||||
|
@ -200,6 +200,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
|
||||
DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke();
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "AMA calculation", start);
|
||||
// Fix bug determine basal
|
||||
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.OpenAPSMA;
|
|||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.javascript.Callable;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Function;
|
||||
import org.mozilla.javascript.NativeJSON;
|
||||
|
@ -29,9 +28,9 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
|||
import info.nightscout.utils.SP;
|
||||
|
||||
public class DetermineBasalAdapterMAJS {
|
||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
private ScriptReader mScriptReader = null;
|
||||
private ScriptReader mScriptReader;
|
||||
private JSONObject mProfile;
|
||||
private JSONObject mGlucoseStatus;
|
||||
private JSONObject mIobData;
|
||||
|
@ -39,12 +38,12 @@ public class DetermineBasalAdapterMAJS {
|
|||
private JSONObject mCurrentTemp;
|
||||
|
||||
private String storedCurrentTemp = null;
|
||||
public String storedIobData = null;
|
||||
private String storedIobData = null;
|
||||
private String storedGlucoseStatus = null;
|
||||
private String storedProfile = null;
|
||||
private String storedMeal_data = null;
|
||||
|
||||
public DetermineBasalAdapterMAJS(ScriptReader scriptReader) throws IOException {
|
||||
DetermineBasalAdapterMAJS(ScriptReader scriptReader) {
|
||||
mScriptReader = scriptReader;
|
||||
}
|
||||
|
||||
|
@ -97,7 +96,7 @@ public class DetermineBasalAdapterMAJS {
|
|||
|
||||
// Parse the jsResult object to a JSON-String
|
||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug("Result: " + result);
|
||||
try {
|
||||
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result));
|
||||
|
@ -108,14 +107,10 @@ public class DetermineBasalAdapterMAJS {
|
|||
log.debug("Problem loading JS Functions");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.debug("IOException");
|
||||
log.error("IOException");
|
||||
} catch (RhinoException e) {
|
||||
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error(e.toString());
|
||||
} catch (InstantiationException e) {
|
||||
log.error(e.toString());
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
log.error(e.toString());
|
||||
} finally {
|
||||
Context.exit();
|
||||
|
@ -210,7 +205,7 @@ public class DetermineBasalAdapterMAJS {
|
|||
mMealData.put("boluses", mealData.boluses);
|
||||
}
|
||||
|
||||
public String readFile(String filename) throws IOException {
|
||||
private String readFile(String filename) throws IOException {
|
||||
byte[] bytes = mScriptReader.readFile(filename);
|
||||
String string = new String(bytes, "UTF-8");
|
||||
if (string.startsWith("#!/usr/bin/env node")) {
|
||||
|
@ -219,13 +214,8 @@ public class DetermineBasalAdapterMAJS {
|
|||
return string;
|
||||
}
|
||||
|
||||
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
|
||||
@Override
|
||||
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||
return objects[1];
|
||||
}
|
||||
});
|
||||
private Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), (context, scriptable, scriptable1, objects) -> objects[1]);
|
||||
return param;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,17 +6,18 @@ import org.mozilla.javascript.NativeObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
|
||||
public class DetermineBasalResultMA extends APSResult {
|
||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalResultMA.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
public JSONObject json = new JSONObject();
|
||||
public double eventualBG;
|
||||
public double snoozeBG;
|
||||
public String mealAssist;
|
||||
private double eventualBG;
|
||||
private double snoozeBG;
|
||||
private String mealAssist;
|
||||
|
||||
public DetermineBasalResultMA(NativeObject result, JSONObject j) {
|
||||
DetermineBasalResultMA(NativeObject result, JSONObject j) {
|
||||
json = j;
|
||||
if (result.containsKey("error")) {
|
||||
reason = (String) result.get("error");
|
||||
|
@ -49,7 +50,7 @@ public class DetermineBasalResultMA extends APSResult {
|
|||
}
|
||||
}
|
||||
|
||||
public DetermineBasalResultMA() {
|
||||
private DetermineBasalResultMA() {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.mozilla.javascript.ScriptableObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
|
||||
/**
|
||||
* Created by adrian on 15/10/17.
|
||||
|
@ -14,10 +14,10 @@ import info.nightscout.utils.ToastUtils;
|
|||
|
||||
public class LoggerCallback extends ScriptableObject {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterMAJS.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
static StringBuffer errorBuffer = new StringBuffer();
|
||||
static StringBuffer logBuffer = new StringBuffer();
|
||||
private static StringBuffer errorBuffer = new StringBuffer();
|
||||
private static StringBuffer logBuffer = new StringBuffer();
|
||||
|
||||
|
||||
public LoggerCallback() {
|
||||
|
@ -36,19 +36,20 @@ public class LoggerCallback extends ScriptableObject {
|
|||
}
|
||||
|
||||
public void jsFunction_log(Object obj1) {
|
||||
if (Config.logAps)
|
||||
log.debug(obj1.toString());
|
||||
logBuffer.append(obj1.toString());
|
||||
logBuffer.append(' ');
|
||||
}
|
||||
|
||||
public void jsFunction_error(Object obj1) {
|
||||
if (Config.logAps)
|
||||
log.error(obj1.toString());
|
||||
errorBuffer.append(obj1.toString());
|
||||
errorBuffer.append(' ');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getScriptDebug() {
|
||||
String ret = "";
|
||||
if (errorBuffer.length() > 0) {
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.OpenAPSMA;
|
|||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -12,10 +11,6 @@ import android.widget.TextView;
|
|||
import com.crashlytics.android.answers.CustomEvent;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||
|
@ -24,8 +19,6 @@ import info.nightscout.utils.FabricPrivacy;
|
|||
import info.nightscout.utils.JSONFormatter;
|
||||
|
||||
public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClickListener {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSMAFragment.class);
|
||||
|
||||
Button run;
|
||||
TextView lastRunView;
|
||||
TextView glucoseStatusView;
|
||||
|
@ -87,9 +80,7 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
|
|||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.runOnUiThread(() -> {
|
||||
DetermineBasalResultMA lastAPSResult = OpenAPSMAPlugin.getPlugin().lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
|
@ -106,16 +97,13 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
|
|||
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != null) {
|
||||
lastRunView.setText(OpenAPSMAPlugin.getPlugin().lastAPSRun.toLocaleString());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateResultGUI(final String text) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.runOnUiThread(() -> {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
|
@ -124,7 +112,6 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
|
|||
mealDataView.setText("");
|
||||
requestView.setText("");
|
||||
lastRunView.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,10 @@ import org.json.JSONException;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
|
@ -39,7 +39,7 @@ import static info.nightscout.utils.HardLimits.verifyHardLimits;
|
|||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSMAPlugin.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
private static OpenAPSMAPlugin openAPSMAPlugin;
|
||||
|
||||
|
@ -90,15 +90,11 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||
if (Config.logAps)
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = null;
|
||||
try {
|
||||
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
@ -106,21 +102,21 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (profile == null) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEnabled(PluginType.APS)) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.openapsma_disabled));
|
||||
return;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
return;
|
||||
}
|
||||
|
@ -147,6 +143,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
|
||||
double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "MA data gathering", start);
|
||||
|
||||
minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
|
||||
|
@ -177,6 +174,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "MA calculation", start);
|
||||
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ import info.nightscout.androidaps.events.EventUpdateGui;
|
|||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class EventOpenAPSUpdateResultGui extends EventUpdateGui {
|
||||
public String text = null;
|
||||
public String text;
|
||||
|
||||
public EventOpenAPSUpdateResultGui(String text) {
|
||||
this.text = text;
|
||||
|
|
|
@ -3,7 +3,6 @@ package info.nightscout.androidaps.plugins.OpenAPSSMB;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.javascript.Callable;
|
||||
import org.mozilla.javascript.Context;
|
||||
import org.mozilla.javascript.Function;
|
||||
import org.mozilla.javascript.NativeJSON;
|
||||
|
@ -35,10 +34,10 @@ import info.nightscout.utils.SP;
|
|||
import info.nightscout.utils.SafeParse;
|
||||
|
||||
public class DetermineBasalAdapterSMBJS {
|
||||
private static Logger log = LoggerFactory.getLogger(DetermineBasalAdapterSMBJS.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
|
||||
private ScriptReader mScriptReader = null;
|
||||
private ScriptReader mScriptReader;
|
||||
private JSONObject mProfile;
|
||||
private JSONObject mGlucoseStatus;
|
||||
private JSONArray mIobData;
|
||||
|
@ -64,7 +63,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
* Main code
|
||||
*/
|
||||
|
||||
public DetermineBasalAdapterSMBJS(ScriptReader scriptReader) throws IOException {
|
||||
DetermineBasalAdapterSMBJS(ScriptReader scriptReader) {
|
||||
mScriptReader = scriptReader;
|
||||
}
|
||||
|
||||
|
@ -72,6 +71,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
public DetermineBasalResultSMB invoke() {
|
||||
|
||||
|
||||
if (Config.logAps) {
|
||||
log.debug(">>> Invoking detemine_basal <<<");
|
||||
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||
|
@ -85,6 +85,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
log.debug("Reservoir data: " + "undefined");
|
||||
log.debug("MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed));
|
||||
log.debug("SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed));
|
||||
}
|
||||
|
||||
DetermineBasalResultSMB determineBasalResultSMB = null;
|
||||
|
||||
|
@ -135,7 +136,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
|
||||
// Parse the jsResult object to a JSON-String
|
||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug("Result: " + result);
|
||||
try {
|
||||
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result));
|
||||
|
@ -143,17 +144,13 @@ public class DetermineBasalAdapterSMBJS {
|
|||
log.error("Unhandled exception", e);
|
||||
}
|
||||
} else {
|
||||
log.debug("Problem loading JS Functions");
|
||||
log.error("Problem loading JS Functions");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.debug("IOException");
|
||||
log.error("IOException");
|
||||
} catch (RhinoException e) {
|
||||
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
|
||||
} catch (IllegalAccessException e) {
|
||||
log.error(e.toString());
|
||||
} catch (InstantiationException e) {
|
||||
log.error(e.toString());
|
||||
} catch (InvocationTargetException e) {
|
||||
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
||||
log.error(e.toString());
|
||||
} finally {
|
||||
Context.exit();
|
||||
|
@ -319,31 +316,21 @@ public class DetermineBasalAdapterSMBJS {
|
|||
|
||||
}
|
||||
|
||||
public Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||
private Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
||||
|
||||
if (jsonObject == null) return Undefined.instance;
|
||||
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), new Callable() {
|
||||
@Override
|
||||
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||
return objects[1];
|
||||
}
|
||||
});
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), (context, scriptable, scriptable1, objects) -> objects[1]);
|
||||
return param;
|
||||
}
|
||||
|
||||
public Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
|
||||
private Object makeParamArray(JSONArray jsonArray, Context rhino, Scriptable scope) {
|
||||
//Object param = NativeJSON.parse(rhino, scope, "{myarray: " + jsonArray.toString() + " }", new Callable() {
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), new Callable() {
|
||||
@Override
|
||||
public Object call(Context context, Scriptable scriptable, Scriptable scriptable1, Object[] objects) {
|
||||
return objects[1];
|
||||
}
|
||||
});
|
||||
Object param = NativeJSON.parse(rhino, scope, jsonArray.toString(), (context, scriptable, scriptable1, objects) -> objects[1]);
|
||||
return param;
|
||||
}
|
||||
|
||||
public String readFile(String filename) throws IOException {
|
||||
private String readFile(String filename) throws IOException {
|
||||
byte[] bytes = mScriptReader.readFile(filename);
|
||||
String string = new String(bytes, "UTF-8");
|
||||
if (string.startsWith("#!/usr/bin/env node")) {
|
||||
|
|
|
@ -5,11 +5,12 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
|
||||
public class DetermineBasalResultSMB extends APSResult {
|
||||
private static final Logger log = LoggerFactory.getLogger(DetermineBasalResultSMB.class);
|
||||
private static final Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
private double eventualBG;
|
||||
private double snoozeBG;
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.slf4j.LoggerFactory;
|
|||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.plugins.Common.SubscriberFragment;
|
||||
|
@ -28,7 +29,7 @@ import info.nightscout.utils.FabricPrivacy;
|
|||
import info.nightscout.utils.JSONFormatter;
|
||||
|
||||
public class OpenAPSSMBFragment extends SubscriberFragment {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSSMBFragment.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
@BindView(R.id.openapsma_run)
|
||||
Button run;
|
||||
|
@ -84,9 +85,7 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
|||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.runOnUiThread(() -> {
|
||||
synchronized (OpenAPSSMBFragment.this) {
|
||||
if (!isBound()) return;
|
||||
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
|
||||
|
@ -119,16 +118,13 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
|||
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void updateResultGUI(final String text) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
activity.runOnUiThread(() -> {
|
||||
synchronized (OpenAPSSMBFragment.this) {
|
||||
if (isBound()) {
|
||||
resultView.setText(text);
|
||||
|
@ -143,7 +139,6 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
|||
lastRunView.setText("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
package info.nightscout.androidaps.plugins.OpenAPSSMB;
|
||||
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||
|
@ -24,16 +23,17 @@ import info.nightscout.androidaps.interfaces.PluginDescription;
|
|||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.OpenAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.HardLimits;
|
||||
import info.nightscout.androidaps.plugins.NSClientInternal.NSUpload;
|
||||
import info.nightscout.utils.Profiler;
|
||||
import info.nightscout.utils.Round;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
@ -42,7 +42,7 @@ import info.nightscout.utils.ToastUtils;
|
|||
* Created by mike on 05.08.2016.
|
||||
*/
|
||||
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(OpenAPSSMBPlugin.class);
|
||||
private static Logger log = LoggerFactory.getLogger(Constants.APS);
|
||||
|
||||
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
|
||||
|
@ -94,15 +94,11 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||
if (Config.logAps)
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = null;
|
||||
try {
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
|
||||
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
@ -110,21 +106,21 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (profile == null) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEnabled(PluginType.APS)) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.openapsma_disabled));
|
||||
return;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null) {
|
||||
MainApp.bus().post(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
||||
if (Config.logAPSResult)
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
return;
|
||||
}
|
||||
|
@ -146,10 +142,12 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
Date start = new Date();
|
||||
Date startPart = new Date();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(profile);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = new Date();
|
||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "getMealData()", startPart);
|
||||
|
||||
double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
||||
|
@ -170,7 +168,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (!checkOnlyHardLimits(profile.getDia(), "dia", HardLimits.MINDIA, HardLimits.MAXDIA))
|
||||
return;
|
||||
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||
if (!checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", HardLimits.MINIC, HardLimits.MAXIC))
|
||||
return;
|
||||
if (!checkOnlyHardLimits(Profile.toMgdl(profile.getIsf(), units), "sens", HardLimits.MINISF, HardLimits.MAXISF))
|
||||
return;
|
||||
|
@ -200,7 +198,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering);
|
||||
inputConstraints.copyReasons(advancedFiltering);
|
||||
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "SMB data gathering", start);
|
||||
|
||||
start = new Date();
|
||||
|
@ -219,6 +219,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
long now = System.currentTimeMillis();
|
||||
|
||||
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "SMB calculation", start);
|
||||
// TODO still needed with oref1?
|
||||
// Fix bug determine basal
|
||||
|
|
Loading…
Reference in a new issue