add new logger to APS plugins

This commit is contained in:
AdrianLxM 2019-12-28 02:49:00 +01:00
parent 6752cbae94
commit 93bc179181
16 changed files with 191 additions and 201 deletions

View file

@ -5,6 +5,7 @@ import dagger.Component
import dagger.android.AndroidInjectionModule import dagger.android.AndroidInjectionModule
import dagger.android.AndroidInjector import dagger.android.AndroidInjector
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5 import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Objective5
import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS import info.nightscout.androidaps.plugins.general.automation.actions.ActionSendSMS
import info.nightscout.androidaps.queue.commands.CommandSetProfile import info.nightscout.androidaps.queue.commands.CommandSetProfile
@ -30,6 +31,8 @@ interface AppComponent : AndroidInjector<MainApp> {
fun injectObjective5(objective5: Objective5) fun injectObjective5(objective5: Objective5)
fun injectLoggerCallback(loggerCallback: LoggerCallback)
@Component.Builder @Component.Builder
interface Builder { interface Builder {

View file

@ -11,6 +11,7 @@ import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.logging.AAPSLogger import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.AAPSLoggerDebug import info.nightscout.androidaps.logging.AAPSLoggerDebug
import info.nightscout.androidaps.logging.AAPSLoggerProduction import info.nightscout.androidaps.logging.AAPSLoggerProduction
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
@ -65,16 +66,19 @@ class AppModule {
interface AppBindings { interface AppBindings {
@ContributesAndroidInjector @ContributesAndroidInjector
fun bindDataService(): DataService fun dataServiceInjector(): DataService
@ContributesAndroidInjector @ContributesAndroidInjector
fun bindCommandSetProfile(): CommandSetProfile fun commandSetProfileInjector(): CommandSetProfile
@ContributesAndroidInjector @ContributesAndroidInjector
fun bindActionSendSMS(): ActionSendSMS fun actionSendSMSInjector(): ActionSendSMS
@ContributesAndroidInjector @ContributesAndroidInjector
fun bindObjective5(): Objective5 fun objective5Injector(): Objective5
@ContributesAndroidInjector
fun loggerCallbackInjector(): LoggerCallback
@Binds @Binds
fun bindContext(mainApp: MainApp): Context fun bindContext(mainApp: MainApp): Context

View file

@ -11,8 +11,6 @@ import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Undefined; import org.mozilla.javascript.Undefined;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -26,7 +24,8 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback; import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults; import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
@ -38,7 +37,7 @@ import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
public class DetermineBasalAdapterAMAJS { public class DetermineBasalAdapterAMAJS {
private static Logger log = LoggerFactory.getLogger(L.APS); private final AAPSLogger aapsLogger;
private ScriptReader mScriptReader = null; private ScriptReader mScriptReader = null;
@ -59,25 +58,25 @@ public class DetermineBasalAdapterAMAJS {
private String scriptDebug = ""; private String scriptDebug = "";
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) { public DetermineBasalAdapterAMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
mScriptReader = scriptReader; mScriptReader = scriptReader;
this.aapsLogger = aapsLogger;
} }
@Nullable @Nullable
public DetermineBasalResultAMA invoke() { public DetermineBasalResultAMA invoke() {
if (L.isEnabled(L.APS)) { aapsLogger.debug(LTag.APS, ">>> Invoking detemine_basal <<<");
log.debug(">>> Invoking detemine_basal <<<"); aapsLogger.debug(LTag.APS, "Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString())); aapsLogger.debug(LTag.APS, "IOB data: " + (storedIobData = mIobData.toString()));
log.debug("IOB data: " + (storedIobData = mIobData.toString())); aapsLogger.debug(LTag.APS, "Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString())); aapsLogger.debug(LTag.APS, "Profile: " + (storedProfile = mProfile.toString()));
log.debug("Profile: " + (storedProfile = mProfile.toString())); aapsLogger.debug(LTag.APS, "Meal data: " + (storedMeal_data = mMealData.toString()));
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
if (mAutosensData != null) if (mAutosensData != null)
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString())); aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
else else
log.debug("Autosens data: " + (storedAutosens_data = "undefined")); aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = "undefined"));
}
DetermineBasalResultAMA determineBasalResultAMA = null; DetermineBasalResultAMA determineBasalResultAMA = null;
@ -124,22 +123,21 @@ public class DetermineBasalAdapterAMAJS {
// Parse the jsResult object to a JSON-String // Parse the jsResult object to a JSON-String
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, "Result: " + result);
log.debug("Result: " + result);
try { try {
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result)); determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result), aapsLogger);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
} else { } else {
log.error("Problem loading JS Functions"); aapsLogger.error(LTag.APS, "Problem loading JS Functions");
} }
} catch (IOException e) { } catch (IOException e) {
log.error("IOException"); aapsLogger.error(LTag.APS, "IOException");
} catch (RhinoException e) { } catch (RhinoException e) {
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString()); aapsLogger.error(LTag.APS, "RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
log.error(e.toString()); aapsLogger.error(LTag.APS, e.toString());
} finally { } finally {
Context.exit(); Context.exit();
} }

View file

@ -3,21 +3,20 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.mozilla.javascript.NativeObject; import org.mozilla.javascript.NativeObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
public class DetermineBasalResultAMA extends APSResult { public class DetermineBasalResultAMA extends APSResult {
private static Logger log = LoggerFactory.getLogger(L.APS); private AAPSLogger aapsLogger;
private double eventualBG; private double eventualBG;
private double snoozeBG; private double snoozeBG;
DetermineBasalResultAMA(NativeObject result, JSONObject j) { DetermineBasalResultAMA(NativeObject result, JSONObject j, AAPSLogger aapsLogger) {
this(); this(aapsLogger);
date = DateUtil.now(); date = DateUtil.now();
json = j; json = j;
if (result.containsKey("error")) { if (result.containsKey("error")) {
@ -48,13 +47,14 @@ public class DetermineBasalResultAMA extends APSResult {
bolusRequested = false; bolusRequested = false;
} }
private DetermineBasalResultAMA() { private DetermineBasalResultAMA(AAPSLogger aapsLogger) {
hasPredictions = true; hasPredictions = true;
this.aapsLogger = aapsLogger;
} }
@Override @Override
public DetermineBasalResultAMA clone() { public DetermineBasalResultAMA clone() {
DetermineBasalResultAMA newResult = new DetermineBasalResultAMA(); DetermineBasalResultAMA newResult = new DetermineBasalResultAMA(aapsLogger);
doClone(newResult); doClone(newResult);
newResult.eventualBG = eventualBG; newResult.eventualBG = eventualBG;
@ -68,7 +68,7 @@ public class DetermineBasalResultAMA extends APSResult {
JSONObject ret = new JSONObject(this.json.toString()); JSONObject ret = new JSONObject(this.json.toString());
return ret; return ret;
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
return null; return null;
} }

View file

@ -8,7 +8,8 @@ import android.view.ViewGroup
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
@ -21,16 +22,17 @@ import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.openapsama_fragment.* import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.slf4j.LoggerFactory
import javax.inject.Inject import javax.inject.Inject
class OpenAPSAMAFragment : DaggerFragment() { class OpenAPSAMAFragment : DaggerFragment() {
private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@Inject @Inject
lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
@Inject
lateinit var aapsLogger: AAPSLogger
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsama_fragment, container, false) return inflater.inflate(R.layout.openapsama_fragment, container, false)
@ -88,7 +90,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
val iobArray = JSONArray(determineBasalAdapterAMAJS.iobDataParam) val iobArray = JSONArray(determineBasalAdapterAMAJS.iobDataParam)
openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0)))
} catch (e: JSONException) { } catch (e: JSONException) {
log.error("Unhandled exception", e) aapsLogger.error(LTag.APS,"Unhandled exception", e)
openapsma_iobdata.text = "JSONException see log for details" openapsma_iobdata.text = "JSONException see log for details"
} }

View file

@ -1,13 +1,10 @@
package info.nightscout.androidaps.plugins.aps.openAPSAMA; package info.nightscout.androidaps.plugins.aps.openAPSAMA;
import org.json.JSONException; import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
@ -19,13 +16,15 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
import info.nightscout.androidaps.plugins.bus.RxBus; import info.nightscout.androidaps.plugins.bus.RxBus;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
@ -40,8 +39,8 @@ import info.nightscout.androidaps.utils.Round;
@Singleton @Singleton
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface { public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(L.APS);
private final AAPSLogger aapsLogger;
// last values // last values
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null; DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
long lastAPSRun = 0; long lastAPSRun = 0;
@ -49,7 +48,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
@Inject @Inject
public OpenAPSAMAPlugin() { public OpenAPSAMAPlugin(AAPSLogger aapsLogger) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSAMAFragment.class.getName()) .fragmentClass(OpenAPSAMAFragment.class.getName())
@ -58,6 +57,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
.preferencesId(R.xml.pref_openapsama) .preferencesId(R.xml.pref_openapsama)
.description(R.string.description_ama) .description(R.string.description_ama)
); );
this.aapsLogger = aapsLogger;
} }
@Override @Override
@ -84,11 +84,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
@Override @Override
public void invoke(String initiator, boolean tempBasalFallback) { public void invoke(String initiator, boolean tempBasalFallback) {
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null; lastAPSResult = null;
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS; DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext())); determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
Profile profile = ProfileFunctions.getInstance().getProfile(); Profile profile = ProfileFunctions.getInstance().getProfile();
@ -96,29 +95,25 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
if (profile == null) { if (profile == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
log.debug(MainApp.gs(R.string.noprofileselected));
return; return;
} }
if (pump == null) { if (pump == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
log.debug(MainApp.gs(R.string.nopumpselected));
return; return;
} }
if (!isEnabled(PluginType.APS)) { if (!isEnabled(PluginType.APS)) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
log.debug(MainApp.gs(R.string.openapsma_disabled));
return; return;
} }
if (glucoseStatus == null) { if (glucoseStatus == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
return; return;
} }
@ -133,13 +128,11 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
long startPart = System.currentTimeMillis(); long startPart = System.currentTimeMillis();
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile); IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
Profiler.log(log, "calculateIobArrayInDia()", startPart);
startPart = System.currentTimeMillis(); startPart = System.currentTimeMillis();
MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
Profiler.log(log, "getMealData()", startPart);
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value(); double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
@ -180,10 +173,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
lastAutosensResult = new AutosensResult(); lastAutosensResult = new AutosensResult();
lastAutosensResult.sensResult = "autosens disabled"; lastAutosensResult.sensResult = "autosens disabled";
} }
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart); Profiler.log(aapsLogger, LTag.APS, "AMA data gathering", start);
if (L.isEnabled(L.APS))
Profiler.log(log, "AMA data gathering", start);
start = System.currentTimeMillis(); start = System.currentTimeMillis();
@ -199,12 +190,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke(); DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke();
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "AMA calculation", start);
Profiler.log(log, "AMA calculation", start);
// Fix bug determine basal // Fix bug determine basal
if (determineBasalResultAMA == null) { if (determineBasalResultAMA == null) {
if (L.isEnabled(L.APS)) aapsLogger.error(LTag.APS, "SMB calculation returned null");
log.error("SMB calculation returned null");
lastDetermineBasalAdapterAMAJS = null; lastDetermineBasalAdapterAMAJS = null;
lastAPSResult = null; lastAPSResult = null;
lastAPSRun = 0; lastAPSRun = 0;
@ -219,7 +208,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
try { try {
determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now)); determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS; lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS;

View file

@ -9,8 +9,6 @@ import org.mozilla.javascript.NativeObject;
import org.mozilla.javascript.RhinoException; import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.ScriptableObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -20,20 +18,22 @@ import javax.annotation.Nullable;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin; import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
public class DetermineBasalAdapterMAJS { public class DetermineBasalAdapterMAJS {
private static Logger log = LoggerFactory.getLogger(L.APS);
private final AAPSLogger aapsLogger;
private ScriptReader mScriptReader; private ScriptReader mScriptReader;
private JSONObject mProfile; private JSONObject mProfile;
private JSONObject mGlucoseStatus; private JSONObject mGlucoseStatus;
@ -47,8 +47,9 @@ public class DetermineBasalAdapterMAJS {
private String storedProfile = null; private String storedProfile = null;
private String storedMeal_data = null; private String storedMeal_data = null;
DetermineBasalAdapterMAJS(ScriptReader scriptReader) { DetermineBasalAdapterMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
mScriptReader = scriptReader; mScriptReader = scriptReader;
this.aapsLogger = aapsLogger;
} }
@Nullable @Nullable
@ -102,21 +103,21 @@ public class DetermineBasalAdapterMAJS {
// Parse the jsResult object to a JSON-String // Parse the jsResult object to a JSON-String
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug("Result: " + result); aapsLogger.debug(LTag.APS, "Result: " + result);
try { try {
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result)); determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result), aapsLogger);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
} else { } else {
log.debug("Problem loading JS Functions"); aapsLogger.debug(LTag.APS, "Problem loading JS Functions");
} }
} catch (IOException e) { } catch (IOException e) {
log.error("IOException"); aapsLogger.error(LTag.APS, "IOException");
} catch (RhinoException e) { } catch (RhinoException e) {
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString()); aapsLogger.error(LTag.APS, "RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
log.error(e.toString()); aapsLogger.error(LTag.APS, e.toString());
} finally { } finally {
Context.exit(); Context.exit();
} }

