add new logger to APS plugins
This commit is contained in:
parent
6752cbae94
commit
93bc179181
|
@ -5,6 +5,7 @@ import dagger.Component
|
|||
import dagger.android.AndroidInjectionModule
|
||||
import dagger.android.AndroidInjector
|
||||
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.general.automation.actions.ActionSendSMS
|
||||
import info.nightscout.androidaps.queue.commands.CommandSetProfile
|
||||
|
@ -30,6 +31,8 @@ interface AppComponent : AndroidInjector<MainApp> {
|
|||
|
||||
fun injectObjective5(objective5: Objective5)
|
||||
|
||||
fun injectLoggerCallback(loggerCallback: LoggerCallback)
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import info.nightscout.androidaps.MainApp
|
|||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.AAPSLoggerDebug
|
||||
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.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctionImplementation
|
||||
|
@ -65,16 +66,19 @@ class AppModule {
|
|||
interface AppBindings {
|
||||
|
||||
@ContributesAndroidInjector
|
||||
fun bindDataService(): DataService
|
||||
fun dataServiceInjector(): DataService
|
||||
|
||||
@ContributesAndroidInjector
|
||||
fun bindCommandSetProfile(): CommandSetProfile
|
||||
fun commandSetProfileInjector(): CommandSetProfile
|
||||
|
||||
@ContributesAndroidInjector
|
||||
fun bindActionSendSMS(): ActionSendSMS
|
||||
fun actionSendSMSInjector(): ActionSendSMS
|
||||
|
||||
@ContributesAndroidInjector
|
||||
fun bindObjective5(): Objective5
|
||||
fun objective5Injector(): Objective5
|
||||
|
||||
@ContributesAndroidInjector
|
||||
fun loggerCallbackInjector(): LoggerCallback
|
||||
|
||||
@Binds
|
||||
fun bindContext(mainApp: MainApp): Context
|
||||
|
|
|
@ -11,8 +11,6 @@ import org.mozilla.javascript.RhinoException;
|
|||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.Undefined;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
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.Profile;
|
||||
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.openAPSMA.LoggerCallback;
|
||||
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;
|
||||
|
||||
public class DetermineBasalAdapterAMAJS {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
private final AAPSLogger aapsLogger;
|
||||
|
||||
|
||||
private ScriptReader mScriptReader = null;
|
||||
|
@ -59,25 +58,25 @@ public class DetermineBasalAdapterAMAJS {
|
|||
|
||||
private String scriptDebug = "";
|
||||
|
||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader) {
|
||||
public DetermineBasalAdapterAMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
|
||||
mScriptReader = scriptReader;
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DetermineBasalResultAMA invoke() {
|
||||
|
||||
if (L.isEnabled(L.APS)) {
|
||||
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"));
|
||||
}
|
||||
aapsLogger.debug(LTag.APS, ">>> Invoking detemine_basal <<<");
|
||||
aapsLogger.debug(LTag.APS, "Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
aapsLogger.debug(LTag.APS, "IOB data: " + (storedIobData = mIobData.toString()));
|
||||
aapsLogger.debug(LTag.APS, "Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||
aapsLogger.debug(LTag.APS, "Profile: " + (storedProfile = mProfile.toString()));
|
||||
aapsLogger.debug(LTag.APS, "Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||
if (mAutosensData != null)
|
||||
aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||
else
|
||||
aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = "undefined"));
|
||||
|
||||
|
||||
DetermineBasalResultAMA determineBasalResultAMA = null;
|
||||
|
||||
|
@ -124,22 +123,21 @@ public class DetermineBasalAdapterAMAJS {
|
|||
|
||||
// Parse the jsResult object to a JSON-String
|
||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug("Result: " + result);
|
||||
aapsLogger.debug(LTag.APS, "Result: " + result);
|
||||
try {
|
||||
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result));
|
||||
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result), aapsLogger);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
} else {
|
||||
log.error("Problem loading JS Functions");
|
||||
aapsLogger.error(LTag.APS, "Problem loading JS Functions");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("IOException");
|
||||
aapsLogger.error(LTag.APS, "IOException");
|
||||
} 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) {
|
||||
log.error(e.toString());
|
||||
aapsLogger.error(LTag.APS, e.toString());
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
|
|
|
@ -3,21 +3,20 @@ package info.nightscout.androidaps.plugins.aps.openAPSAMA;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
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.utils.DateUtil;
|
||||
|
||||
public class DetermineBasalResultAMA extends APSResult {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
private AAPSLogger aapsLogger;
|
||||
|
||||
private double eventualBG;
|
||||
private double snoozeBG;
|
||||
|
||||
DetermineBasalResultAMA(NativeObject result, JSONObject j) {
|
||||
this();
|
||||
DetermineBasalResultAMA(NativeObject result, JSONObject j, AAPSLogger aapsLogger) {
|
||||
this(aapsLogger);
|
||||
date = DateUtil.now();
|
||||
json = j;
|
||||
if (result.containsKey("error")) {
|
||||
|
@ -48,13 +47,14 @@ public class DetermineBasalResultAMA extends APSResult {
|
|||
bolusRequested = false;
|
||||
}
|
||||
|
||||
private DetermineBasalResultAMA() {
|
||||
private DetermineBasalResultAMA(AAPSLogger aapsLogger) {
|
||||
hasPredictions = true;
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DetermineBasalResultAMA clone() {
|
||||
DetermineBasalResultAMA newResult = new DetermineBasalResultAMA();
|
||||
DetermineBasalResultAMA newResult = new DetermineBasalResultAMA(aapsLogger);
|
||||
doClone(newResult);
|
||||
|
||||
newResult.eventualBG = eventualBG;
|
||||
|
@ -68,7 +68,7 @@ public class DetermineBasalResultAMA extends APSResult {
|
|||
JSONObject ret = new JSONObject(this.json.toString());
|
||||
return ret;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import android.view.ViewGroup
|
|||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.MainApp
|
||||
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.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
|
@ -21,16 +22,17 @@ import io.reactivex.disposables.CompositeDisposable
|
|||
import kotlinx.android.synthetic.main.openapsama_fragment.*
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSAMAFragment : DaggerFragment() {
|
||||
private val log = LoggerFactory.getLogger(L.APS)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
||||
|
||||
@Inject
|
||||
lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.openapsama_fragment, container, false)
|
||||
|
@ -88,7 +90,7 @@ class OpenAPSAMAFragment : DaggerFragment() {
|
|||
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)))
|
||||
} catch (e: JSONException) {
|
||||
log.error("Unhandled exception", e)
|
||||
aapsLogger.error(LTag.APS,"Unhandled exception", e)
|
||||
openapsma_iobdata.text = "JSONException see log for details"
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
package info.nightscout.androidaps.plugins.aps.openAPSAMA;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
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.PluginType;
|
||||
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.ScriptReader;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
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.iob.iobCobCalculator.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||
|
@ -40,8 +39,8 @@ import info.nightscout.androidaps.utils.Round;
|
|||
|
||||
@Singleton
|
||||
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
|
||||
private final AAPSLogger aapsLogger;
|
||||
// last values
|
||||
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
||||
long lastAPSRun = 0;
|
||||
|
@ -49,7 +48,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
AutosensResult lastAutosensResult = null;
|
||||
|
||||
@Inject
|
||||
public OpenAPSAMAPlugin() {
|
||||
public OpenAPSAMAPlugin(AAPSLogger aapsLogger) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSAMAFragment.class.getName())
|
||||
|
@ -58,6 +57,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
.preferencesId(R.xml.pref_openapsama)
|
||||
.description(R.string.description_ama)
|
||||
);
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,11 +84,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||
|
@ -96,29 +95,25 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (profile == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pump == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.nopumpselected));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEnabled(PluginType.APS)) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.openapsma_disabled));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
|
||||
return;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -133,13 +128,11 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
long start = System.currentTimeMillis();
|
||||
long startPart = System.currentTimeMillis();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = System.currentTimeMillis();
|
||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "getMealData()", startPart);
|
||||
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
||||
|
||||
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
||||
|
||||
|
@ -180,10 +173,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
lastAutosensResult = new AutosensResult();
|
||||
lastAutosensResult.sensResult = "autosens disabled";
|
||||
}
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "AMA data gathering", start);
|
||||
Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
Profiler.log(aapsLogger, LTag.APS, "AMA data gathering", start);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
|
||||
|
@ -199,12 +190,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
|
||||
DetermineBasalResultAMA determineBasalResultAMA = determineBasalAdapterAMAJS.invoke();
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "AMA calculation", start);
|
||||
Profiler.log(aapsLogger, LTag.APS, "AMA calculation", start);
|
||||
// Fix bug determine basal
|
||||
if (determineBasalResultAMA == null) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.error("SMB calculation returned null");
|
||||
aapsLogger.error(LTag.APS, "SMB calculation returned null");
|
||||
lastDetermineBasalAdapterAMAJS = null;
|
||||
lastAPSResult = null;
|
||||
lastAPSRun = 0;
|
||||
|
@ -219,7 +208,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
try {
|
||||
determineBasalResultAMA.json.put("timestamp", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
|
||||
lastDetermineBasalAdapterAMAJS = determineBasalAdapterAMAJS;
|
||||
|
|
|
@ -9,8 +9,6 @@ import org.mozilla.javascript.NativeObject;
|
|||
import org.mozilla.javascript.RhinoException;
|
||||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -20,20 +18,22 @@ import javax.annotation.Nullable;
|
|||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
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.MealData;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
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.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
|
||||
public class DetermineBasalAdapterMAJS {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
|
||||
private final AAPSLogger aapsLogger;
|
||||
private ScriptReader mScriptReader;
|
||||
private JSONObject mProfile;
|
||||
private JSONObject mGlucoseStatus;
|
||||
|
@ -47,8 +47,9 @@ public class DetermineBasalAdapterMAJS {
|
|||
private String storedProfile = null;
|
||||
private String storedMeal_data = null;
|
||||
|
||||
DetermineBasalAdapterMAJS(ScriptReader scriptReader) {
|
||||
DetermineBasalAdapterMAJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
|
||||
mScriptReader = scriptReader;
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -102,21 +103,21 @@ public class DetermineBasalAdapterMAJS {
|
|||
// Parse the jsResult object to a JSON-String
|
||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug("Result: " + result);
|
||||
aapsLogger.debug(LTag.APS, "Result: " + result);
|
||||
try {
|
||||
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result));
|
||||
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result), aapsLogger);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
} else {
|
||||
log.debug("Problem loading JS Functions");
|
||||
aapsLogger.debug(LTag.APS, "Problem loading JS Functions");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("IOException");
|
||||
aapsLogger.error(LTag.APS, "IOException");
|
||||
} 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) {
|
||||
log.error(e.toString());
|
||||
aapsLogger.error(LTag.APS, e.toString());
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
|
|
|
@ -3,20 +3,20 @@ package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
|||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
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;
|
||||
|
||||
public class DetermineBasalResultMA extends APSResult {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
private AAPSLogger aapsLogger;
|
||||
|
||||
private double eventualBG;
|
||||
private double snoozeBG;
|
||||
private String mealAssist;
|
||||
|
||||
DetermineBasalResultMA(NativeObject result, JSONObject j) {
|
||||
DetermineBasalResultMA(NativeObject result, JSONObject j, AAPSLogger aapsLogger) {
|
||||
this(aapsLogger);
|
||||
json = j;
|
||||
if (result.containsKey("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
|
||||
public DetermineBasalResultMA clone() {
|
||||
DetermineBasalResultMA newResult = new DetermineBasalResultMA();
|
||||
DetermineBasalResultMA newResult = new DetermineBasalResultMA(aapsLogger);
|
||||
doClone(newResult);
|
||||
|
||||
newResult.eventualBG = eventualBG;
|
||||
|
@ -69,7 +70,7 @@ public class DetermineBasalResultMA extends APSResult {
|
|||
JSONObject ret = new JSONObject(this.json.toString());
|
||||
return ret;
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
||||
|
||||
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.
|
||||
|
@ -13,7 +15,8 @@ import info.nightscout.androidaps.logging.L;
|
|||
|
||||
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 logBuffer = new StringBuffer();
|
||||
|
@ -23,6 +26,7 @@ public class LoggerCallback extends ScriptableObject {
|
|||
//empty constructor needed for Rhino
|
||||
errorBuffer = new StringBuffer();
|
||||
logBuffer = new StringBuffer();
|
||||
MainApp.instance().androidInjector().inject(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,14 +39,12 @@ public class LoggerCallback extends ScriptableObject {
|
|||
}
|
||||
|
||||
public void jsFunction_log(Object obj1) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(obj1.toString().trim());
|
||||
aapsLogger.debug(LTag.APS, obj1.toString().trim());
|
||||
logBuffer.append(obj1.toString());
|
||||
}
|
||||
|
||||
public void jsFunction_error(Object obj1) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.error(obj1.toString().trim());
|
||||
aapsLogger.error(LTag.APS, obj1.toString().trim());
|
||||
errorBuffer.append(obj1.toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory
|
|||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSMAFragment : DaggerFragment() {
|
||||
private val log = LoggerFactory.getLogger(L.APS)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
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.PluginType;
|
||||
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.ScriptReader;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
||||
|
@ -40,7 +39,7 @@ import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
|
|||
|
||||
@Singleton
|
||||
public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
private final AAPSLogger aapsLogger;
|
||||
|
||||
// last values
|
||||
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
|
||||
|
@ -48,7 +47,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
DetermineBasalResultMA lastAPSResult = null;
|
||||
|
||||
@Inject
|
||||
public OpenAPSMAPlugin() {
|
||||
public OpenAPSMAPlugin(AAPSLogger aapsLogger) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSMAFragment.class.getName())
|
||||
|
@ -57,6 +56,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
.preferencesId(R.xml.pref_openapsma)
|
||||
.description(R.string.description_ma)
|
||||
);
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -83,11 +83,10 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
|
||||
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||
|
@ -95,29 +94,25 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
if (profile == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pump == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.nopumpselected));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEnabled(PluginType.APS)) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.openapsma_disabled));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
|
||||
return;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -141,8 +136,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
|
||||
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "MA data gathering", start);
|
||||
Profiler.log(aapsLogger, LTag.APS, "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]);
|
||||
|
@ -173,16 +167,14 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
FabricPrivacy.logException(e);
|
||||
return;
|
||||
}
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "MA calculation", start);
|
||||
Profiler.log(aapsLogger, LTag.APS, "MA calculation", start);
|
||||
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
|
||||
if (determineBasalResultMA == null) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.error("MA calculation returned null");
|
||||
aapsLogger.error(LTag.APS, "MA calculation returned null");
|
||||
lastDetermineBasalAdapterMAJS = null;
|
||||
lastAPSResult = null;
|
||||
lastAPSRun = 0;
|
||||
|
@ -196,7 +188,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
try {
|
||||
determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
|
||||
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
|
||||
|
|
|
@ -11,8 +11,6 @@ import org.mozilla.javascript.RhinoException;
|
|||
import org.mozilla.javascript.Scriptable;
|
||||
import org.mozilla.javascript.ScriptableObject;
|
||||
import org.mozilla.javascript.Undefined;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
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.Profile;
|
||||
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.openAPSMA.LoggerCallback;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
|
@ -39,7 +38,7 @@ import info.nightscout.androidaps.utils.SP;
|
|||
import info.nightscout.androidaps.utils.SafeParse;
|
||||
|
||||
public class DetermineBasalAdapterSMBJS {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
private final AAPSLogger aapsLogger;
|
||||
|
||||
|
||||
private ScriptReader mScriptReader;
|
||||
|
@ -68,8 +67,9 @@ public class DetermineBasalAdapterSMBJS {
|
|||
* Main code
|
||||
*/
|
||||
|
||||
DetermineBasalAdapterSMBJS(ScriptReader scriptReader) {
|
||||
DetermineBasalAdapterSMBJS(ScriptReader scriptReader, AAPSLogger aapsLogger) {
|
||||
mScriptReader = scriptReader;
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
|
||||
|
@ -77,21 +77,20 @@ public class DetermineBasalAdapterSMBJS {
|
|||
public DetermineBasalResultSMB invoke() {
|
||||
|
||||
|
||||
if (L.isEnabled(L.APS)) {
|
||||
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));
|
||||
}
|
||||
aapsLogger.debug(LTag.APS, ">>> Invoking detemine_basal <<<");
|
||||
aapsLogger.debug(LTag.APS, "Glucose status: " + (storedGlucoseStatus = mGlucoseStatus.toString()));
|
||||
aapsLogger.debug(LTag.APS, "IOB data: " + (storedIobData = mIobData.toString()));
|
||||
aapsLogger.debug(LTag.APS, "Current temp: " + (storedCurrentTemp = mCurrentTemp.toString()));
|
||||
aapsLogger.debug(LTag.APS, "Profile: " + (storedProfile = mProfile.toString()));
|
||||
aapsLogger.debug(LTag.APS, "Meal data: " + (storedMeal_data = mMealData.toString()));
|
||||
if (mAutosensData != null)
|
||||
aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = mAutosensData.toString()));
|
||||
else
|
||||
aapsLogger.debug(LTag.APS, "Autosens data: " + (storedAutosens_data = "undefined"));
|
||||
aapsLogger.debug(LTag.APS, "Reservoir data: " + "undefined");
|
||||
aapsLogger.debug(LTag.APS, "MicroBolusAllowed: " + (storedMicroBolusAllowed = "" + mMicrobolusAllowed));
|
||||
aapsLogger.debug(LTag.APS, "SMBAlwaysAllowed: " + (storedSMBAlwaysAllowed = "" + mSMBAlwaysAllowed));
|
||||
|
||||
|
||||
DetermineBasalResultSMB determineBasalResultSMB = null;
|
||||
|
||||
|
@ -142,22 +141,21 @@ public class DetermineBasalAdapterSMBJS {
|
|||
|
||||
// Parse the jsResult object to a JSON-String
|
||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug("Result: " + result);
|
||||
aapsLogger.debug(LTag.APS, "Result: " + result);
|
||||
try {
|
||||
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result));
|
||||
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result), aapsLogger);
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
} else {
|
||||
log.error("Problem loading JS Functions");
|
||||
aapsLogger.error(LTag.APS, "Problem loading JS Functions");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("IOException");
|
||||
aapsLogger.error(LTag.APS, "IOException");
|
||||
} 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) {
|
||||
log.error(e.toString());
|
||||
aapsLogger.error(LTag.APS, e.toString());
|
||||
} finally {
|
||||
Context.exit();
|
||||
}
|
||||
|
|
|
@ -2,21 +2,20 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
|
|||
|
||||
import org.json.JSONException;
|
||||
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.utils.DateUtil;
|
||||
|
||||
public class DetermineBasalResultSMB extends APSResult {
|
||||
private static final Logger log = LoggerFactory.getLogger(L.APS);
|
||||
private final AAPSLogger aapsLogger;
|
||||
|
||||
private double eventualBG;
|
||||
private double snoozeBG;
|
||||
|
||||
DetermineBasalResultSMB(JSONObject result) {
|
||||
this();
|
||||
DetermineBasalResultSMB(JSONObject result, AAPSLogger aapsLogger) {
|
||||
this(aapsLogger);
|
||||
date = DateUtil.now();
|
||||
json = result;
|
||||
try {
|
||||
|
@ -53,21 +52,22 @@ public class DetermineBasalResultSMB extends APSResult {
|
|||
try {
|
||||
deliverAt = DateUtil.fromISODateString(date).getTime();
|
||||
} catch (Exception e) {
|
||||
log.warn("Error parsing 'deliverAt' date: " + date, e);
|
||||
aapsLogger.error(LTag.APS, "Error parsing 'deliverAt' date: " + date, 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;
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DetermineBasalResultSMB clone() {
|
||||
DetermineBasalResultSMB newResult = new DetermineBasalResultSMB();
|
||||
DetermineBasalResultSMB newResult = new DetermineBasalResultSMB(aapsLogger);
|
||||
doClone(newResult);
|
||||
|
||||
newResult.eventualBG = eventualBG;
|
||||
|
@ -80,7 +80,7 @@ public class DetermineBasalResultSMB extends APSResult {
|
|||
try {
|
||||
return new JSONObject(this.json.toString());
|
||||
} 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;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ import android.view.ViewGroup
|
|||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.MainApp
|
||||
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.EventOpenAPSUpdateResultGui
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus
|
||||
|
@ -22,16 +23,17 @@ import io.reactivex.disposables.CompositeDisposable
|
|||
import kotlinx.android.synthetic.main.openapsama_fragment.*
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONException
|
||||
import org.slf4j.LoggerFactory
|
||||
import javax.inject.Inject
|
||||
|
||||
class OpenAPSSMBFragment : DaggerFragment() {
|
||||
private val log = LoggerFactory.getLogger(L.APS)
|
||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
||||
|
||||
@Inject
|
||||
lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
||||
|
||||
@Inject
|
||||
lateinit var aapsLogger: AAPSLogger
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.openapsama_fragment, container, false)
|
||||
|
@ -88,7 +90,7 @@ class OpenAPSSMBFragment : DaggerFragment() {
|
|||
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)))
|
||||
} catch (e: JSONException) {
|
||||
log.error("Unhandled exception", e)
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e)
|
||||
@SuppressLint("SetTextl18n")
|
||||
openapsma_iobdata.text = "JSONException see log for details"
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@ package info.nightscout.androidaps.plugins.aps.openAPSSMB;
|
|||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
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.PluginType;
|
||||
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.ScriptReader;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
||||
|
@ -45,9 +44,9 @@ import info.nightscout.androidaps.utils.ToastUtils;
|
|||
|
||||
@Singleton
|
||||
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
|
||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
||||
|
||||
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
private final AAPSLogger aapsLogger;
|
||||
|
||||
/**
|
||||
* @deprecated Use dagger to get an instance
|
||||
|
@ -66,7 +65,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
AutosensResult lastAutosensResult = null;
|
||||
|
||||
@Inject
|
||||
public OpenAPSSMBPlugin() {
|
||||
public OpenAPSSMBPlugin(AAPSLogger aapsLogger) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
.fragmentClass(OpenAPSSMBFragment.class.getName())
|
||||
|
@ -76,6 +75,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
.description(R.string.description_smb)
|
||||
);
|
||||
this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger
|
||||
this.aapsLogger = aapsLogger;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -102,11 +102,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
|
||||
@Override
|
||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug("invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||
lastAPSResult = null;
|
||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
|
||||
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()));
|
||||
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
|
||||
|
||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||
|
@ -114,29 +113,25 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
|
||||
if (profile == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.noprofileselected));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pump == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.nopumpselected));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isEnabled(PluginType.APS)) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.openapsma_disabled));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
|
||||
return;
|
||||
}
|
||||
|
||||
if (glucoseStatus == null) {
|
||||
RxBus.INSTANCE.send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
||||
if (L.isEnabled(L.APS))
|
||||
log.debug(MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -156,8 +151,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
long startPart = System.currentTimeMillis();
|
||||
|
||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "getMealData()", startPart);
|
||||
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
||||
|
||||
Constraint<Double> maxIOBAllowedConstraint = ConstraintChecker.getInstance().getMaxIOBAllowed();
|
||||
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);
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "calculateIobArrayInDia()", startPart);
|
||||
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = System.currentTimeMillis();
|
||||
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
|
||||
|
@ -218,10 +211,8 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
ConstraintChecker.getInstance().isUAMEnabled(uam);
|
||||
inputConstraints.copyReasons(uam);
|
||||
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "SMB data gathering", start);
|
||||
Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
|
||||
Profiler.log(aapsLogger, LTag.APS, "SMB data gathering", start);
|
||||
|
||||
start = System.currentTimeMillis();
|
||||
try {
|
||||
|
@ -240,11 +231,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
long now = System.currentTimeMillis();
|
||||
|
||||
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
|
||||
if (L.isEnabled(L.APS))
|
||||
Profiler.log(log, "SMB calculation", start);
|
||||
Profiler.log(aapsLogger, LTag.APS, "SMB calculation", start);
|
||||
if (determineBasalResultSMB == null) {
|
||||
if (L.isEnabled(L.APS))
|
||||
log.error("SMB calculation returned null");
|
||||
aapsLogger.error(LTag.APS, "SMB calculation returned null");
|
||||
lastDetermineBasalAdapterSMBJS = null;
|
||||
lastAPSResult = null;
|
||||
lastAPSRun = 0;
|
||||
|
@ -259,7 +248,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
try {
|
||||
determineBasalResultSMB.json.put("timestamp", DateUtil.toISOString(now));
|
||||
} catch (JSONException e) {
|
||||
log.error("Unhandled exception", e);
|
||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
||||
}
|
||||
|
||||
determineBasalResultSMB.inputConstraints = inputConstraints;
|
||||
|
@ -274,11 +263,11 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
}
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
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;
|
||||
if (newvalue < lowLimit || newvalue > highLimit) {
|
||||
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);
|
||||
msg += ".\n";
|
||||
msg += String.format(MainApp.gs(R.string.valuelimitedto), value, newvalue);
|
||||
log.error(msg);
|
||||
aapsLogger.error(LTag.APS, msg);
|
||||
NSUpload.uploadError(msg);
|
||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error);
|
||||
}
|
||||
|
|
|
@ -2,15 +2,25 @@ package info.nightscout.androidaps.utils;
|
|||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
|
||||
/**
|
||||
* Created by mike on 29.01.2017.
|
||||
*/
|
||||
|
||||
public class Profiler {
|
||||
public Profiler(){}
|
||||
public Profiler() {
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
static public void log(Logger log, String function, long start) {
|
||||
long msec = System.currentTimeMillis() - start;
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue