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;
|
||||
|
@ -373,12 +375,12 @@ public class DeviceStatus {
|
|||
public int uploaderBattery = 0;
|
||||
public String created_at = null;
|
||||
|
||||
public JSONObject mongoRecord () {
|
||||
public JSONObject mongoRecord() {
|
||||
JSONObject record = new JSONObject();
|
||||
|
||||
try {
|
||||
if (device != null) record.put("device" , device);
|
||||
if (pump != null) record.put("pump" , pump);
|
||||
if (device != null) record.put("device", device);
|
||||
if (pump != null) record.put("pump", pump);
|
||||
if (suggested != null) {
|
||||
JSONObject openaps = new JSONObject();
|
||||
if (enacted != null) openaps.put("enacted", enacted);
|
||||
|
@ -387,7 +389,7 @@ public class DeviceStatus {
|
|||
record.put("openaps", openaps);
|
||||
}
|
||||
if (uploaderBattery != 0) record.put("uploaderBattery", uploaderBattery);
|
||||
if (created_at != null) record.put("created_at" , created_at);
|
||||
if (created_at != null) record.put("created_at", created_at);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
|
|
|
@ -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() {
|
||||
|
@ -131,15 +131,15 @@ public class LoopPlugin extends PluginBase {
|
|||
PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method is triggered once autosens calculation has completed, so the LoopPlugin
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
* <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.
|
||||
*/
|
||||
@Subscribe
|
||||
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
|
||||
|
@ -248,19 +248,20 @@ public class LoopPlugin extends PluginBase {
|
|||
return isDisconnected;
|
||||
}
|
||||
|
||||
public synchronized void invoke(String initiator, boolean allowNotification){
|
||||
public synchronized void invoke(String initiator, boolean allowNotification) {
|
||||
invoke(initiator, allowNotification, false);
|
||||
}
|
||||
|
||||
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();
|
||||
log.debug(message);
|
||||
if (Config.logAps)
|
||||
log.debug(message);
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(message));
|
||||
return;
|
||||
}
|
||||
|
@ -273,7 +274,8 @@ public class LoopPlugin extends PluginBase {
|
|||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (!MainApp.getConfigBuilder().isProfileValid("Loop")) {
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.noprofileselected)));
|
||||
return;
|
||||
}
|
||||
|
@ -303,7 +305,8 @@ public class LoopPlugin extends PluginBase {
|
|||
// safety check for multiple SMBs
|
||||
long lastBolusTime = TreatmentsPlugin.getPlugin().getLastBolusTime();
|
||||
if (lastBolusTime != 0 && lastBolusTime + 3 * 60 * 1000 > System.currentTimeMillis()) {
|
||||
log.debug("SMB requsted but still in 3 min interval");
|
||||
if (Config.logAps)
|
||||
log.debug("SMB requsted but still in 3 min interval");
|
||||
resultAfterConstraints.smb = 0;
|
||||
}
|
||||
|
||||
|
@ -318,13 +321,15 @@ public class LoopPlugin extends PluginBase {
|
|||
NSUpload.uploadDeviceStatus();
|
||||
|
||||
if (isSuspended()) {
|
||||
log.debug(MainApp.gs(R.string.loopsuspended));
|
||||
if (Config.logAps)
|
||||
log.debug(MainApp.gs(R.string.loopsuspended));
|
||||
MainApp.bus().post(new EventLoopSetLastRunGui(MainApp.gs(R.string.loopsuspended)));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pump.isSuspended()) {
|
||||
log.debug(MainApp.gs(R.string.pumpsuspended));
|
||||
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,23 +55,24 @@ public class DetermineBasalAdapterAMAJS {
|
|||
|
||||
private String scriptDebug = "";
|
||||
|
||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) throws IOException {
|
||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) {
|
||||
mScriptReader = scriptReader;
|
||||
}
|
||||
|
||||
public DetermineBasalResultAMA invoke() {
|
||||
|
||||
|
||||
log.debug(">>> Invoking detemine_basal <<<");
|
||||
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||
log.debug("Profile: " + (storedProfile = mProfile.toString()));
|
||||
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||
if (mAutosensData != null)
|
||||
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||
else
|
||||
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
||||
if (Config.logAps) {
|
||||
log.debug(">>> Invoking detemine_basal <<<");
|
||||
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||
log.debug("Profile: " + (storedProfile = mProfile.toString()));
|
||||
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||
if (mAutosensData != null)
|
||||
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();
|
||||
|
@ -214,7 +210,7 @@ public class DetermineBasalAdapterAMAJS {
|
|||
mProfile.put("temptargetSet", tempTargetSet);
|
||||
mProfile.put("autosens_adjust_targets", SP.getBoolean(R.string.key_openapsama_autosens_adjusttargets, true));
|
||||
//align with max-absorption model in AMA sensitivity
|
||||
if(mealData.usedMinCarbsImpact > 0){
|
||||
if (mealData.usedMinCarbsImpact > 0) {
|
||||
mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact);
|
||||
} else {
|
||||
mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
|
||||
|
@ -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,29 +43,23 @@ 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);
|
||||
View view = inflater.inflate(R.layout.openapsama_fragment, container, false);
|
||||
|
||||
run = (Button) view.findViewById(R.id.openapsma_run);
|
||||
run.setOnClickListener(this);
|
||||
lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun);
|
||||
glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus);
|
||||
currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp);
|
||||
iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata);
|
||||
profileView = (TextView) view.findViewById(R.id.openapsma_profile);
|
||||
mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata);
|
||||
autosensDataView = (TextView) view.findViewById(R.id.openapsma_autosensdata);
|
||||
scriptdebugView = (TextView) view.findViewById(R.id.openapsma_scriptdebugdata);
|
||||
resultView = (TextView) view.findViewById(R.id.openapsma_result);
|
||||
requestView = (TextView) view.findViewById(R.id.openapsma_request);
|
||||
run = (Button) view.findViewById(R.id.openapsma_run);
|
||||
run.setOnClickListener(this);
|
||||
lastRunView = (TextView) view.findViewById(R.id.openapsma_lastrun);
|
||||
glucoseStatusView = (TextView) view.findViewById(R.id.openapsma_glucosestatus);
|
||||
currentTempView = (TextView) view.findViewById(R.id.openapsma_currenttemp);
|
||||
iobDataView = (TextView) view.findViewById(R.id.openapsma_iobdata);
|
||||
profileView = (TextView) view.findViewById(R.id.openapsma_profile);
|
||||
mealDataView = (TextView) view.findViewById(R.id.openapsma_mealdata);
|
||||
autosensDataView = (TextView) view.findViewById(R.id.openapsma_autosensdata);
|
||||
scriptdebugView = (TextView) view.findViewById(R.id.openapsma_scriptdebugdata);
|
||||
resultView = (TextView) view.findViewById(R.id.openapsma_result);
|
||||
requestView = (TextView) view.findViewById(R.id.openapsma_request);
|
||||
|
||||
updateGUI();
|
||||
return view;
|
||||
} catch (Exception e) {
|
||||
FabricPrivacy.logException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
updateGUI();
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,35 +87,32 @@ 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() {
|
||||
DetermineBasalResultAMA lastAPSResult = OpenAPSAMAPlugin.getPlugin().lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
requestView.setText(lastAPSResult.toSpanned());
|
||||
}
|
||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS;
|
||||
if (determineBasalAdapterAMAJS != null) {
|
||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getGlucoseStatusParam()));
|
||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
|
||||
try {
|
||||
JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam());
|
||||
iobDataView.setText(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0)));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
iobDataView.setText("JSONException");
|
||||
}
|
||||
profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam()));
|
||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
|
||||
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
|
||||
}
|
||||
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != null) {
|
||||
lastRunView.setText(OpenAPSAMAPlugin.getPlugin().lastAPSRun.toLocaleString());
|
||||
}
|
||||
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
|
||||
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));
|
||||
activity.runOnUiThread(() -> {
|
||||
DetermineBasalResultAMA lastAPSResult = OpenAPSAMAPlugin.getPlugin().lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
requestView.setText(lastAPSResult.toSpanned());
|
||||
}
|
||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS = OpenAPSAMAPlugin.getPlugin().lastDetermineBasalAdapterAMAJS;
|
||||
if (determineBasalAdapterAMAJS != null) {
|
||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getGlucoseStatusParam()));
|
||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getCurrentTempParam()));
|
||||
try {
|
||||
JSONArray iobArray = new JSONArray(determineBasalAdapterAMAJS.getIobDataParam());
|
||||
iobDataView.setText(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0)));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
iobDataView.setText("JSONException");
|
||||
}
|
||||
profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam()));
|
||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
|
||||
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
|
||||
}
|
||||
if (OpenAPSAMAPlugin.getPlugin().lastAPSRun != null) {
|
||||
lastRunView.setText(OpenAPSAMAPlugin.getPlugin().lastAPSRun.toLocaleString());
|
||||
}
|
||||
if (OpenAPSAMAPlugin.getPlugin().lastAutosensResult != null) {
|
||||
autosensDataView.setText(JSONFormatter.format(OpenAPSAMAPlugin.getPlugin().lastAutosensResult.json()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -129,20 +120,17 @@ public class OpenAPSAMAFragment extends SubscriberFragment implements View.OnCli
|
|||
void updateResultGUI(final String text) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
iobDataView.setText("");
|
||||
profileView.setText("");
|
||||
mealDataView.setText("");
|
||||
autosensDataView.setText("");
|
||||
scriptdebugView.setText("");
|
||||
requestView.setText("");
|
||||
lastRunView.setText("");
|
||||
}
|
||||
activity.runOnUiThread(() -> {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
iobDataView.setText("");
|
||||
profileView.setText("");
|
||||
mealDataView.setText("");
|
||||
autosensDataView.setText("");
|
||||
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) {
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + 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;
|
||||
}
|
||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
|
||||
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,11 +135,13 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
Date start = new Date();
|
||||
Date startPart = new Date();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = new Date();
|
||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
Profiler.log(log, "getMealData()", startPart);
|
||||
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,8 +182,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
lastAutosensResult = new AutosensResult();
|
||||
lastAutosensResult.sensResult = "autosens disabled";
|
||||
}
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
Profiler.log(log, "AMA data gathering", start);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "AMA data gathering", start);
|
||||
|
||||
start = new Date();
|
||||
|
||||
|
@ -200,7 +200,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
|
||||
DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke();
|
||||
Profiler.log(log, "AMA calculation", start);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "AMA calculation", start);
|
||||
// Fix bug determine basal
|
||||
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
|
||||
determineBasalResultAMA.tempBasalRequested = false;
|
||||
|
|
|
@ -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,26 +36,27 @@ public class LoggerCallback extends ScriptableObject {
|
|||
}
|
||||
|
||||
public void jsFunction_log(Object obj1) {
|
||||
log.debug(obj1.toString());
|
||||
if (Config.logAps)
|
||||
log.debug(obj1.toString());
|
||||
logBuffer.append(obj1.toString());
|
||||
logBuffer.append(' ');
|
||||
}
|
||||
|
||||
public void jsFunction_error(Object obj1) {
|
||||
log.error(obj1.toString());
|
||||
if (Config.logAps)
|
||||
log.error(obj1.toString());
|
||||
errorBuffer.append(obj1.toString());
|
||||
errorBuffer.append(' ');
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getScriptDebug(){
|
||||
public static String getScriptDebug() {
|
||||
String ret = "";
|
||||
if(errorBuffer.length() > 0){
|
||||
if (errorBuffer.length() > 0) {
|
||||
ret += "e:\n" + errorBuffer.toString();
|
||||
}
|
||||
if(ret.length() > 0 && logBuffer.length() > 0) ret += '\n';
|
||||
if(logBuffer.length() > 0){
|
||||
if (ret.length() > 0 && logBuffer.length() > 0) ret += '\n';
|
||||
if (logBuffer.length() > 0) {
|
||||
ret += "d:\n" + logBuffer.toString();
|
||||
}
|
||||
return ret;
|
||||
|
|
|
@ -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,25 +80,22 @@ 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() {
|
||||
DetermineBasalResultMA lastAPSResult = OpenAPSMAPlugin.getPlugin().lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
requestView.setText(lastAPSResult.toSpanned());
|
||||
}
|
||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS;
|
||||
if (determineBasalAdapterMAJS != null) {
|
||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getGlucoseStatusParam()));
|
||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getCurrentTempParam()));
|
||||
iobDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getIobDataParam()));
|
||||
profileView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getProfileParam()));
|
||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getMealDataParam()));
|
||||
}
|
||||
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != null) {
|
||||
lastRunView.setText(OpenAPSMAPlugin.getPlugin().lastAPSRun.toLocaleString());
|
||||
}
|
||||
activity.runOnUiThread(() -> {
|
||||
DetermineBasalResultMA lastAPSResult = OpenAPSMAPlugin.getPlugin().lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
requestView.setText(lastAPSResult.toSpanned());
|
||||
}
|
||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS = OpenAPSMAPlugin.getPlugin().lastDetermineBasalAdapterMAJS;
|
||||
if (determineBasalAdapterMAJS != null) {
|
||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getGlucoseStatusParam()));
|
||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getCurrentTempParam()));
|
||||
iobDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getIobDataParam()));
|
||||
profileView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getProfileParam()));
|
||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterMAJS.getMealDataParam()));
|
||||
}
|
||||
if (OpenAPSMAPlugin.getPlugin().lastAPSRun != null) {
|
||||
lastRunView.setText(OpenAPSMAPlugin.getPlugin().lastAPSRun.toLocaleString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -113,18 +103,15 @@ public class OpenAPSMAFragment extends SubscriberFragment implements View.OnClic
|
|||
private void updateResultGUI(final String text) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
iobDataView.setText("");
|
||||
profileView.setText("");
|
||||
mealDataView.setText("");
|
||||
requestView.setText("");
|
||||
lastRunView.setText("");
|
||||
}
|
||||
activity.runOnUiThread(() -> {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
iobDataView.setText("");
|
||||
profileView.setText("");
|
||||
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) {
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + 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;
|
||||
}
|
||||
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
|
||||
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,7 +143,8 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
|
||||
double maxIob = MainApp.getConstraintChecker().getMaxIOBAllowed().value();
|
||||
Profiler.log(log, "MA data gathering", start);
|
||||
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]);
|
||||
maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
||||
|
@ -177,7 +174,8 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
}
|
||||
Profiler.log(log, "MA calculation", start);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "MA calculation", start);
|
||||
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
|
|
@ -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,19 +71,21 @@ public class DetermineBasalAdapterSMBJS {
|
|||
public DetermineBasalResultSMB invoke() {
|
||||
|
||||
|
||||
log.debug(">>> Invoking detemine_basal <<<");
|
||||
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||
log.debug("Profile: " + (storedProfile = mProfile.toString()));
|
||||
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||
if (mAutosensData != null)
|
||||
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||
else
|
||||
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
||||
log.debug("Reservoir data: " + "undefined");
|
||||
log.debug("MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed));
|
||||
log.debug("SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed));
|
||||
if (Config.logAps) {
|
||||
log.debug(">>> Invoking detemine_basal <<<");
|
||||
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
log.debug("IOB data: " + (storedIobData = mIobData.toString()));
|
||||
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||
log.debug("Profile: " + (storedProfile = mProfile.toString()));
|
||||
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||
if (mAutosensData != null)
|
||||
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||
else
|
||||
log.debug("Autosens data: " + (storedAutosens_data = "undefined"));
|
||||
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();
|
||||
|
@ -244,7 +241,7 @@ public class DetermineBasalAdapterSMBJS {
|
|||
mProfile.put("maxCOB", SMBDefaults.maxCOB);
|
||||
mProfile.put("skip_neutral_temps", SMBDefaults.skip_neutral_temps);
|
||||
//align with max-absorption model in AMA sensitivity
|
||||
if(mealData.usedMinCarbsImpact > 0){
|
||||
if (mealData.usedMinCarbsImpact > 0) {
|
||||
mProfile.put("min_5m_carbimpact", mealData.usedMinCarbsImpact);
|
||||
} else {
|
||||
mProfile.put("min_5m_carbimpact", SP.getDouble(R.string.key_openapsama_min_5m_carbimpact, SMBDefaults.min_5m_carbimpact));
|
||||
|
@ -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,40 +85,37 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
|||
protected void updateGUI() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (OpenAPSSMBFragment.this) {
|
||||
if (!isBound()) return;
|
||||
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
|
||||
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
requestView.setText(lastAPSResult.toSpanned());
|
||||
}
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
|
||||
if (determineBasalAdapterSMBJS != null) {
|
||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
|
||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
|
||||
try {
|
||||
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
|
||||
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
iobDataView.setText("JSONException see log for details");
|
||||
}
|
||||
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
|
||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
|
||||
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
|
||||
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
|
||||
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
|
||||
}
|
||||
if (plugin.lastAPSRun != null) {
|
||||
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim());
|
||||
}
|
||||
if (plugin.lastAutosensResult != null) {
|
||||
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
|
||||
activity.runOnUiThread(() -> {
|
||||
synchronized (OpenAPSSMBFragment.this) {
|
||||
if (!isBound()) return;
|
||||
OpenAPSSMBPlugin plugin = OpenAPSSMBPlugin.getPlugin();
|
||||
DetermineBasalResultSMB lastAPSResult = plugin.lastAPSResult;
|
||||
if (lastAPSResult != null) {
|
||||
resultView.setText(JSONFormatter.format(lastAPSResult.json));
|
||||
requestView.setText(lastAPSResult.toSpanned());
|
||||
}
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = plugin.lastDetermineBasalAdapterSMBJS;
|
||||
if (determineBasalAdapterSMBJS != null) {
|
||||
glucoseStatusView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getGlucoseStatusParam()).toString().trim());
|
||||
currentTempView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getCurrentTempParam()).toString().trim());
|
||||
try {
|
||||
JSONArray iobArray = new JSONArray(determineBasalAdapterSMBJS.getIobDataParam());
|
||||
iobDataView.setText((String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n" + JSONFormatter.format(iobArray.getString(0))).trim());
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
iobDataView.setText("JSONException see log for details");
|
||||
}
|
||||
profileView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getProfileParam()).toString().trim());
|
||||
mealDataView.setText(JSONFormatter.format(determineBasalAdapterSMBJS.getMealDataParam()).toString().trim());
|
||||
scriptdebugView.setText(determineBasalAdapterSMBJS.getScriptDebug().trim());
|
||||
if (lastAPSResult != null && lastAPSResult.inputConstraints != null)
|
||||
constraintsView.setText(lastAPSResult.inputConstraints.getReasons().trim());
|
||||
}
|
||||
if (plugin.lastAPSRun != null) {
|
||||
lastRunView.setText(plugin.lastAPSRun.toLocaleString().trim());
|
||||
}
|
||||
if (plugin.lastAutosensResult != null) {
|
||||
autosensDataView.setText(JSONFormatter.format(plugin.lastAutosensResult.json()).toString().trim());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -126,22 +124,19 @@ public class OpenAPSSMBFragment extends SubscriberFragment {
|
|||
void updateResultGUI(final String text) {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null)
|
||||
activity.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (OpenAPSSMBFragment.this) {
|
||||
if (isBound()) {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
iobDataView.setText("");
|
||||
profileView.setText("");
|
||||
mealDataView.setText("");
|
||||
autosensDataView.setText("");
|
||||
scriptdebugView.setText("");
|
||||
requestView.setText("");
|
||||
lastRunView.setText("");
|
||||
}
|
||||
activity.runOnUiThread(() -> {
|
||||
synchronized (OpenAPSSMBFragment.this) {
|
||||
if (isBound()) {
|
||||
resultView.setText(text);
|
||||
glucoseStatusView.setText("");
|
||||
currentTempView.setText("");
|
||||
iobDataView.setText("");
|
||||
profileView.setText("");
|
||||
mealDataView.setText("");
|
||||
autosensDataView.setText("");
|
||||
scriptdebugView.setText("");
|
||||
requestView.setText("");
|
||||
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) {
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
if (Config.logAps)
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS = null;
|
||||
try {
|
||||
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return;
|
||||
}
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
|
||||
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
|
||||
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,11 +142,13 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
Date start = new Date();
|
||||
Date startPart = new Date();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(profile);
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = new Date();
|
||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
Profiler.log(log, "getMealData()", startPart);
|
||||
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,8 +198,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
MainApp.getConstraintChecker().isAdvancedFilteringEnabled(advancedFiltering);
|
||||
inputConstraints.copyReasons(advancedFiltering);
|
||||
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
Profiler.log(log, "SMB data gathering", start);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "SMB data gathering", start);
|
||||
|
||||
start = new Date();
|
||||
try {
|
||||
|
@ -219,7 +219,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
long now = System.currentTimeMillis();
|
||||
|
||||
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
|
||||
Profiler.log(log, "SMB calculation", start);
|
||||
if (Config.logAps)
|
||||
Profiler.log(log, "SMB calculation", start);
|
||||
// TODO still needed with oref1?
|
||||
// Fix bug determine basal
|
||||
if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
|
||||
|
|
Loading…
Reference in a new issue