View file

@ -3,20 +3,20 @@ package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.mozilla.javascript.NativeObject; import org.mozilla.javascript.NativeObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
public class DetermineBasalResultMA extends APSResult { public class DetermineBasalResultMA extends APSResult {
private static Logger log = LoggerFactory.getLogger(L.APS); private AAPSLogger aapsLogger;
private double eventualBG; private double eventualBG;
private double snoozeBG; private double snoozeBG;
private String mealAssist; private String mealAssist;
DetermineBasalResultMA(NativeObject result, JSONObject j) { DetermineBasalResultMA(NativeObject result, JSONObject j, AAPSLogger aapsLogger) {
this(aapsLogger);
json = j; json = j;
if (result.containsKey("error")) { if (result.containsKey("error")) {
reason = (String) result.get("error"); reason = (String) result.get("error");
@ -49,12 +49,13 @@ public class DetermineBasalResultMA extends APSResult {
} }
} }
private DetermineBasalResultMA() { private DetermineBasalResultMA(AAPSLogger aapsLogger) {
this.aapsLogger = aapsLogger;
} }
@Override @Override
public DetermineBasalResultMA clone() { public DetermineBasalResultMA clone() {
DetermineBasalResultMA newResult = new DetermineBasalResultMA(); DetermineBasalResultMA newResult = new DetermineBasalResultMA(aapsLogger);
doClone(newResult); doClone(newResult);
newResult.eventualBG = eventualBG; newResult.eventualBG = eventualBG;
@ -69,7 +70,7 @@ public class DetermineBasalResultMA extends APSResult {
JSONObject ret = new JSONObject(this.json.toString()); JSONObject ret = new JSONObject(this.json.toString());
return ret; return ret;
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
return null; return null;
} }

View file

@ -1,10 +1,12 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA; package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.ScriptableObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import javax.inject.Inject;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
/** /**
* Created by adrian on 15/10/17. * Created by adrian on 15/10/17.
@ -13,7 +15,8 @@ import info.nightscout.androidaps.logging.L;
public class LoggerCallback extends ScriptableObject { public class LoggerCallback extends ScriptableObject {
private static Logger log = LoggerFactory.getLogger(L.APS); @Inject
AAPSLogger aapsLogger;
private static StringBuffer errorBuffer = new StringBuffer(); private static StringBuffer errorBuffer = new StringBuffer();
private static StringBuffer logBuffer = new StringBuffer(); private static StringBuffer logBuffer = new StringBuffer();
@ -23,6 +26,7 @@ public class LoggerCallback extends ScriptableObject {
//empty constructor needed for Rhino //empty constructor needed for Rhino
errorBuffer = new StringBuffer(); errorBuffer = new StringBuffer();
logBuffer = new StringBuffer(); logBuffer = new StringBuffer();
MainApp.instance().androidInjector().inject(this);
} }
@Override @Override
@ -35,14 +39,12 @@ public class LoggerCallback extends ScriptableObject {
} }
public void jsFunction_log(Object obj1) { public void jsFunction_log(Object obj1) {
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, obj1.toString().trim());
log.debug(obj1.toString().trim());
logBuffer.append(obj1.toString()); logBuffer.append(obj1.toString());
} }
public void jsFunction_error(Object obj1) { public void jsFunction_error(Object obj1) {
if (L.isEnabled(L.APS)) aapsLogger.error(LTag.APS, obj1.toString().trim());
log.error(obj1.toString().trim());
errorBuffer.append(obj1.toString()); errorBuffer.append(obj1.toString());
} }

View file

@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory
import javax.inject.Inject import javax.inject.Inject
class OpenAPSMAFragment : DaggerFragment() { class OpenAPSMAFragment : DaggerFragment() {
private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@Inject @Inject

View file

@ -1,8 +1,6 @@
package info.nightscout.androidaps.plugins.aps.openAPSMA; package info.nightscout.androidaps.plugins.aps.openAPSMA;
import org.json.JSONException; import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -18,7 +16,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
@ -40,7 +39,7 @@ import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
@Singleton @Singleton
public class OpenAPSMAPlugin extends PluginBase implements APSInterface { public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
private static Logger log = LoggerFactory.getLogger(L.APS); private final AAPSLogger aapsLogger;
// last values // last values
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null; DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
@ -48,7 +47,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
DetermineBasalResultMA lastAPSResult = null; DetermineBasalResultMA lastAPSResult = null;
@Inject @Inject
public OpenAPSMAPlugin() { public OpenAPSMAPlugin(AAPSLogger aapsLogger) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSMAFragment.class.getName()) .fragmentClass(OpenAPSMAFragment.class.getName())
@ -57,6 +56,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
.preferencesId(R.xml.pref_openapsma) .preferencesId(R.xml.pref_openapsma)
.description(R.string.description_ma) .description(R.string.description_ma)
); );
this.aapsLogger = aapsLogger;
} }
@Override @Override
@ -83,11 +83,10 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
@Override @Override
public void invoke(String initiator, boolean tempBasalFallback) { public void invoke(String initiator, boolean tempBasalFallback) {
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null; lastAPSResult = null;
DetermineBasalAdapterMAJS determineBasalAdapterMAJS; DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext())); determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
Profile profile = ProfileFunctions.getInstance().getProfile(); Profile profile = ProfileFunctions.getInstance().getProfile();
@ -95,29 +94,25 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
if (profile == null) { if (profile == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
log.debug(MainApp.gs(R.string.noprofileselected));
return; return;
} }
if (pump == null) { if (pump == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
log.debug(MainApp.gs(R.string.nopumpselected));
return; return;
} }
if (!isEnabled(PluginType.APS)) { if (!isEnabled(PluginType.APS)) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
log.debug(MainApp.gs(R.string.openapsma_disabled));
return; return;
} }
if (glucoseStatus == null) { if (glucoseStatus == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
return; return;
} }
@ -141,8 +136,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value(); double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "MA data gathering", start);
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]); 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]); maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
@ -173,16 +167,14 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
FabricPrivacy.logException(e); FabricPrivacy.logException(e);
return; return;
} }
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "MA calculation", start);
Profiler.log(log, "MA calculation", start);
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke(); DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
if (determineBasalResultMA == null) { if (determineBasalResultMA == null) {
if (L.isEnabled(L.APS)) aapsLogger.error(LTag.APS, "MA calculation returned null");
log.error("MA calculation returned null");
lastDetermineBasalAdapterMAJS = null; lastDetermineBasalAdapterMAJS = null;
lastAPSResult = null; lastAPSResult = null;
lastAPSRun = 0; lastAPSRun = 0;
@ -196,7 +188,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
try { try {
determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now)); determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS; lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;

View file

@ -11,8 +11,6 @@ import org.mozilla.javascript.RhinoException;
import org.mozilla.javascript.Scriptable; import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.ScriptableObject; import org.mozilla.javascript.ScriptableObject;
import org.mozilla.javascript.Undefined; import org.mozilla.javascript.Undefined;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -27,7 +25,8 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.TemporaryBasal; import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback; import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker; import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
@ -39,7 +38,7 @@ import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.SafeParse; import info.nightscout.androidaps.utils.SafeParse;
public class DetermineBasalAdapterSMBJS { public class DetermineBasalAdapterSMBJS {
private static Logger log = LoggerFactory.getLogger(L.APS); private final AAPSLogger aapsLogger;
private ScriptReader mScriptReader; private ScriptReader mScriptReader;
@ -68,8 +67,9 @@ public class DetermineBasalAdapterSMBJS {
* Main code * Main code
*/ */
DetermineBasalAdapterSMBJS(ScriptReader scriptReader) { DetermineBasalAdapterSMBJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
mScriptReader = scriptReader; mScriptReader = scriptReader;
this.aapsLogger = aapsLogger;
} }
@ -77,21 +77,20 @@ public class DetermineBasalAdapterSMBJS {
public DetermineBasalResultSMB invoke() { public DetermineBasalResultSMB invoke() {
if (L.isEnabled(L.APS)) { aapsLogger.debug(LTag.APS, ">>> Invoking detemine_basal <<<");
log.debug(">>> Invoking detemine_basal <<<"); aapsLogger.debug(LTag.APS, "Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
log.debug("Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString())); aapsLogger.debug(LTag.APS, "IOB data: " + (storedIobData = mIobData.toString()));
log.debug("IOB data: " + (storedIobData = mIobData.toString())); aapsLogger.debug(LTag.APS, "Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
log.debug("Current temp: " + (storedCurrentTemp = mCurrentTemp.toString())); aapsLogger.debug(LTag.APS, "Profile: " + (storedProfile = mProfile.toString()));
log.debug("Profile: " + (storedProfile = mProfile.toString())); aapsLogger.debug(LTag.APS, "Meal data: " + (storedMeal_data = mMealData.toString()));
log.debug("Meal data: " + (storedMeal_data = mMealData.toString()));
if (mAutosensData != null) if (mAutosensData != null)
log.debug("Autosens data: " + (storedAutosens_data = mAutosensData.toString())); aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
else else
log.debug("Autosens data: " + (storedAutosens_data = "undefined")); aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = "undefined"));
log.debug("Reservoir data: " + "undefined"); aapsLogger.debug(LTag.APS, "Reservoir data: " + "undefined");
log.debug("MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed)); aapsLogger.debug(LTag.APS, "MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed));
log.debug("SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed)); aapsLogger.debug(LTag.APS, "SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed));
}
DetermineBasalResultSMB determineBasalResultSMB = null; DetermineBasalResultSMB determineBasalResultSMB = null;
@ -142,22 +141,21 @@ public class DetermineBasalAdapterSMBJS {
// Parse the jsResult object to a JSON-String // Parse the jsResult object to a JSON-String
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString(); String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, "Result: " + result);
log.debug("Result: " + result);
try { try {
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result)); determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result), aapsLogger);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
} else { } else {
log.error("Problem loading JS Functions"); aapsLogger.error(LTag.APS, "Problem loading JS Functions");
} }
} catch (IOException e) { } catch (IOException e) {
log.error("IOException"); aapsLogger.error(LTag.APS, "IOException");
} catch (RhinoException e) { } catch (RhinoException e) {
log.error("RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString()); aapsLogger.error(LTag.APS, "RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) { } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
log.error(e.toString()); aapsLogger.error(LTag.APS, e.toString());
} finally { } finally {
Context.exit(); Context.exit();
} }

