Remove MA
This commit is contained in:
parent
a8d76cef4c
commit
bebe9015e8
22 changed files with 22 additions and 753 deletions
|
@ -19,7 +19,6 @@ import info.nightscout.androidaps.events.EventRebuildTabs
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
||||||
|
@ -80,7 +79,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
|
||||||
@Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin
|
@Inject lateinit var medtronicPumpPlugin: MedtronicPumpPlugin
|
||||||
@Inject lateinit var nsClientPlugin: NSClientPlugin
|
@Inject lateinit var nsClientPlugin: NSClientPlugin
|
||||||
@Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
@Inject lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
||||||
@Inject lateinit var openAPSMAPlugin: OpenAPSMAPlugin
|
|
||||||
@Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
@Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
||||||
@Inject lateinit var safetyPlugin: SafetyPlugin
|
@Inject lateinit var safetyPlugin: SafetyPlugin
|
||||||
@Inject lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin
|
@Inject lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin
|
||||||
|
@ -162,7 +160,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
|
||||||
addPreferencesFromResourceIfEnabled(glimpPlugin, rootKey)
|
addPreferencesFromResourceIfEnabled(glimpPlugin, rootKey)
|
||||||
addPreferencesFromResourceIfEnabled(careportalPlugin, rootKey)
|
addPreferencesFromResourceIfEnabled(careportalPlugin, rootKey)
|
||||||
addPreferencesFromResourceIfEnabled(loopPlugin, rootKey, Config.APS)
|
addPreferencesFromResourceIfEnabled(loopPlugin, rootKey, Config.APS)
|
||||||
addPreferencesFromResourceIfEnabled(openAPSMAPlugin, rootKey, Config.APS)
|
|
||||||
addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, rootKey, Config.APS)
|
addPreferencesFromResourceIfEnabled(openAPSAMAPlugin, rootKey, Config.APS)
|
||||||
addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, rootKey, Config.APS)
|
addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, rootKey, Config.APS)
|
||||||
addPreferencesFromResourceIfEnabled(sensitivityAAPSPlugin, rootKey)
|
addPreferencesFromResourceIfEnabled(sensitivityAAPSPlugin, rootKey)
|
||||||
|
|
|
@ -12,8 +12,7 @@ import info.nightscout.androidaps.db.BgReading
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch
|
import info.nightscout.androidaps.db.ProfileSwitch
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA
|
import info.nightscout.androidaps.plugins.aps.logger.LoggerCallback
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.*
|
import info.nightscout.androidaps.plugins.constraints.objectives.objectives.*
|
||||||
|
@ -55,7 +54,6 @@ interface AppComponent : AndroidInjector<MainApp> {
|
||||||
fun injectPumpEnactResult(pumpEnactResult: PumpEnactResult)
|
fun injectPumpEnactResult(pumpEnactResult: PumpEnactResult)
|
||||||
fun injectAPSResult(apsResult: APSResult)
|
fun injectAPSResult(apsResult: APSResult)
|
||||||
fun injectDetermineBasalResultSMB(determineBasalResultSMB: DetermineBasalResultSMB)
|
fun injectDetermineBasalResultSMB(determineBasalResultSMB: DetermineBasalResultSMB)
|
||||||
fun injectDetermineBasalResultMA(determineBasalResultMA: DetermineBasalResultMA)
|
|
||||||
fun injectDetermineBasalResultAMA(determineBasalResultAMA: DetermineBasalResultAMA)
|
fun injectDetermineBasalResultAMA(determineBasalResultAMA: DetermineBasalResultAMA)
|
||||||
fun injectDetermineBasalAdapterSMBJS(determineBasalAdapterSMBJS: DetermineBasalAdapterSMBJS)
|
fun injectDetermineBasalAdapterSMBJS(determineBasalAdapterSMBJS: DetermineBasalAdapterSMBJS)
|
||||||
|
|
||||||
|
|
|
@ -22,8 +22,7 @@ import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.AAPSLoggerProduction
|
import info.nightscout.androidaps.logging.AAPSLoggerProduction
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.DetermineBasalResultAMA
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.DetermineBasalResultMA
|
import info.nightscout.androidaps.plugins.aps.logger.LoggerCallback
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.LoggerCallback
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalAdapterSMBJS
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.DetermineBasalResultSMB
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
import info.nightscout.androidaps.plugins.configBuilder.PluginStore
|
||||||
|
@ -121,7 +120,6 @@ open class AppModule {
|
||||||
|
|
||||||
@ContributesAndroidInjector fun apsResultInjector(): APSResult
|
@ContributesAndroidInjector fun apsResultInjector(): APSResult
|
||||||
@ContributesAndroidInjector fun determineBasalResultSMBInjector(): DetermineBasalResultSMB
|
@ContributesAndroidInjector fun determineBasalResultSMBInjector(): DetermineBasalResultSMB
|
||||||
@ContributesAndroidInjector fun determineBasalResultMAInjector(): DetermineBasalResultMA
|
|
||||||
@ContributesAndroidInjector fun determineBasalResultAMAInjector(): DetermineBasalResultAMA
|
@ContributesAndroidInjector fun determineBasalResultAMAInjector(): DetermineBasalResultAMA
|
||||||
|
|
||||||
@ContributesAndroidInjector
|
@ContributesAndroidInjector
|
||||||
|
|
|
@ -6,7 +6,6 @@ import info.nightscout.androidaps.activities.MyPreferenceFragment
|
||||||
import info.nightscout.androidaps.dialogs.*
|
import info.nightscout.androidaps.dialogs.*
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopFragment
|
import info.nightscout.androidaps.plugins.aps.loop.LoopFragment
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAFragment
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAFragment
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAFragment
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBFragment
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderFragment
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment
|
import info.nightscout.androidaps.plugins.constraints.objectives.ObjectivesFragment
|
||||||
|
@ -63,7 +62,6 @@ abstract class FragmentsModule {
|
||||||
@ContributesAndroidInjector abstract fun contributesLocalProfileFragment(): LocalProfileFragment
|
@ContributesAndroidInjector abstract fun contributesLocalProfileFragment(): LocalProfileFragment
|
||||||
@ContributesAndroidInjector abstract fun contributesObjectivesFragment(): ObjectivesFragment
|
@ContributesAndroidInjector abstract fun contributesObjectivesFragment(): ObjectivesFragment
|
||||||
@ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
|
@ContributesAndroidInjector abstract fun contributesOpenAPSAMAFragment(): OpenAPSAMAFragment
|
||||||
@ContributesAndroidInjector abstract fun contributesOpenAPSMAFragment(): OpenAPSMAFragment
|
|
||||||
@ContributesAndroidInjector abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
|
@ContributesAndroidInjector abstract fun contributesOpenAPSSMBFragment(): OpenAPSSMBFragment
|
||||||
@ContributesAndroidInjector abstract fun contributesOverviewFragment(): OverviewFragment
|
@ContributesAndroidInjector abstract fun contributesOverviewFragment(): OverviewFragment
|
||||||
@ContributesAndroidInjector abstract fun contributesLocalInsightFragment(): LocalInsightFragment
|
@ContributesAndroidInjector abstract fun contributesLocalInsightFragment(): LocalInsightFragment
|
||||||
|
|
|
@ -11,7 +11,6 @@ import info.nightscout.androidaps.Config
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase
|
import info.nightscout.androidaps.interfaces.PluginBase
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin
|
import info.nightscout.androidaps.plugins.constraints.dstHelper.DstHelperPlugin
|
||||||
|
@ -188,36 +187,30 @@ abstract class PluginsModule {
|
||||||
@APS
|
@APS
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@IntKey(210)
|
@IntKey(210)
|
||||||
abstract fun bindOpenAPSMAPlugin(plugin: OpenAPSMAPlugin): PluginBase
|
|
||||||
|
|
||||||
@Binds
|
|
||||||
@APS
|
|
||||||
@IntoMap
|
|
||||||
@IntKey(220)
|
|
||||||
abstract fun bindOpenAPSAMAPlugin(plugin: OpenAPSAMAPlugin): PluginBase
|
abstract fun bindOpenAPSAMAPlugin(plugin: OpenAPSAMAPlugin): PluginBase
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@APS
|
@APS
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@IntKey(230)
|
@IntKey(220)
|
||||||
abstract fun bindOpenAPSSMBPlugin(plugin: OpenAPSSMBPlugin): PluginBase
|
abstract fun bindOpenAPSSMBPlugin(plugin: OpenAPSSMBPlugin): PluginBase
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@AllConfigs
|
@AllConfigs
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@IntKey(240)
|
@IntKey(230)
|
||||||
abstract fun bindNSProfilePlugin(plugin: NSProfilePlugin): PluginBase
|
abstract fun bindNSProfilePlugin(plugin: NSProfilePlugin): PluginBase
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@NotNSClient
|
@NotNSClient
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@IntKey(250)
|
@IntKey(240)
|
||||||
abstract fun bindLocalProfilePlugin(plugin: LocalProfilePlugin): PluginBase
|
abstract fun bindLocalProfilePlugin(plugin: LocalProfilePlugin): PluginBase
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
@AllConfigs
|
@AllConfigs
|
||||||
@IntoMap
|
@IntoMap
|
||||||
@IntKey(255)
|
@IntKey(250)
|
||||||
abstract fun bindAutomationPlugin(plugin: AutomationPlugin): PluginBase
|
abstract fun bindAutomationPlugin(plugin: AutomationPlugin): PluginBase
|
||||||
|
|
||||||
@Binds
|
@Binds
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA.events
|
package info.nightscout.androidaps.plugins.aps.events
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventUpdateGui
|
import info.nightscout.androidaps.events.EventUpdateGui
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA.events
|
package info.nightscout.androidaps.plugins.aps.events
|
||||||
|
|
||||||
import info.nightscout.androidaps.events.EventUpdateGui
|
import info.nightscout.androidaps.events.EventUpdateGui
|
||||||
|
|
|
@ -29,7 +29,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
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.logger.LoggerCallback;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.SMBDefaults;
|
||||||
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;
|
||||||
|
|
|
@ -9,8 +9,8 @@ import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
|
|
@ -23,8 +23,8 @@ import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
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.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
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;
|
||||||
|
|
|
@ -1,232 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.mozilla.javascript.Context;
|
|
||||||
import org.mozilla.javascript.Function;
|
|
||||||
import org.mozilla.javascript.NativeJSON;
|
|
||||||
import org.mozilla.javascript.NativeObject;
|
|
||||||
import org.mozilla.javascript.RhinoException;
|
|
||||||
import org.mozilla.javascript.Scriptable;
|
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
|
||||||
import info.nightscout.androidaps.Constants;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
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.ProfileFunction;
|
|
||||||
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 HasAndroidInjector injector;
|
|
||||||
@Inject AAPSLogger aapsLogger;
|
|
||||||
@Inject ProfileFunction profileFunction;
|
|
||||||
@Inject TreatmentsPlugin treatmentsPlugin;
|
|
||||||
|
|
||||||
private ScriptReader mScriptReader;
|
|
||||||
private JSONObject mProfile;
|
|
||||||
private JSONObject mGlucoseStatus;
|
|
||||||
private JSONObject mIobData;
|
|
||||||
private JSONObject mMealData;
|
|
||||||
private JSONObject mCurrentTemp;
|
|
||||||
|
|
||||||
private String storedCurrentTemp = null;
|
|
||||||
private String storedIobData = null;
|
|
||||||
private String storedGlucoseStatus = null;
|
|
||||||
private String storedProfile = null;
|
|
||||||
private String storedMeal_data = null;
|
|
||||||
|
|
||||||
DetermineBasalAdapterMAJS(ScriptReader scriptReader, HasAndroidInjector injector) {
|
|
||||||
injector.androidInjector().inject(this);
|
|
||||||
mScriptReader = scriptReader;
|
|
||||||
this.injector = injector;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public DetermineBasalResultMA invoke() {
|
|
||||||
DetermineBasalResultMA determineBasalResultMA = null;
|
|
||||||
|
|
||||||
Context rhino = Context.enter();
|
|
||||||
Scriptable scope = rhino.initStandardObjects();
|
|
||||||
// Turn off optimization to make Rhino Android compatible
|
|
||||||
rhino.setOptimizationLevel(-1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
//register logger callback for console.log and console.error
|
|
||||||
ScriptableObject.defineClass(scope, LoggerCallback.class);
|
|
||||||
Scriptable myLogger = rhino.newObject(scope, "LoggerCallback", null);
|
|
||||||
scope.put("console", scope, myLogger);
|
|
||||||
|
|
||||||
//set module parent
|
|
||||||
rhino.evaluateString(scope, "var module = {\"parent\":Boolean(1)};", "JavaScript", 0, null);
|
|
||||||
|
|
||||||
//generate functions "determine_basal" and "setTempBasal"
|
|
||||||
rhino.evaluateString(scope, readFile("OpenAPSMA/determine-basal.js"), "JavaScript", 0, null);
|
|
||||||
|
|
||||||
String setTempBasalCode = "var setTempBasal = function (rate, duration, profile, rT, offline) {" +
|
|
||||||
"rT.duration = duration;\n" +
|
|
||||||
" rT.rate = rate;" +
|
|
||||||
"return rT;" +
|
|
||||||
"};";
|
|
||||||
rhino.evaluateString(scope, setTempBasalCode, "setTempBasal.js", 0, null);
|
|
||||||
Object determineBasalObj = scope.get("determine_basal", scope);
|
|
||||||
Object setTempBasalObj = scope.get("setTempBasal", scope);
|
|
||||||
|
|
||||||
//call determine-basal
|
|
||||||
if (determineBasalObj instanceof Function && setTempBasalObj instanceof Function) {
|
|
||||||
Function determineBasalJS = (Function) determineBasalObj;
|
|
||||||
Function setTempBasalJS = (Function) setTempBasalObj;
|
|
||||||
|
|
||||||
//prepare parameters
|
|
||||||
Object[] params = new Object[]{
|
|
||||||
makeParam(mGlucoseStatus, rhino, scope),
|
|
||||||
makeParam(mCurrentTemp, rhino, scope),
|
|
||||||
makeParam(mIobData, rhino, scope),
|
|
||||||
makeParam(mProfile, rhino, scope),
|
|
||||||
"undefined",
|
|
||||||
makeParam(mMealData, rhino, scope),
|
|
||||||
setTempBasalJS};
|
|
||||||
|
|
||||||
NativeObject jsResult = (NativeObject) determineBasalJS.call(rhino, scope, scope, params);
|
|
||||||
|
|
||||||
// Parse the jsResult object to a JSON-String
|
|
||||||
String result = NativeJSON.stringify(rhino, scope, jsResult, null, null).toString();
|
|
||||||
aapsLogger.debug(LTag.APS, "Result: " + result);
|
|
||||||
try {
|
|
||||||
determineBasalResultMA = new DetermineBasalResultMA(injector, jsResult, new JSONObject(result));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
aapsLogger.debug(LTag.APS, "Problem loading JS Functions");
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
aapsLogger.error(LTag.APS, "IOException");
|
|
||||||
} catch (RhinoException e) {
|
|
||||||
aapsLogger.error(LTag.APS, "RhinoException: (" + e.lineNumber() + "," + e.columnNumber() + ") " + e.toString());
|
|
||||||
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
|
|
||||||
aapsLogger.error(LTag.APS, e.toString());
|
|
||||||
} finally {
|
|
||||||
Context.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
storedGlucoseStatus = mGlucoseStatus.toString();
|
|
||||||
storedIobData = mIobData.toString();
|
|
||||||
storedCurrentTemp = mCurrentTemp.toString();
|
|
||||||
storedProfile = mProfile.toString();
|
|
||||||
storedMeal_data = mMealData.toString();
|
|
||||||
|
|
||||||
return determineBasalResultMA;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getGlucoseStatusParam() {
|
|
||||||
return storedGlucoseStatus;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getCurrentTempParam() {
|
|
||||||
return storedCurrentTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getIobDataParam() {
|
|
||||||
return storedIobData;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getProfileParam() {
|
|
||||||
return storedProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getMealDataParam() {
|
|
||||||
return storedMeal_data;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setData(Profile profile,
|
|
||||||
double maxIob,
|
|
||||||
double maxBasal,
|
|
||||||
double minBg,
|
|
||||||
double maxBg,
|
|
||||||
double targetBg,
|
|
||||||
double basalRate,
|
|
||||||
IobTotal iobData,
|
|
||||||
GlucoseStatus glucoseStatus,
|
|
||||||
MealData mealData) throws JSONException {
|
|
||||||
|
|
||||||
mProfile = new JSONObject();
|
|
||||||
mProfile.put("max_iob", maxIob);
|
|
||||||
mProfile.put("dia", Math.min(profile.getDia(), 3d));
|
|
||||||
mProfile.put("type", "current");
|
|
||||||
mProfile.put("max_daily_basal", profile.getMaxDailyBasal());
|
|
||||||
mProfile.put("max_basal", maxBasal);
|
|
||||||
mProfile.put("min_bg", minBg);
|
|
||||||
mProfile.put("max_bg", maxBg);
|
|
||||||
mProfile.put("target_bg", targetBg);
|
|
||||||
mProfile.put("carb_ratio", profile.getIc());
|
|
||||||
mProfile.put("sens", profile.getIsfMgdl());
|
|
||||||
|
|
||||||
mProfile.put("current_basal", basalRate);
|
|
||||||
|
|
||||||
if (profileFunction.getUnits().equals(Constants.MMOL)) {
|
|
||||||
mProfile.put("out_units", "mmol/L");
|
|
||||||
}
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
TemporaryBasal tb = treatmentsPlugin.getTempBasalFromHistory(now);
|
|
||||||
|
|
||||||
mCurrentTemp = new JSONObject();
|
|
||||||
mCurrentTemp.put("duration", tb != null ? tb.getPlannedRemainingMinutes() : 0);
|
|
||||||
mCurrentTemp.put("rate", tb != null ? tb.tempBasalConvertedToAbsolute(now, profile) : 0d);
|
|
||||||
|
|
||||||
mIobData = new JSONObject();
|
|
||||||
mIobData.put("iob", iobData.iob); //netIob
|
|
||||||
mIobData.put("activity", iobData.activity); //netActivity
|
|
||||||
mIobData.put("bolussnooze", iobData.bolussnooze); //bolusIob
|
|
||||||
mIobData.put("basaliob", iobData.basaliob);
|
|
||||||
mIobData.put("netbasalinsulin", iobData.netbasalinsulin);
|
|
||||||
mIobData.put("hightempinsulin", iobData.hightempinsulin);
|
|
||||||
|
|
||||||
mGlucoseStatus = new JSONObject();
|
|
||||||
mGlucoseStatus.put("glucose", glucoseStatus.glucose);
|
|
||||||
if (SP.getBoolean(R.string.key_always_use_shortavg, false)) {
|
|
||||||
mGlucoseStatus.put("delta", glucoseStatus.short_avgdelta);
|
|
||||||
} else {
|
|
||||||
mGlucoseStatus.put("delta", glucoseStatus.delta);
|
|
||||||
}
|
|
||||||
mGlucoseStatus.put("avgdelta", glucoseStatus.avgdelta);
|
|
||||||
|
|
||||||
mMealData = new JSONObject();
|
|
||||||
mMealData.put("carbs", mealData.carbs);
|
|
||||||
mMealData.put("boluses", mealData.boluses);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readFile(String filename) throws IOException {
|
|
||||||
byte[] bytes = mScriptReader.readFile(filename);
|
|
||||||
String string = new String(bytes, StandardCharsets.UTF_8);
|
|
||||||
if (string.startsWith("#!/usr/bin/env node")) {
|
|
||||||
string = string.substring(20);
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object makeParam(JSONObject jsonObject, Context rhino, Scriptable scope) {
|
|
||||||
Object param = NativeJSON.parse(rhino, scope, jsonObject.toString(), (context, scriptable, scriptable1, objects) -> objects[1]);
|
|
||||||
return param;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.mozilla.javascript.NativeObject;
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
|
||||||
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 AAPSLogger aapsLogger;
|
|
||||||
|
|
||||||
private double eventualBG;
|
|
||||||
private double snoozeBG;
|
|
||||||
private String mealAssist;
|
|
||||||
|
|
||||||
DetermineBasalResultMA(HasAndroidInjector injector, NativeObject result, JSONObject j) {
|
|
||||||
this(injector);
|
|
||||||
json = j;
|
|
||||||
if (result.containsKey("error")) {
|
|
||||||
reason = (String) result.get("error");
|
|
||||||
tempBasalRequested = false;
|
|
||||||
rate = -1;
|
|
||||||
duration = -1;
|
|
||||||
mealAssist = "";
|
|
||||||
} else {
|
|
||||||
reason = result.get("reason").toString();
|
|
||||||
eventualBG = (Double) result.get("eventualBG");
|
|
||||||
snoozeBG = (Double) result.get("snoozeBG");
|
|
||||||
if (result.containsKey("rate")) {
|
|
||||||
rate = (Double) result.get("rate");
|
|
||||||
if (rate < 0d) rate = 0d;
|
|
||||||
tempBasalRequested = true;
|
|
||||||
} else {
|
|
||||||
rate = -1;
|
|
||||||
tempBasalRequested = false;
|
|
||||||
}
|
|
||||||
if (result.containsKey("duration")) {
|
|
||||||
duration = ((Double) result.get("duration")).intValue();
|
|
||||||
//changeRequested as above
|
|
||||||
} else {
|
|
||||||
duration = -1;
|
|
||||||
tempBasalRequested = false;
|
|
||||||
}
|
|
||||||
if (result.containsKey("mealAssist")) {
|
|
||||||
mealAssist = result.get("mealAssist").toString();
|
|
||||||
} else mealAssist = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private DetermineBasalResultMA(HasAndroidInjector injector) {
|
|
||||||
super(injector);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public DetermineBasalResultMA newAndClone(HasAndroidInjector injector) {
|
|
||||||
DetermineBasalResultMA newResult = new DetermineBasalResultMA(injector);
|
|
||||||
doClone(newResult);
|
|
||||||
|
|
||||||
newResult.eventualBG = eventualBG;
|
|
||||||
newResult.snoozeBG = snoozeBG;
|
|
||||||
newResult.mealAssist = mealAssist;
|
|
||||||
return newResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public JSONObject json() {
|
|
||||||
try {
|
|
||||||
JSONObject ret = new JSONObject(this.json.toString());
|
|
||||||
return ret;
|
|
||||||
} catch (JSONException e) {
|
|
||||||
aapsLogger.error(LTag.APS, "Unhandled exception", e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
|
||||||
|
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
public class LoggerCallback extends ScriptableObject {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
AAPSLogger aapsLogger;
|
|
||||||
|
|
||||||
private static StringBuffer errorBuffer = new StringBuffer();
|
|
||||||
private static StringBuffer logBuffer = new StringBuffer();
|
|
||||||
|
|
||||||
|
|
||||||
public LoggerCallback() {
|
|
||||||
//empty constructor needed for Rhino
|
|
||||||
errorBuffer = new StringBuffer();
|
|
||||||
logBuffer = new StringBuffer();
|
|
||||||
MainApp.instance().androidInjector().inject(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getClassName() {
|
|
||||||
return "LoggerCallback";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void jsConstructor() {
|
|
||||||
//empty constructor on JS site; could work as setter
|
|
||||||
}
|
|
||||||
|
|
||||||
public void jsFunction_log(Object obj1) {
|
|
||||||
aapsLogger.debug(LTag.APS, obj1.toString().trim());
|
|
||||||
logBuffer.append(obj1.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void jsFunction_error(Object obj1) {
|
|
||||||
aapsLogger.error(LTag.APS, obj1.toString().trim());
|
|
||||||
errorBuffer.append(obj1.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static String getScriptDebug() {
|
|
||||||
String ret = "";
|
|
||||||
if (errorBuffer.length() > 0) {
|
|
||||||
ret += "e:\n" + errorBuffer.toString();
|
|
||||||
}
|
|
||||||
if (ret.length() > 0 && logBuffer.length() > 0) ret += '\n';
|
|
||||||
if (logBuffer.length() > 0) {
|
|
||||||
ret += "d:\n" + logBuffer.toString();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import dagger.android.support.DaggerFragment
|
|
||||||
import info.nightscout.androidaps.R
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
|
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
|
||||||
import info.nightscout.androidaps.utils.JSONFormatter
|
|
||||||
import info.nightscout.androidaps.utils.extensions.plusAssign
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.disposables.CompositeDisposable
|
|
||||||
import kotlinx.android.synthetic.main.openapsama_fragment.*
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
class OpenAPSMAFragment : DaggerFragment() {
|
|
||||||
private var disposable: CompositeDisposable = CompositeDisposable()
|
|
||||||
|
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
|
||||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
|
||||||
@Inject lateinit var openAPSMAPlugin: OpenAPSMAPlugin
|
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
|
|
||||||
savedInstanceState: Bundle?): View? {
|
|
||||||
return inflater.inflate(R.layout.openapsma_fragment, container, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
|
|
||||||
openapsma_run.setOnClickListener {
|
|
||||||
openAPSMAPlugin.invoke("OpenAPSMA button", false)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override fun onResume() {
|
|
||||||
super.onResume()
|
|
||||||
|
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(EventOpenAPSUpdateGui::class.java)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe({
|
|
||||||
updateGUI()
|
|
||||||
}, { fabricPrivacy.logException(it) })
|
|
||||||
disposable += rxBus
|
|
||||||
.toObservable(EventOpenAPSUpdateResultGui::class.java)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
|
||||||
.subscribe({
|
|
||||||
updateResultGUI(it.text)
|
|
||||||
}, { fabricPrivacy.logException(it) })
|
|
||||||
updateGUI()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
disposable.clear()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
private fun updateGUI() {
|
|
||||||
if (openapsma_result == null) return
|
|
||||||
openAPSMAPlugin.lastAPSResult?.let { lastAPSResult ->
|
|
||||||
openapsma_result.text = JSONFormatter.format(lastAPSResult.json)
|
|
||||||
openapsma_request.text = lastAPSResult.toSpanned()
|
|
||||||
}
|
|
||||||
openAPSMAPlugin.lastDetermineBasalAdapterMAJS?.let { determineBasalAdapterMAJS ->
|
|
||||||
openapsma_glucosestatus.text = JSONFormatter.format(determineBasalAdapterMAJS.glucoseStatusParam)
|
|
||||||
openapsma_currenttemp.text = JSONFormatter.format(determineBasalAdapterMAJS.currentTempParam)
|
|
||||||
openapsma_iobdata.text = JSONFormatter.format(determineBasalAdapterMAJS.iobDataParam)
|
|
||||||
openapsma_profile.text = JSONFormatter.format(determineBasalAdapterMAJS.profileParam)
|
|
||||||
openapsma_mealdata.text = JSONFormatter.format(determineBasalAdapterMAJS.mealDataParam)
|
|
||||||
}
|
|
||||||
if (openAPSMAPlugin.lastAPSRun != 0L) {
|
|
||||||
openapsma_lastrun.text = DateUtil.dateAndTimeString(openAPSMAPlugin.lastAPSRun)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Synchronized
|
|
||||||
private fun updateResultGUI(text: String) {
|
|
||||||
if (openapsma_result == null) return
|
|
||||||
openapsma_result.text = text
|
|
||||||
openapsma_glucosestatus.text = ""
|
|
||||||
openapsma_currenttemp.text = ""
|
|
||||||
openapsma_iobdata.text = ""
|
|
||||||
openapsma_profile.text = ""
|
|
||||||
openapsma_mealdata.text = ""
|
|
||||||
openapsma_request.text = ""
|
|
||||||
openapsma_lastrun.text = ""
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,232 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.aps.openAPSMA;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Singleton;
|
|
||||||
|
|
||||||
import dagger.android.HasAndroidInjector;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
|
||||||
import info.nightscout.androidaps.data.MealData;
|
|
||||||
import info.nightscout.androidaps.data.Profile;
|
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.ActivePluginProvider;
|
|
||||||
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.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.RxBusWrapper;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
|
||||||
import info.nightscout.androidaps.utils.HardLimits;
|
|
||||||
import info.nightscout.androidaps.utils.Profiler;
|
|
||||||
import info.nightscout.androidaps.utils.Round;
|
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
|
||||||
|
|
||||||
@Singleton
|
|
||||||
public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|
||||||
private final RxBusWrapper rxBus;
|
|
||||||
private final ConstraintChecker constraintChecker;
|
|
||||||
private final ResourceHelper resourceHelper;
|
|
||||||
private final ProfileFunction profileFunction;
|
|
||||||
private final Context context;
|
|
||||||
private final ActivePluginProvider activePlugin;
|
|
||||||
private final TreatmentsPlugin treatmentsPlugin;
|
|
||||||
private final IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
|
||||||
private final HardLimits hardLimits;
|
|
||||||
|
|
||||||
// last values
|
|
||||||
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
|
|
||||||
long lastAPSRun = 0;
|
|
||||||
DetermineBasalResultMA lastAPSResult = null;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public OpenAPSMAPlugin(
|
|
||||||
HasAndroidInjector injector,
|
|
||||||
AAPSLogger aapsLogger,
|
|
||||||
RxBusWrapper rxBus,
|
|
||||||
ConstraintChecker constraintChecker,
|
|
||||||
ResourceHelper resourceHelper,
|
|
||||||
ProfileFunction profileFunction,
|
|
||||||
Context context,
|
|
||||||
ActivePluginProvider activePlugin,
|
|
||||||
TreatmentsPlugin treatmentsPlugin,
|
|
||||||
IobCobCalculatorPlugin iobCobCalculatorPlugin,
|
|
||||||
HardLimits hardLimits
|
|
||||||
) {
|
|
||||||
super(new PluginDescription()
|
|
||||||
.mainType(PluginType.APS)
|
|
||||||
.fragmentClass(OpenAPSMAFragment.class.getName())
|
|
||||||
.pluginName(R.string.openapsma)
|
|
||||||
.shortName(R.string.oaps_shortname)
|
|
||||||
.preferencesId(R.xml.pref_openapsma)
|
|
||||||
.description(R.string.description_ma),
|
|
||||||
aapsLogger, resourceHelper, injector
|
|
||||||
);
|
|
||||||
|
|
||||||
this.constraintChecker = constraintChecker;
|
|
||||||
this.resourceHelper = resourceHelper;
|
|
||||||
this.profileFunction = profileFunction;
|
|
||||||
this.context = context;
|
|
||||||
this.rxBus = rxBus;
|
|
||||||
this.activePlugin = activePlugin;
|
|
||||||
this.treatmentsPlugin = treatmentsPlugin;
|
|
||||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
|
||||||
this.hardLimits = hardLimits;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean specialEnableCondition() {
|
|
||||||
try {
|
|
||||||
PumpInterface pump = activePlugin.getActivePump();
|
|
||||||
return pump.getPumpDescription().isTempBasalCapable;
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
// may fail during initialization
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean specialShowInListCondition() {
|
|
||||||
PumpInterface pump = activePlugin.getActivePump();
|
|
||||||
return pump.getPumpDescription().isTempBasalCapable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public APSResult getLastAPSResult() {
|
|
||||||
return lastAPSResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getLastAPSRun() {
|
|
||||||
return lastAPSRun;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
|
||||||
getAapsLogger().debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
|
||||||
lastAPSResult = null;
|
|
||||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
|
|
||||||
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(context), getInjector());
|
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = new GlucoseStatus(getInjector()).getGlucoseStatusData();
|
|
||||||
Profile profile = profileFunction.getProfile();
|
|
||||||
PumpInterface pump = activePlugin.getActivePump();
|
|
||||||
|
|
||||||
if (profile == null) {
|
|
||||||
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.noprofileselected)));
|
|
||||||
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
|
||||||
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_disabled)));
|
|
||||||
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.openapsma_disabled));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (glucoseStatus == null) {
|
|
||||||
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_noglucosedata)));
|
|
||||||
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.openapsma_noglucosedata));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
double maxBasal = constraintChecker.getMaxBasalAllowed(profile).value();
|
|
||||||
|
|
||||||
double minBg = profile.getTargetLowMgdl();
|
|
||||||
double maxBg = profile.getTargetHighMgdl();
|
|
||||||
double targetBg = profile.getTargetMgdl();
|
|
||||||
|
|
||||||
minBg = Round.roundTo(minBg, 0.1d);
|
|
||||||
maxBg = Round.roundTo(maxBg, 0.1d);
|
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
|
||||||
treatmentsPlugin.updateTotalIOBTreatments();
|
|
||||||
treatmentsPlugin.updateTotalIOBTempBasals();
|
|
||||||
IobTotal bolusIob = treatmentsPlugin.getLastCalculationTreatments();
|
|
||||||
IobTotal basalIob = treatmentsPlugin.getLastCalculationTempBasals();
|
|
||||||
|
|
||||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
|
||||||
|
|
||||||
MealData mealData = iobCobCalculatorPlugin.getMealData();
|
|
||||||
|
|
||||||
double maxIob = constraintChecker.getMaxIOBAllowed().value();
|
|
||||||
Profiler.log(getAapsLogger(), LTag.APS, "MA data gathering", start);
|
|
||||||
|
|
||||||
minBg = hardLimits.verifyHardLimits(minBg, "minBg", hardLimits.getVERY_HARD_LIMIT_MIN_BG()[0], hardLimits.getVERY_HARD_LIMIT_MIN_BG()[1]);
|
|
||||||
maxBg = hardLimits.verifyHardLimits(maxBg, "maxBg", hardLimits.getVERY_HARD_LIMIT_MAX_BG()[0], hardLimits.getVERY_HARD_LIMIT_MAX_BG()[1]);
|
|
||||||
targetBg = hardLimits.verifyHardLimits(targetBg, "targetBg", hardLimits.getVERY_HARD_LIMIT_TARGET_BG()[0], hardLimits.getVERY_HARD_LIMIT_TARGET_BG()[1]);
|
|
||||||
|
|
||||||
TempTarget tempTarget = treatmentsPlugin.getTempTargetFromHistory(System.currentTimeMillis());
|
|
||||||
if (tempTarget != null) {
|
|
||||||
minBg = hardLimits.verifyHardLimits(tempTarget.low, "minBg", hardLimits.getVERY_HARD_LIMIT_TEMP_MIN_BG()[0], hardLimits.getVERY_HARD_LIMIT_TEMP_MIN_BG()[1]);
|
|
||||||
maxBg = hardLimits.verifyHardLimits(tempTarget.high, "maxBg", hardLimits.getVERY_HARD_LIMIT_TEMP_MAX_BG()[0], hardLimits.getVERY_HARD_LIMIT_TEMP_MAX_BG()[1]);
|
|
||||||
targetBg = hardLimits.verifyHardLimits(tempTarget.target(), "targetBg", hardLimits.getVERY_HARD_LIMIT_TEMP_TARGET_BG()[0], hardLimits.getVERY_HARD_LIMIT_TEMP_TARGET_BG()[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!hardLimits.checkOnlyHardLimits(profile.getDia(), "dia", hardLimits.getMINDIA(), hardLimits.getMAXDIA()))
|
|
||||||
return;
|
|
||||||
if (!hardLimits.checkOnlyHardLimits(profile.getIcTimeFromMidnight(Profile.secondsFromMidnight()), "carbratio", hardLimits.getMINIC(), hardLimits.getMAXIC()))
|
|
||||||
return;
|
|
||||||
if (!hardLimits.checkOnlyHardLimits(profile.getIsfMgdl(), "sens", hardLimits.getMINISF(), hardLimits.getMAXISF()))
|
|
||||||
return;
|
|
||||||
if (!hardLimits.checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.02, hardLimits.maxBasal()))
|
|
||||||
return;
|
|
||||||
if (!hardLimits.checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, hardLimits.maxBasal()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
start = System.currentTimeMillis();
|
|
||||||
try {
|
|
||||||
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, activePlugin.getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
FabricPrivacy.getInstance().logException(e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Profiler.log(getAapsLogger(), LTag.APS, "MA calculation", start);
|
|
||||||
|
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
|
|
||||||
DetermineBasalResultMA determineBasalResultMA = determineBasalAdapterMAJS.invoke();
|
|
||||||
if (determineBasalResultMA == null) {
|
|
||||||
getAapsLogger().error(LTag.APS, "MA calculation returned null");
|
|
||||||
lastDetermineBasalAdapterMAJS = null;
|
|
||||||
lastAPSResult = null;
|
|
||||||
lastAPSRun = 0;
|
|
||||||
} else {
|
|
||||||
// Fix bug determine basal
|
|
||||||
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !treatmentsPlugin.isTempBasalInProgress())
|
|
||||||
determineBasalResultMA.tempBasalRequested = false;
|
|
||||||
|
|
||||||
determineBasalResultMA.iob = iobTotal;
|
|
||||||
|
|
||||||
try {
|
|
||||||
determineBasalResultMA.json.put("timestamp", DateUtil.toISOString(now));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
getAapsLogger().error(LTag.APS, "Unhandled exception", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
lastDetermineBasalAdapterMAJS = determineBasalAdapterMAJS;
|
|
||||||
lastAPSResult = determineBasalResultMA;
|
|
||||||
lastAPSRun = now;
|
|
||||||
}
|
|
||||||
rxBus.send(new EventOpenAPSUpdateGui());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -29,7 +29,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
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.logger.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.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
|
|
|
@ -10,8 +10,8 @@ import dagger.android.support.DaggerFragment
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
|
|
|
@ -26,8 +26,8 @@ import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.logging.LTag;
|
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.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
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;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||||
|
@ -42,7 +41,6 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
private RxBusWrapper rxBus;
|
private RxBusWrapper rxBus;
|
||||||
private ConstraintChecker constraintChecker;
|
private ConstraintChecker constraintChecker;
|
||||||
private OpenAPSAMAPlugin openAPSAMAPlugin;
|
private OpenAPSAMAPlugin openAPSAMAPlugin;
|
||||||
private OpenAPSMAPlugin openAPSMAPlugin;
|
|
||||||
private OpenAPSSMBPlugin openAPSSMBPlugin;
|
private OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||||
private SensitivityOref1Plugin sensitivityOref1Plugin;
|
private SensitivityOref1Plugin sensitivityOref1Plugin;
|
||||||
private ActivePluginProvider activePlugin;
|
private ActivePluginProvider activePlugin;
|
||||||
|
@ -59,7 +57,6 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
RxBusWrapper rxBus,
|
RxBusWrapper rxBus,
|
||||||
ConstraintChecker constraintChecker,
|
ConstraintChecker constraintChecker,
|
||||||
OpenAPSAMAPlugin openAPSAMAPlugin,
|
OpenAPSAMAPlugin openAPSAMAPlugin,
|
||||||
OpenAPSMAPlugin openAPSMAPlugin,
|
|
||||||
OpenAPSSMBPlugin openAPSSMBPlugin,
|
OpenAPSSMBPlugin openAPSSMBPlugin,
|
||||||
SensitivityOref1Plugin sensitivityOref1Plugin,
|
SensitivityOref1Plugin sensitivityOref1Plugin,
|
||||||
ActivePluginProvider activePlugin,
|
ActivePluginProvider activePlugin,
|
||||||
|
@ -80,7 +77,6 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
this.constraintChecker = constraintChecker;
|
this.constraintChecker = constraintChecker;
|
||||||
this.openAPSAMAPlugin = openAPSAMAPlugin;
|
this.openAPSAMAPlugin = openAPSAMAPlugin;
|
||||||
this.openAPSMAPlugin = openAPSMAPlugin;
|
|
||||||
this.openAPSSMBPlugin = openAPSSMBPlugin;
|
this.openAPSSMBPlugin = openAPSSMBPlugin;
|
||||||
this.sensitivityOref1Plugin = sensitivityOref1Plugin;
|
this.sensitivityOref1Plugin = sensitivityOref1Plugin;
|
||||||
this.activePlugin = activePlugin;
|
this.activePlugin = activePlugin;
|
||||||
|
@ -276,8 +272,6 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
maxIobPref = sp.getDouble(R.string.key_openapsma_max_iob, 1.5d);
|
maxIobPref = sp.getDouble(R.string.key_openapsma_max_iob, 1.5d);
|
||||||
maxIob.setIfSmaller(getAapsLogger(), maxIobPref, String.format(getResourceHelper().gs(R.string.limitingiob), maxIobPref, getResourceHelper().gs(R.string.maxvalueinpreferences)), this);
|
maxIob.setIfSmaller(getAapsLogger(), maxIobPref, String.format(getResourceHelper().gs(R.string.limitingiob), maxIobPref, getResourceHelper().gs(R.string.maxvalueinpreferences)), this);
|
||||||
|
|
||||||
if (openAPSMAPlugin.isEnabled(PluginType.APS))
|
|
||||||
maxIob.setIfSmaller(getAapsLogger(), hardLimits.maxIobAMA(), String.format(getResourceHelper().gs(R.string.limitingiob), hardLimits.maxIobAMA(), getResourceHelper().gs(R.string.hardlimit)), this);
|
|
||||||
if (openAPSAMAPlugin.isEnabled(PluginType.APS))
|
if (openAPSAMAPlugin.isEnabled(PluginType.APS))
|
||||||
maxIob.setIfSmaller(getAapsLogger(), hardLimits.maxIobAMA(), String.format(getResourceHelper().gs(R.string.limitingiob), hardLimits.maxIobAMA(), getResourceHelper().gs(R.string.hardlimit)), this);
|
maxIob.setIfSmaller(getAapsLogger(), hardLimits.maxIobAMA(), String.format(getResourceHelper().gs(R.string.limitingiob), hardLimits.maxIobAMA(), getResourceHelper().gs(R.string.hardlimit)), this);
|
||||||
if (openAPSSMBPlugin.isEnabled(PluginType.APS))
|
if (openAPSSMBPlugin.isEnabled(PluginType.APS))
|
||||||
|
|
|
@ -22,7 +22,7 @@ import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.logging.LTag
|
import info.nightscout.androidaps.logging.LTag
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus
|
import info.nightscout.androidaps.plugins.general.nsclient.data.NSDeviceStatus
|
||||||
|
|
|
@ -11,7 +11,7 @@ import info.nightscout.androidaps.interfaces.PluginDescription
|
||||||
import info.nightscout.androidaps.interfaces.PluginType
|
import info.nightscout.androidaps.interfaces.PluginType
|
||||||
import info.nightscout.androidaps.logging.AAPSLogger
|
import info.nightscout.androidaps.logging.AAPSLogger
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui
|
import info.nightscout.androidaps.plugins.aps.events.EventOpenAPSUpdateGui
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning
|
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusProgressIfRunning
|
||||||
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress
|
||||||
|
|
|
@ -7,7 +7,6 @@ import info.nightscout.androidaps.MainApp
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.TestBaseWithProfile
|
import info.nightscout.androidaps.TestBaseWithProfile
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin
|
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin
|
||||||
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.ConstraintChecker
|
||||||
|
@ -44,7 +43,7 @@ import java.util.*
|
||||||
* Created by mike on 18.03.2018.
|
* Created by mike on 18.03.2018.
|
||||||
*/
|
*/
|
||||||
@RunWith(PowerMockRunner::class)
|
@RunWith(PowerMockRunner::class)
|
||||||
@PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class, OpenAPSMAPlugin::class, OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class, VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class)
|
@PrepareForTest(MainApp::class, ConfigBuilderPlugin::class, ConstraintChecker::class, SP::class, Context::class, OpenAPSAMAPlugin::class, OpenAPSSMBPlugin::class, TreatmentsPlugin::class, TreatmentService::class, VirtualPumpPlugin::class, DetailedBolusInfoStorage::class, GlimpPlugin::class)
|
||||||
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
|
|
||||||
@Mock lateinit var activePlugin: ActivePluginProvider
|
@Mock lateinit var activePlugin: ActivePluginProvider
|
||||||
|
@ -70,7 +69,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
private lateinit var insightPlugin: LocalInsightPlugin
|
private lateinit var insightPlugin: LocalInsightPlugin
|
||||||
private lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
private lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin
|
||||||
private lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
private lateinit var openAPSAMAPlugin: OpenAPSAMAPlugin
|
||||||
private lateinit var openAPSMAPlugin: OpenAPSMAPlugin
|
|
||||||
private lateinit var hardLimits: HardLimits
|
private lateinit var hardLimits: HardLimits
|
||||||
|
|
||||||
val injector = HasAndroidInjector {
|
val injector = HasAndroidInjector {
|
||||||
|
@ -119,8 +117,7 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context)
|
insightPlugin = LocalInsightPlugin(injector, aapsLogger, rxBus, resourceHelper, treatmentsPlugin, sp, commandQueue, profileFunction, context)
|
||||||
openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits)
|
openAPSSMBPlugin = OpenAPSSMBPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits)
|
||||||
openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits)
|
openAPSAMAPlugin = OpenAPSAMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits)
|
||||||
openAPSMAPlugin = OpenAPSMAPlugin(injector, aapsLogger, rxBus, constraintChecker, resourceHelper, profileFunction, context, activePlugin, treatmentsPlugin, iobCobCalculatorPlugin, hardLimits)
|
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin)
|
||||||
safetyPlugin = SafetyPlugin(injector, aapsLogger, resourceHelper, sp, rxBus, constraintChecker, openAPSAMAPlugin, openAPSMAPlugin, openAPSSMBPlugin, sensitivityOref1Plugin, activePlugin, hardLimits, buildHelper, treatmentsPlugin)
|
|
||||||
val constraintsPluginsList = ArrayList<PluginBase?>()
|
val constraintsPluginsList = ArrayList<PluginBase?>()
|
||||||
constraintsPluginsList.add(safetyPlugin)
|
constraintsPluginsList.add(safetyPlugin)
|
||||||
constraintsPluginsList.add(objectivesPlugin)
|
constraintsPluginsList.add(objectivesPlugin)
|
||||||
|
@ -316,7 +313,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getDouble(R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5)
|
`when`(sp.getDouble(R.string.key_openapsma_max_iob, 1.5)).thenReturn(1.5)
|
||||||
`when`(sp.getString(R.string.key_age, "")).thenReturn("teenage")
|
`when`(sp.getString(R.string.key_age, "")).thenReturn("teenage")
|
||||||
openAPSAMAPlugin.setPluginEnabled(PluginType.APS, true)
|
openAPSAMAPlugin.setPluginEnabled(PluginType.APS, true)
|
||||||
openAPSMAPlugin.setPluginEnabled(PluginType.APS, false)
|
|
||||||
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, false)
|
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, false)
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
|
@ -333,7 +329,6 @@ class ConstraintsCheckerTest : TestBaseWithProfile() {
|
||||||
`when`(sp.getString(R.string.key_age, "")).thenReturn("teenage")
|
`when`(sp.getString(R.string.key_age, "")).thenReturn("teenage")
|
||||||
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true)
|
openAPSSMBPlugin.setPluginEnabled(PluginType.APS, true)
|
||||||
openAPSAMAPlugin.setPluginEnabled(PluginType.APS, false)
|
openAPSAMAPlugin.setPluginEnabled(PluginType.APS, false)
|
||||||
openAPSMAPlugin.setPluginEnabled(PluginType.APS, false)
|
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
val d = constraintChecker.getMaxIOBAllowed()
|
val d = constraintChecker.getMaxIOBAllowed()
|
||||||
|
|
Loading…
Reference in a new issue