APS plugins injection
This commit is contained in:
parent
716053229a
commit
270c1c69f4
4 changed files with 168 additions and 95 deletions
|
@ -22,10 +22,10 @@ import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
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;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
|
@ -36,11 +36,19 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.HardLimits;
|
import info.nightscout.androidaps.utils.HardLimits;
|
||||||
import info.nightscout.androidaps.utils.Profiler;
|
import info.nightscout.androidaps.utils.Profiler;
|
||||||
import info.nightscout.androidaps.utils.Round;
|
import info.nightscout.androidaps.utils.Round;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
|
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
|
private final RxBusWrapper rxBus;
|
||||||
|
private final ConstraintChecker constraintChecker;
|
||||||
|
private final ResourceHelper resourceHelper;
|
||||||
|
private final ProfileFunction profileFunction;
|
||||||
|
private final MainApp mainApp;
|
||||||
|
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||||
|
private final TreatmentsPlugin treatmentsPlugin;
|
||||||
|
|
||||||
// last values
|
// last values
|
||||||
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
||||||
long lastAPSRun = 0;
|
long lastAPSRun = 0;
|
||||||
|
@ -48,7 +56,16 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
AutosensResult lastAutosensResult = null;
|
AutosensResult lastAutosensResult = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OpenAPSAMAPlugin(AAPSLogger aapsLogger) {
|
public OpenAPSAMAPlugin(
|
||||||
|
AAPSLogger aapsLogger,
|
||||||
|
RxBusWrapper rxBus,
|
||||||
|
ConstraintChecker constraintChecker,
|
||||||
|
ResourceHelper resourceHelper,
|
||||||
|
ProfileFunction profileFunction,
|
||||||
|
MainApp mainApp,
|
||||||
|
ConfigBuilderPlugin configBuilderPlugin,
|
||||||
|
TreatmentsPlugin treatmentsPlugin
|
||||||
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.APS)
|
.mainType(PluginType.APS)
|
||||||
.fragmentClass(OpenAPSAMAFragment.class.getName())
|
.fragmentClass(OpenAPSAMAFragment.class.getName())
|
||||||
|
@ -58,17 +75,24 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
.description(R.string.description_ama)
|
.description(R.string.description_ama)
|
||||||
);
|
);
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
|
this.rxBus = rxBus;
|
||||||
|
this.constraintChecker = constraintChecker;
|
||||||
|
this.resourceHelper = resourceHelper;
|
||||||
|
this.profileFunction = profileFunction;
|
||||||
|
this.mainApp = mainApp;
|
||||||
|
this.configBuilderPlugin = configBuilderPlugin;
|
||||||
|
this.treatmentsPlugin = treatmentsPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean specialEnableCondition() {
|
public boolean specialEnableCondition() {
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean specialShowInListCondition() {
|
public boolean specialShowInListCondition() {
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,37 +111,37 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
DetermineBasalAdapterAMAJS determineBasalAdapterAMAJS;
|
||||||
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
|
determineBasalAdapterAMAJS = new DetermineBasalAdapterAMAJS(new ScriptReader(mainApp), aapsLogger);
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
Profile profile = profileFunction.getProfile();
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.noprofileselected)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pump == null) {
|
if (pump == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.nopumpselected)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.nopumpselected));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
if (!isEnabled(PluginType.APS)) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_disabled)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.openapsma_disabled));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glucoseStatus == null) {
|
if (glucoseStatus == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_noglucosedata)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.openapsma_noglucosedata));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double maxBasal = ConstraintChecker.getInstance().getMaxBasalAllowed(profile).value();
|
double maxBasal = constraintChecker.getMaxBasalAllowed(profile).value();
|
||||||
double minBg = profile.getTargetLowMgdl();
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = profile.getTargetHighMgdl();
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
double targetBg = profile.getTargetMgdl();
|
double targetBg = profile.getTargetMgdl();
|
||||||
|
@ -131,17 +155,17 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
MealData mealData = treatmentsPlugin.getMealData();
|
||||||
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
||||||
|
|
||||||
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
double maxIob = constraintChecker.getMaxIOBAllowed().value();
|
||||||
|
|
||||||
minBg = HardLimits.verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
|
minBg = HardLimits.verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
|
||||||
maxBg = HardLimits.verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
maxBg = HardLimits.verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
||||||
targetBg = HardLimits.verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]);
|
targetBg = HardLimits.verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]);
|
||||||
|
|
||||||
boolean isTempTarget = false;
|
boolean isTempTarget = false;
|
||||||
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis());
|
TempTarget tempTarget = treatmentsPlugin.getTempTargetFromHistory(System.currentTimeMillis());
|
||||||
if (tempTarget != null) {
|
if (tempTarget != null) {
|
||||||
isTempTarget = true;
|
isTempTarget = true;
|
||||||
minBg = HardLimits.verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]);
|
minBg = HardLimits.verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]);
|
||||||
|
@ -162,10 +186,10 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
|
if (constraintChecker.isAutosensModeEnabled().value()) {
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||||
if (autosensData == null) {
|
if (autosensData == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openaps_noasdata)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastAutosensResult = autosensData.autosensResult;
|
lastAutosensResult = autosensData.autosensResult;
|
||||||
|
@ -179,7 +203,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, configBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
||||||
lastAutosensResult.ratio, //autosensDataRatio
|
lastAutosensResult.ratio, //autosensDataRatio
|
||||||
isTempTarget
|
isTempTarget
|
||||||
);
|
);
|
||||||
|
@ -198,7 +222,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
lastAPSRun = 0;
|
lastAPSRun = 0;
|
||||||
} else {
|
} else {
|
||||||
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
|
if (determineBasalResultAMA.rate == 0d && determineBasalResultAMA.duration == 0 && !treatmentsPlugin.isTempBasalInProgress())
|
||||||
determineBasalResultAMA.tempBasalRequested = false;
|
determineBasalResultAMA.tempBasalRequested = false;
|
||||||
|
|
||||||
determineBasalResultAMA.iob = iobArray[0];
|
determineBasalResultAMA.iob = iobArray[0];
|
||||||
|
@ -215,7 +239,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
||||||
lastAPSResult = determineBasalResultAMA;
|
lastAPSResult = determineBasalResultAMA;
|
||||||
lastAPSRun = now;
|
lastAPSRun = now;
|
||||||
}
|
}
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateGui());
|
rxBus.send(new EventOpenAPSUpdateGui());
|
||||||
|
|
||||||
//deviceStatus.suggested = determineBasalResultAMA.json;
|
//deviceStatus.suggested = determineBasalResultAMA.json;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,10 @@ import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
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;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.androidaps.utils.DateUtil;
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
|
@ -33,6 +33,7 @@ import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||||
import info.nightscout.androidaps.utils.HardLimits;
|
import info.nightscout.androidaps.utils.HardLimits;
|
||||||
import info.nightscout.androidaps.utils.Profiler;
|
import info.nightscout.androidaps.utils.Profiler;
|
||||||
import info.nightscout.androidaps.utils.Round;
|
import info.nightscout.androidaps.utils.Round;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
|
||||||
import static info.nightscout.androidaps.utils.HardLimits.checkOnlyHardLimits;
|
import static info.nightscout.androidaps.utils.HardLimits.checkOnlyHardLimits;
|
||||||
import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
|
import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
|
||||||
|
@ -40,6 +41,13 @@ import static info.nightscout.androidaps.utils.HardLimits.verifyHardLimits;
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
private final AAPSLogger aapsLogger;
|
private final AAPSLogger aapsLogger;
|
||||||
|
private final RxBusWrapper rxBus;
|
||||||
|
private final ConstraintChecker constraintChecker;
|
||||||
|
private final ResourceHelper resourceHelper;
|
||||||
|
private final ProfileFunction profileFunction;
|
||||||
|
private final MainApp mainApp;
|
||||||
|
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||||
|
private final TreatmentsPlugin treatmentsPlugin;
|
||||||
|
|
||||||
// last values
|
// last values
|
||||||
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
|
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
|
||||||
|
@ -47,7 +55,16 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
DetermineBasalResultMA lastAPSResult = null;
|
DetermineBasalResultMA lastAPSResult = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OpenAPSMAPlugin(AAPSLogger aapsLogger) {
|
public OpenAPSMAPlugin(
|
||||||
|
AAPSLogger aapsLogger,
|
||||||
|
RxBusWrapper rxBus,
|
||||||
|
ConstraintChecker constraintChecker,
|
||||||
|
ResourceHelper resourceHelper,
|
||||||
|
ProfileFunction profileFunction,
|
||||||
|
MainApp mainApp,
|
||||||
|
ConfigBuilderPlugin configBuilderPlugin,
|
||||||
|
TreatmentsPlugin treatmentsPlugin
|
||||||
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.APS)
|
.mainType(PluginType.APS)
|
||||||
.fragmentClass(OpenAPSMAFragment.class.getName())
|
.fragmentClass(OpenAPSMAFragment.class.getName())
|
||||||
|
@ -57,17 +74,24 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
.description(R.string.description_ma)
|
.description(R.string.description_ma)
|
||||||
);
|
);
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
|
this.rxBus = rxBus;
|
||||||
|
this.constraintChecker = constraintChecker;
|
||||||
|
this.resourceHelper = resourceHelper;
|
||||||
|
this.profileFunction = profileFunction;
|
||||||
|
this.mainApp = mainApp;
|
||||||
|
this.configBuilderPlugin = configBuilderPlugin;
|
||||||
|
this.treatmentsPlugin = treatmentsPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean specialEnableCondition() {
|
public boolean specialEnableCondition() {
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean specialShowInListCondition() {
|
public boolean specialShowInListCondition() {
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,37 +110,37 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
|
DetermineBasalAdapterMAJS determineBasalAdapterMAJS;
|
||||||
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
|
determineBasalAdapterMAJS = new DetermineBasalAdapterMAJS(new ScriptReader(mainApp), aapsLogger);
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
Profile profile = profileFunction.getProfile();
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.noprofileselected)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pump == null) {
|
if (pump == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.nopumpselected)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.nopumpselected));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
if (!isEnabled(PluginType.APS)) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_disabled)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.openapsma_disabled));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glucoseStatus == null) {
|
if (glucoseStatus == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_noglucosedata)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.openapsma_noglucosedata));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double maxBasal = ConstraintChecker.getInstance().getMaxBasalAllowed(profile).value();
|
double maxBasal = constraintChecker.getMaxBasalAllowed(profile).value();
|
||||||
|
|
||||||
double minBg = profile.getTargetLowMgdl();
|
double minBg = profile.getTargetLowMgdl();
|
||||||
double maxBg = profile.getTargetHighMgdl();
|
double maxBg = profile.getTargetHighMgdl();
|
||||||
|
@ -126,23 +150,23 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
maxBg = Round.roundTo(maxBg, 0.1d);
|
maxBg = Round.roundTo(maxBg, 0.1d);
|
||||||
|
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
TreatmentsPlugin.getPlugin().updateTotalIOBTreatments();
|
treatmentsPlugin.updateTotalIOBTreatments();
|
||||||
TreatmentsPlugin.getPlugin().updateTotalIOBTempBasals();
|
treatmentsPlugin.updateTotalIOBTempBasals();
|
||||||
IobTotal bolusIob = TreatmentsPlugin.getPlugin().getLastCalculationTreatments();
|
IobTotal bolusIob = treatmentsPlugin.getLastCalculationTreatments();
|
||||||
IobTotal basalIob = TreatmentsPlugin.getPlugin().getLastCalculationTempBasals();
|
IobTotal basalIob = treatmentsPlugin.getLastCalculationTempBasals();
|
||||||
|
|
||||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||||
|
|
||||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
MealData mealData = treatmentsPlugin.getMealData();
|
||||||
|
|
||||||
double maxIob = ConstraintChecker.getInstance().getMaxIOBAllowed().value();
|
double maxIob = constraintChecker.getMaxIOBAllowed().value();
|
||||||
Profiler.log(aapsLogger, LTag.APS, "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]);
|
minBg = verifyHardLimits(minBg, "minBg", HardLimits.VERY_HARD_LIMIT_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_MIN_BG[1]);
|
||||||
maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
maxBg = verifyHardLimits(maxBg, "maxBg", HardLimits.VERY_HARD_LIMIT_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_MAX_BG[1]);
|
||||||
targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]);
|
targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]);
|
||||||
|
|
||||||
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis());
|
TempTarget tempTarget = treatmentsPlugin.getTempTargetFromHistory(System.currentTimeMillis());
|
||||||
if (tempTarget != null) {
|
if (tempTarget != null) {
|
||||||
minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]);
|
minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]);
|
||||||
maxBg = verifyHardLimits(tempTarget.high, "maxBg", HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]);
|
maxBg = verifyHardLimits(tempTarget.high, "maxBg", HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MAX_BG[1]);
|
||||||
|
@ -162,7 +186,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
|
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
|
determineBasalAdapterMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, configBuilderPlugin.getActivePump().getBaseBasalRate(), iobTotal, glucoseStatus, mealData);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
FabricPrivacy.logException(e);
|
FabricPrivacy.logException(e);
|
||||||
return;
|
return;
|
||||||
|
@ -179,8 +203,8 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
lastAPSRun = 0;
|
lastAPSRun = 0;
|
||||||
} else {
|
} else {
|
||||||
// Fix bug determinef basal
|
// Fix bug determine basal
|
||||||
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
|
if (determineBasalResultMA.rate == 0d && determineBasalResultMA.duration == 0 && !treatmentsPlugin.isTempBasalInProgress())
|
||||||
determineBasalResultMA.tempBasalRequested = false;
|
determineBasalResultMA.tempBasalRequested = false;
|
||||||
|
|
||||||
determineBasalResultMA.iob = iobTotal;
|
determineBasalResultMA.iob = iobTotal;
|
||||||
|
@ -195,7 +219,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
||||||
lastAPSResult = determineBasalResultMA;
|
lastAPSResult = determineBasalResultMA;
|
||||||
lastAPSRun = now;
|
lastAPSRun = now;
|
||||||
}
|
}
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateGui());
|
rxBus.send(new EventOpenAPSUpdateGui());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.aps.loop.ScriptReader;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateGui;
|
||||||
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdateResultGui;
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||||
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;
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
||||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||||
|
@ -41,12 +41,20 @@ import info.nightscout.androidaps.utils.HardLimits;
|
||||||
import info.nightscout.androidaps.utils.Profiler;
|
import info.nightscout.androidaps.utils.Profiler;
|
||||||
import info.nightscout.androidaps.utils.Round;
|
import info.nightscout.androidaps.utils.Round;
|
||||||
import info.nightscout.androidaps.utils.ToastUtils;
|
import info.nightscout.androidaps.utils.ToastUtils;
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
|
public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, ConstraintsInterface {
|
||||||
|
private final AAPSLogger aapsLogger;
|
||||||
|
private final RxBusWrapper rxBus;
|
||||||
|
private final ConstraintChecker constraintChecker;
|
||||||
|
private final ResourceHelper resourceHelper;
|
||||||
|
private final ProfileFunction profileFunction;
|
||||||
|
private final MainApp mainApp;
|
||||||
|
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||||
|
private final TreatmentsPlugin treatmentsPlugin;
|
||||||
|
|
||||||
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||||
private final AAPSLogger aapsLogger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use dagger to get an instance
|
* @deprecated Use dagger to get an instance
|
||||||
|
@ -65,7 +73,16 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
AutosensResult lastAutosensResult = null;
|
AutosensResult lastAutosensResult = null;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public OpenAPSSMBPlugin(AAPSLogger aapsLogger) {
|
public OpenAPSSMBPlugin(
|
||||||
|
AAPSLogger aapsLogger,
|
||||||
|
RxBusWrapper rxBus,
|
||||||
|
ConstraintChecker constraintChecker,
|
||||||
|
ResourceHelper resourceHelper,
|
||||||
|
ProfileFunction profileFunction,
|
||||||
|
MainApp mainApp,
|
||||||
|
ConfigBuilderPlugin configBuilderPlugin,
|
||||||
|
TreatmentsPlugin treatmentsPlugin
|
||||||
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.APS)
|
.mainType(PluginType.APS)
|
||||||
.fragmentClass(OpenAPSSMBFragment.class.getName())
|
.fragmentClass(OpenAPSSMBFragment.class.getName())
|
||||||
|
@ -76,17 +93,24 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
);
|
);
|
||||||
this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger
|
this.openAPSSMBPlugin = this; // TODO: only while transitioning to Dagger
|
||||||
this.aapsLogger = aapsLogger;
|
this.aapsLogger = aapsLogger;
|
||||||
|
this.rxBus = rxBus;
|
||||||
|
this.constraintChecker = constraintChecker;
|
||||||
|
this.resourceHelper = resourceHelper;
|
||||||
|
this.profileFunction = profileFunction;
|
||||||
|
this.mainApp = mainApp;
|
||||||
|
this.configBuilderPlugin = configBuilderPlugin;
|
||||||
|
this.treatmentsPlugin = treatmentsPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean specialEnableCondition() {
|
public boolean specialEnableCondition() {
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean specialShowInListCondition() {
|
public boolean specialShowInListCondition() {
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
return pump == null || pump.getPumpDescription().isTempBasalCapable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,42 +126,42 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String initiator, boolean tempBasalFallback) {
|
public void invoke(String initiator, boolean tempBasalFallback) {
|
||||||
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
aapsLogger.debug(LTag.APS, "invoke from " + initiator + " tempBasalFallback: " + tempBasalFallback);
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
|
DetermineBasalAdapterSMBJS determineBasalAdapterSMBJS;
|
||||||
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(MainApp.instance().getBaseContext()), aapsLogger);
|
determineBasalAdapterSMBJS = new DetermineBasalAdapterSMBJS(new ScriptReader(mainApp), aapsLogger);
|
||||||
|
|
||||||
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
GlucoseStatus glucoseStatus = GlucoseStatus.getGlucoseStatusData();
|
||||||
Profile profile = ProfileFunctions.getInstance().getProfile();
|
Profile profile = profileFunction.getProfile();
|
||||||
PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||||
|
|
||||||
if (profile == null) {
|
if (profile == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.noprofileselected)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.noprofileselected)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.noprofileselected));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.noprofileselected));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pump == null) {
|
if (pump == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.nopumpselected)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.nopumpselected)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.nopumpselected));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.nopumpselected));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isEnabled(PluginType.APS)) {
|
if (!isEnabled(PluginType.APS)) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_disabled)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_disabled)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_disabled));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.openapsma_disabled));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (glucoseStatus == null) {
|
if (glucoseStatus == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openapsma_noglucosedata)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openapsma_noglucosedata)));
|
||||||
aapsLogger.debug(LTag.APS, MainApp.gs(R.string.openapsma_noglucosedata));
|
aapsLogger.debug(LTag.APS, resourceHelper.gs(R.string.openapsma_noglucosedata));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Constraint<Double> inputConstraints = new Constraint<>(0d); // fake. only for collecting all results
|
Constraint<Double> inputConstraints = new Constraint<>(0d); // fake. only for collecting all results
|
||||||
|
|
||||||
Constraint<Double> maxBasalConstraint = ConstraintChecker.getInstance().getMaxBasalAllowed(profile);
|
Constraint<Double> maxBasalConstraint = constraintChecker.getMaxBasalAllowed(profile);
|
||||||
inputConstraints.copyReasons(maxBasalConstraint);
|
inputConstraints.copyReasons(maxBasalConstraint);
|
||||||
double maxBasal = maxBasalConstraint.value();
|
double maxBasal = maxBasalConstraint.value();
|
||||||
double minBg = profile.getTargetLowMgdl();
|
double minBg = profile.getTargetLowMgdl();
|
||||||
|
@ -150,10 +174,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
long startPart = System.currentTimeMillis();
|
long startPart = System.currentTimeMillis();
|
||||||
|
|
||||||
MealData mealData = TreatmentsPlugin.getPlugin().getMealData();
|
MealData mealData = treatmentsPlugin.getMealData();
|
||||||
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
||||||
|
|
||||||
Constraint<Double> maxIOBAllowedConstraint = ConstraintChecker.getInstance().getMaxIOBAllowed();
|
Constraint<Double> maxIOBAllowedConstraint = constraintChecker.getMaxIOBAllowed();
|
||||||
inputConstraints.copyReasons(maxIOBAllowedConstraint);
|
inputConstraints.copyReasons(maxIOBAllowedConstraint);
|
||||||
double maxIob = maxIOBAllowedConstraint.value();
|
double maxIob = maxIOBAllowedConstraint.value();
|
||||||
|
|
||||||
|
@ -162,7 +186,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]);
|
targetBg = verifyHardLimits(targetBg, "targetBg", HardLimits.VERY_HARD_LIMIT_TARGET_BG[0], HardLimits.VERY_HARD_LIMIT_TARGET_BG[1]);
|
||||||
|
|
||||||
boolean isTempTarget = false;
|
boolean isTempTarget = false;
|
||||||
TempTarget tempTarget = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(System.currentTimeMillis());
|
TempTarget tempTarget = treatmentsPlugin.getTempTargetFromHistory(System.currentTimeMillis());
|
||||||
if (tempTarget != null) {
|
if (tempTarget != null) {
|
||||||
isTempTarget = true;
|
isTempTarget = true;
|
||||||
minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]);
|
minBg = verifyHardLimits(tempTarget.low, "minBg", HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[0], HardLimits.VERY_HARD_LIMIT_TEMP_MIN_BG[1]);
|
||||||
|
@ -183,10 +207,10 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
return;
|
return;
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
if (ConstraintChecker.getInstance().isAutosensModeEnabled().value()) {
|
if (constraintChecker.isAutosensModeEnabled().value()) {
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||||
if (autosensData == null) {
|
if (autosensData == null) {
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateResultGui(MainApp.gs(R.string.openaps_noasdata)));
|
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openaps_noasdata)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastAutosensResult = autosensData.autosensResult;
|
lastAutosensResult = autosensData.autosensResult;
|
||||||
|
@ -196,27 +220,27 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
}
|
}
|
||||||
|
|
||||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
||||||
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
||||||
|
|
||||||
startPart = System.currentTimeMillis();
|
startPart = System.currentTimeMillis();
|
||||||
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
|
Constraint<Boolean> smbAllowed = new Constraint<>(!tempBasalFallback);
|
||||||
ConstraintChecker.getInstance().isSMBModeEnabled(smbAllowed);
|
constraintChecker.isSMBModeEnabled(smbAllowed);
|
||||||
inputConstraints.copyReasons(smbAllowed);
|
inputConstraints.copyReasons(smbAllowed);
|
||||||
|
|
||||||
Constraint<Boolean> advancedFiltering = new Constraint<>(!tempBasalFallback);
|
Constraint<Boolean> advancedFiltering = new Constraint<>(!tempBasalFallback);
|
||||||
ConstraintChecker.getInstance().isAdvancedFilteringEnabled(advancedFiltering);
|
constraintChecker.isAdvancedFilteringEnabled(advancedFiltering);
|
||||||
inputConstraints.copyReasons(advancedFiltering);
|
inputConstraints.copyReasons(advancedFiltering);
|
||||||
|
|
||||||
Constraint<Boolean> uam = new Constraint<>(true);
|
Constraint<Boolean> uam = new Constraint<>(true);
|
||||||
ConstraintChecker.getInstance().isUAMEnabled(uam);
|
constraintChecker.isUAMEnabled(uam);
|
||||||
inputConstraints.copyReasons(uam);
|
inputConstraints.copyReasons(uam);
|
||||||
|
|
||||||
Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
|
Profiler.log(aapsLogger, LTag.APS, "detectSensitivityandCarbAbsorption()", startPart);
|
||||||
Profiler.log(aapsLogger, LTag.APS, "SMB data gathering", start);
|
Profiler.log(aapsLogger, LTag.APS, "SMB data gathering", start);
|
||||||
|
|
||||||
start = System.currentTimeMillis();
|
start = System.currentTimeMillis();
|
||||||
try {
|
try {
|
||||||
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, ConfigBuilderPlugin.getPlugin().getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
determineBasalAdapterSMBJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, configBuilderPlugin.getActivePump().getBaseBasalRate(), iobArray, glucoseStatus, mealData,
|
||||||
lastAutosensResult.ratio, //autosensDataRatio
|
lastAutosensResult.ratio, //autosensDataRatio
|
||||||
isTempTarget,
|
isTempTarget,
|
||||||
smbAllowed.value(),
|
smbAllowed.value(),
|
||||||
|
@ -231,16 +255,16 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
|
DetermineBasalResultSMB determineBasalResultSMB = determineBasalAdapterSMBJS.invoke();
|
||||||
Profiler.log(aapsLogger, LTag.APS, "SMB calculation", start);
|
Profiler.log(aapsLogger, LTag.APS, "SMB calculation", start);
|
||||||
if (determineBasalResultSMB == null) {
|
if (determineBasalResultSMB == null) {
|
||||||
aapsLogger.error(LTag.APS, "SMB calculation returned null");
|
aapsLogger.error(LTag.APS, "SMB calculation returned null");
|
||||||
lastDetermineBasalAdapterSMBJS = null;
|
lastDetermineBasalAdapterSMBJS = null;
|
||||||
lastAPSResult = null;
|
lastAPSResult = null;
|
||||||
lastAPSRun = 0;
|
lastAPSRun = 0;
|
||||||
} else {
|
} else {
|
||||||
// TODO still needed with oref1?
|
// TODO still needed with oref1?
|
||||||
// Fix bug determine basal
|
// Fix bug determine basal
|
||||||
if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !TreatmentsPlugin.getPlugin().isTempBasalInProgress())
|
if (determineBasalResultSMB.rate == 0d && determineBasalResultSMB.duration == 0 && !treatmentsPlugin.isTempBasalInProgress())
|
||||||
determineBasalResultSMB.tempBasalRequested = false;
|
determineBasalResultSMB.tempBasalRequested = false;
|
||||||
|
|
||||||
determineBasalResultSMB.iob = iobArray[0];
|
determineBasalResultSMB.iob = iobArray[0];
|
||||||
|
@ -257,7 +281,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
lastAPSResult = determineBasalResultSMB;
|
lastAPSResult = determineBasalResultSMB;
|
||||||
lastAPSRun = now;
|
lastAPSRun = now;
|
||||||
}
|
}
|
||||||
RxBus.Companion.getINSTANCE().send(new EventOpenAPSUpdateGui());
|
rxBus.send(new EventOpenAPSUpdateGui());
|
||||||
|
|
||||||
//deviceStatus.suggested = determineBasalResultAMA.json;
|
//deviceStatus.suggested = determineBasalResultAMA.json;
|
||||||
}
|
}
|
||||||
|
@ -272,12 +296,12 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
||||||
if (newvalue < lowLimit || newvalue > highLimit) {
|
if (newvalue < lowLimit || newvalue > highLimit) {
|
||||||
newvalue = Math.max(newvalue, lowLimit);
|
newvalue = Math.max(newvalue, lowLimit);
|
||||||
newvalue = Math.min(newvalue, highLimit);
|
newvalue = Math.min(newvalue, highLimit);
|
||||||
String msg = String.format(MainApp.gs(R.string.valueoutofrange), valueName);
|
String msg = String.format(resourceHelper.gs(R.string.valueoutofrange), valueName);
|
||||||
msg += ".\n";
|
msg += ".\n";
|
||||||
msg += String.format(MainApp.gs(R.string.valuelimitedto), value, newvalue);
|
msg += String.format(resourceHelper.gs(R.string.valuelimitedto), value, newvalue);
|
||||||
aapsLogger.error(LTag.APS, msg);
|
aapsLogger.error(LTag.APS, msg);
|
||||||
NSUpload.uploadError(msg);
|
NSUpload.uploadError(msg);
|
||||||
ToastUtils.showToastInUiThread(MainApp.instance().getApplicationContext(), msg, R.raw.error);
|
ToastUtils.showToastInUiThread(mainApp, msg, R.raw.error);
|
||||||
}
|
}
|
||||||
return newvalue;
|
return newvalue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import dagger.android.support.DaggerDialogFragment
|
import dagger.android.support.DaggerDialogFragment
|
||||||
import info.nightscout.androidaps.MainApp
|
|
||||||
import info.nightscout.androidaps.R
|
import info.nightscout.androidaps.R
|
||||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||||
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
import info.nightscout.androidaps.plugins.constraints.objectives.events.EventObjectivesUpdateGui
|
||||||
|
@ -15,11 +14,13 @@ import info.nightscout.androidaps.plugins.constraints.objectives.objectives.Obje
|
||||||
import info.nightscout.androidaps.utils.DateUtil
|
import info.nightscout.androidaps.utils.DateUtil
|
||||||
import info.nightscout.androidaps.utils.T
|
import info.nightscout.androidaps.utils.T
|
||||||
import info.nightscout.androidaps.utils.ToastUtils
|
import info.nightscout.androidaps.utils.ToastUtils
|
||||||
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import kotlinx.android.synthetic.main.objectives_exam_fragment.*
|
import kotlinx.android.synthetic.main.objectives_exam_fragment.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ObjectivesExamDialog : DaggerDialogFragment() {
|
class ObjectivesExamDialog : DaggerDialogFragment() {
|
||||||
@Inject lateinit var rxBus: RxBusWrapper
|
@Inject lateinit var rxBus: RxBusWrapper
|
||||||
|
@Inject lateinit var resourceHelper: ResourceHelper
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var objective: Objective? = null
|
var objective: Objective? = null
|
||||||
|
@ -75,7 +76,7 @@ class ObjectivesExamDialog : DaggerDialogFragment() {
|
||||||
objectives_exam_hints.addView(h.generate(context))
|
objectives_exam_hints.addView(h.generate(context))
|
||||||
}
|
}
|
||||||
// Disabled to
|
// Disabled to
|
||||||
objectives_exam_disabledto.text = MainApp.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo))
|
objectives_exam_disabledto.text = resourceHelper.gs(R.string.answerdisabledto, DateUtil.timeString(task.disabledTo))
|
||||||
objectives_exam_disabledto.visibility = if (task.isEnabledAnswer) View.GONE else View.VISIBLE
|
objectives_exam_disabledto.visibility = if (task.isEnabledAnswer) View.GONE else View.VISIBLE
|
||||||
// Buttons
|
// Buttons
|
||||||
objectives_exam_verify.isEnabled = !task.answered && task.isEnabledAnswer
|
objectives_exam_verify.isEnabled = !task.answered && task.isEnabledAnswer
|
||||||
|
|
Loading…
Reference in a new issue