View file

@ -2,21 +2,20 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
public class DetermineBasalResultSMB extends APSResult { public class DetermineBasalResultSMB extends APSResult {
private static final Logger log = LoggerFactory.getLogger(L.APS); private final AAPSLogger aapsLogger;
private double eventualBG; private double eventualBG;
private double snoozeBG; private double snoozeBG;
DetermineBasalResultSMB(JSONObject result) { DetermineBasalResultSMB(JSONObject result, AAPSLogger aapsLogger) {
this(); this(aapsLogger);
date = DateUtil.now(); date = DateUtil.now();
json = result; json = result;
try { try {
@ -53,21 +52,22 @@ public class DetermineBasalResultSMB extends APSResult {
try { try {
deliverAt = DateUtil.fromISODateString(date).getTime(); deliverAt = DateUtil.fromISODateString(date).getTime();
} catch (Exception e) { } catch (Exception e) {
log.warn("Error parsing 'deliverAt' date: " + date, e); aapsLogger.error(LTag.APS, "Error parsing 'deliverAt' date: " + date, e);
} }
} }
} catch (JSONException e) { } catch (JSONException e) {
log.error("Error parsing determine-basal result JSON", e); aapsLogger.error(LTag.APS, "Error parsing determine-basal result JSON", e);
} }
} }
private DetermineBasalResultSMB() { private DetermineBasalResultSMB(AAPSLogger aapsLogger) {
hasPredictions = true; hasPredictions = true;
this.aapsLogger = aapsLogger;
} }
@Override @Override
public DetermineBasalResultSMB clone() { public DetermineBasalResultSMB clone() {
DetermineBasalResultSMB newResult = new DetermineBasalResultSMB(); DetermineBasalResultSMB newResult = new DetermineBasalResultSMB(aapsLogger);
doClone(newResult); doClone(newResult);
newResult.eventualBG = eventualBG; newResult.eventualBG = eventualBG;
@ -80,7 +80,7 @@ public class DetermineBasalResultSMB extends APSResult {
try { try {
return new JSONObject(this.json.toString()); return new JSONObject(this.json.toString());
} catch (JSONException e) { } catch (JSONException e) {
log.error("Error converting determine-basal result to JSON", e); aapsLogger.error(LTag.APS, "Error converting determine-basal result to JSON", e);
} }
return null; return null;
} }

View file

@ -9,7 +9,8 @@ import android.view.ViewGroup
import dagger.android.support.DaggerFragment import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.MainApp import info.nightscout.androidaps.MainApp
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.logging.L import info.nightscout.androidaps.logging.AAPSLogger
import info.nightscout.androidaps.logging.LTag
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
import info.nightscout.androidaps.plugins.bus.RxBus import info.nightscout.androidaps.plugins.bus.RxBus
@ -22,16 +23,17 @@ import io.reactivex.disposables.CompositeDisposable
import kotlinx.android.synthetic.main.openapsama_fragment.* import kotlinx.android.synthetic.main.openapsama_fragment.*
import org.json.JSONArray import org.json.JSONArray
import org.json.JSONException import org.json.JSONException
import org.slf4j.LoggerFactory
import javax.inject.Inject import javax.inject.Inject
class OpenAPSSMBFragment : DaggerFragment() { class OpenAPSSMBFragment : DaggerFragment() {
private val log = LoggerFactory.getLogger(L.APS)
private var disposable: CompositeDisposable = CompositeDisposable() private var disposable: CompositeDisposable = CompositeDisposable()
@Inject @Inject
lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
@Inject
lateinit var aapsLogger: AAPSLogger
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? { savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.openapsama_fragment, container, false) return inflater.inflate(R.layout.openapsama_fragment, container, false)
@ -88,7 +90,7 @@ class OpenAPSSMBFragment : DaggerFragment() {
val iobArray = JSONArray(determineBasalAdapterSMBJS.iobDataParam) val iobArray = JSONArray(determineBasalAdapterSMBJS.iobDataParam)
openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0))) openapsma_iobdata.text = TextUtils.concat(String.format(MainApp.gs(R.string.array_of_elements), iobArray.length()) + "\n", JSONFormatter.format(iobArray.getString(0)))
} catch (e: JSONException) { } catch (e: JSONException) {
log.error("Unhandled exception", e) aapsLogger.error(LTag.APS, "Unhandled exception", e)
@SuppressLint("SetTextl18n") @SuppressLint("SetTextl18n")
openapsma_iobdata.text = "JSONException see log for details" openapsma_iobdata.text = "JSONException see log for details"
} }

View file

@ -2,8 +2,6 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.json.JSONException; import org.json.JSONException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -21,7 +19,8 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription; import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface; import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
import info.nightscout.androidaps.plugins.aps.loop.APSResult; import info.nightscout.androidaps.plugins.aps.loop.APSResult;
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader; import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui; import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
@ -45,9 +44,9 @@ import info.nightscout.androidaps.utils.ToastUtils;
@Singleton @Singleton
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface { public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
private static Logger log = LoggerFactory.getLogger(L.APS);
private static OpenAPSSMBPlugin openAPSSMBPlugin; private static OpenAPSSMBPlugin openAPSSMBPlugin;
private final AAPSLogger aapsLogger;
/** /**
* @deprecated Use dagger to get an instance * @deprecated Use dagger to get an instance
@ -66,7 +65,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
AutosensResult lastAutosensResult = null; AutosensResult lastAutosensResult = null;
@Inject @Inject
public OpenAPSSMBPlugin() { public OpenAPSSMBPlugin(AAPSLogger aapsLogger) {
super(new PluginDescription() super(new PluginDescription()
.mainType(PluginType.APS) .mainType(PluginType.APS)
.fragmentClass(OpenAPSSMBFragment.class.getName()) .fragmentClass(OpenAPSSMBFragment.class.getName())
@ -76,6 +75,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
.description(R.string.description_smb) .description(R.string.description_smb)
); );
this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger
this.aapsLogger = aapsLogger;
} }
@Override @Override
@ -102,11 +102,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
@Override @Override
public void invoke(String initiator, boolean tempBasalFallback) { public void invoke(String initiator, boolean tempBasalFallback) {
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
lastAPSResult = null; lastAPSResult = null;
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS; DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext())); determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData(); GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
Profile profile = ProfileFunctions.getInstance().getProfile(); Profile profile = ProfileFunctions.getInstance().getProfile();
@ -114,29 +113,25 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
if (profile == null) { if (profile == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
log.debug(MainApp.gs(R.string.noprofileselected));
return; return;
} }
if (pump == null) { if (pump == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
log.debug(MainApp.gs(R.string.nopumpselected));
return; return;
} }
if (!isEnabled(PluginType.APS)) { if (!isEnabled(PluginType.APS)) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
log.debug(MainApp.gs(R.string.openapsma_disabled));
return; return;
} }
if (glucoseStatus == null) { if (glucoseStatus == null) {
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata))); RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
if (L.isEnabled(L.APS)) aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
return; return;
} }
@ -156,8 +151,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
long startPart = System.currentTimeMillis(); long startPart = System.currentTimeMillis();
MealData mealData = TreatmentsPlugin.getPlugin().getMealData(); MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
Profiler.log(log, "getMealData()", startPart);
Constraint<Double> maxIOBAllowedConstraint = ConstraintChecker.getInstance().getMaxIOBAllowed(); Constraint<Double> maxIOBAllowedConstraint = ConstraintChecker.getInstance().getMaxIOBAllowed();
inputConstraints.copyReasons(maxIOBAllowedConstraint); inputConstraints.copyReasons(maxIOBAllowedConstraint);
@ -202,8 +196,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
} }
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget); IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
Profiler.log(log, "calculateIobArrayInDia()", startPart);
startPart = System.currentTimeMillis(); startPart = System.currentTimeMillis();
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback); Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
@ -218,10 +211,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
ConstraintChecker.getInstance().isUAMEnabled(uam); ConstraintChecker.getInstance().isUAMEnabled(uam);
inputConstraints.copyReasons(uam); inputConstraints.copyReasons(uam);
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart); Profiler.log(aapsLogger, LTag.APS, "SMB data gathering", start);
if (L.isEnabled(L.APS))
Profiler.log(log, "SMB data gathering", start);
start = System.currentTimeMillis(); start = System.currentTimeMillis();
try { try {
@ -240,11 +231,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke(); DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
if (L.isEnabled(L.APS)) Profiler.log(aapsLogger, LTag.APS, "SMB calculation", start);
Profiler.log(log, "SMB calculation", start);
if (determineBasalResultSMB == null) { if (determineBasalResultSMB == null) {
if (L.isEnabled(L.APS)) aapsLogger.error(LTag.APS, "SMB calculation returned null");
log.error("SMB calculation returned null");
lastDetermineBasalAdapterSMBJS = null; lastDetermineBasalAdapterSMBJS = null;
lastAPSResult = null; lastAPSResult = null;
lastAPSRun = 0; lastAPSRun = 0;
@ -259,7 +248,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
try { try {
determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now)); determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now));
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); aapsLogger.error(LTag.APS, "Unhandled exception", e);
} }
determineBasalResultSMB.inputConstraints = inputConstraints; determineBasalResultSMB.inputConstraints = inputConstraints;
@ -274,11 +263,11 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
} }
// safety checks // safety checks
private static boolean checkOnlyHardLimits(Double value, String valueName, double lowLimit, double highLimit) { private boolean checkOnlyHardLimits(Double value, String valueName, double lowLimit, double highLimit) {
return value.equals(verifyHardLimits(value, valueName, lowLimit, highLimit)); return value.equals(verifyHardLimits(value, valueName, lowLimit, highLimit));
} }
private static Double verifyHardLimits(Double value, String valueName, double lowLimit, double highLimit) { private Double verifyHardLimits(Double value, String valueName, double lowLimit, double highLimit) {
Double newvalue = value; Double newvalue = value;
if (newvalue < lowLimit || newvalue > highLimit) { if (newvalue < lowLimit || newvalue > highLimit) {
newvalue = Math.max(newvalue, lowLimit); newvalue = Math.max(newvalue, lowLimit);
@ -286,7 +275,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
String msg = String.format(MainApp.gs(R.string.valueoutofrange), valueName); String msg = String.format(MainApp.gs(R.string.valueoutofrange), valueName);
msg += ".\n"; msg += ".\n";
msg += String.format(MainApp.gs(R.string.valuelimitedto), value, newvalue); msg += String.format(MainApp.gs(R.string.valuelimitedto), value, newvalue);
log.error(msg); aapsLogger.error(LTag.APS, msg);
NSUpload.uploadError(msg); NSUpload.uploadError(msg);
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error); ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error);
} }

View file

@ -2,15 +2,25 @@ package info.nightscout.androidaps.utils;
import org.slf4j.Logger; import org.slf4j.Logger;
import info.nightscout.androidaps.logging.AAPSLogger;
import info.nightscout.androidaps.logging.LTag;
/** /**
* Created by mike on 29.01.2017. * Created by mike on 29.01.2017.
*/ */
public class Profiler { public class Profiler {
public Profiler(){} public Profiler() {
}
@Deprecated
static public void log(Logger log, String function, long start) { static public void log(Logger log, String function, long start) {
long msec = System.currentTimeMillis() - start; long msec = System.currentTimeMillis() - start;
log.debug(">>> " + function + " <<< executed in " + msec + " miliseconds"); log.debug(">>> " + function + " <<< executed in " + msec + " miliseconds");
} }
static public void log(AAPSLogger log, LTag lTag, String function, long start) {
long msec = System.currentTimeMillis() - start;
log.debug(lTag, ">>> " + function + " <<< executed in " + msec + " miliseconds");
}
} }