eliminate IobCobCalculatorPlugin::getPlugin
This commit is contained in:
parent
e63169a94b
commit
156738a5cb
5 changed files with 23 additions and 27 deletions
|
@ -10,6 +10,7 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
|
||||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
||||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
|
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||||
|
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -25,9 +26,10 @@ class IobCobStaticCalculatorPlugin @Inject constructor(
|
||||||
treatmentsPlugin: TreatmentsPlugin,
|
treatmentsPlugin: TreatmentsPlugin,
|
||||||
sensitivityOref1Plugin: SensitivityOref1Plugin,
|
sensitivityOref1Plugin: SensitivityOref1Plugin,
|
||||||
sensitivityAAPSPlugin: SensitivityAAPSPlugin,
|
sensitivityAAPSPlugin: SensitivityAAPSPlugin,
|
||||||
sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin
|
sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin,
|
||||||
|
fabricPrivacy: FabricPrivacy
|
||||||
) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction,
|
) : IobCobCalculatorPlugin(injector, aapsLogger, rxBus, sp, resourceHelper, profileFunction,
|
||||||
activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin) {
|
activePlugin, treatmentsPlugin, sensitivityOref1Plugin, sensitivityAAPSPlugin, sensitivityWeightedAveragePlugin, fabricPrivacy) {
|
||||||
|
|
||||||
override fun onStart() { // do not attach to rxbus
|
override fun onStart() { // do not attach to rxbus
|
||||||
}
|
}
|
||||||
|
|
|
@ -391,7 +391,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
lastRun.lastSMBEnact = 0;
|
lastRun.lastSMBEnact = 0;
|
||||||
lastRun.lastSMBRequest = 0;
|
lastRun.lastSMBRequest = 0;
|
||||||
|
|
||||||
NSUpload.uploadDeviceStatus(this);
|
NSUpload.uploadDeviceStatus(this, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump());
|
||||||
|
|
||||||
if (isSuspended()) {
|
if (isSuspended()) {
|
||||||
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended));
|
getAapsLogger().debug(LTag.APS, resourceHelper.gs(R.string.loopsuspended));
|
||||||
|
@ -516,7 +516,7 @@ public class LoopPlugin extends PluginBase {
|
||||||
lastRun.lastTBRRequest = lastRun.lastAPSRun.getTime();
|
lastRun.lastTBRRequest = lastRun.lastAPSRun.getTime();
|
||||||
lastRun.lastTBREnact = DateUtil.now();
|
lastRun.lastTBREnact = DateUtil.now();
|
||||||
lastRun.lastOpenModeAccept = DateUtil.now();
|
lastRun.lastOpenModeAccept = DateUtil.now();
|
||||||
NSUpload.uploadDeviceStatus(lp);
|
NSUpload.uploadDeviceStatus(lp, iobCobCalculatorPlugin, profileFunction, activePlugin.getActivePump());
|
||||||
sp.incInt(R.string.key_ObjectivesmanualEnacts);
|
sp.incInt(R.string.key_ObjectivesmanualEnacts);
|
||||||
}
|
}
|
||||||
rxBus.send(new EventAcceptOpenLoopChange());
|
rxBus.send(new EventAcceptOpenLoopChange());
|
||||||
|
|
|
@ -33,6 +33,7 @@ import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
import info.nightscout.androidaps.logging.StacktraceLoggerWrapper;
|
||||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
import info.nightscout.androidaps.plugins.aps.loop.APSResult;
|
||||||
|
@ -160,9 +161,9 @@ public class NSUpload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void uploadDeviceStatus(LoopPlugin loopPlugin) {
|
public static void uploadDeviceStatus(LoopPlugin loopPlugin, IobCobCalculatorPlugin iobCobCalculatorPlugin, ProfileFunction profileFunction, PumpInterface pumpInterface) {
|
||||||
Profile profile = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfile();
|
Profile profile = profileFunction.getProfile();
|
||||||
String profileName = ConfigBuilderPlugin.getPlugin().getProfileFunction().getProfileName();
|
String profileName = profileFunction.getProfileName();
|
||||||
|
|
||||||
if (profile == null || profileName == null) {
|
if (profile == null || profileName == null) {
|
||||||
log.error("Profile is null. Skipping upload");
|
log.error("Profile is null. Skipping upload");
|
||||||
|
@ -204,14 +205,14 @@ public class NSUpload {
|
||||||
} else {
|
} else {
|
||||||
if (L.isEnabled(L.NSCLIENT))
|
if (L.isEnabled(L.NSCLIENT))
|
||||||
log.debug("OpenAPS data too old to upload, sending iob only");
|
log.debug("OpenAPS data too old to upload, sending iob only");
|
||||||
IobTotal[] iob = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
IobTotal[] iob = iobCobCalculatorPlugin.calculateIobArrayInDia(profile);
|
||||||
if (iob.length > 0) {
|
if (iob.length > 0) {
|
||||||
deviceStatus.iob = iob[0].json();
|
deviceStatus.iob = iob[0].json();
|
||||||
deviceStatus.iob.put("time", DateUtil.toISOString(DateUtil.now()));
|
deviceStatus.iob.put("time", DateUtil.toISOString(DateUtil.now()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
deviceStatus.device = "openaps://" + Build.MANUFACTURER + " " + Build.MODEL;
|
||||||
JSONObject pumpstatus = PluginStore.Companion.getInstance().getActivePump().getJSONStatus(profile, profileName);
|
JSONObject pumpstatus = pumpInterface.getJSONStatus(profile, profileName);
|
||||||
if (pumpstatus != null) {
|
if (pumpstatus != null) {
|
||||||
deviceStatus.pump = pumpstatus;
|
deviceStatus.pump = pumpstatus;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,18 +66,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
private final SensitivityOref1Plugin sensitivityOref1Plugin;
|
private final SensitivityOref1Plugin sensitivityOref1Plugin;
|
||||||
private final SensitivityAAPSPlugin sensitivityAAPSPlugin;
|
private final SensitivityAAPSPlugin sensitivityAAPSPlugin;
|
||||||
private final SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin;
|
private final SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin;
|
||||||
|
private final FabricPrivacy fabricPrivacy;
|
||||||
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
private CompositeDisposable disposable = new CompositeDisposable();
|
||||||
|
|
||||||
private static IobCobCalculatorPlugin plugin = null;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static IobCobCalculatorPlugin getPlugin() {
|
|
||||||
if (plugin == null)
|
|
||||||
throw new IllegalStateException("Accessing IobCobCalculatorPlugin before first instantiation");
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
private LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0
|
private LongSparseArray<IobTotal> iobTable = new LongSparseArray<>(); // oldest at index 0
|
||||||
private LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0
|
private LongSparseArray<AutosensData> autosensDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||||
private LongSparseArray<BasalData> basalDataTable = new LongSparseArray<>(); // oldest at index 0
|
private LongSparseArray<BasalData> basalDataTable = new LongSparseArray<>(); // oldest at index 0
|
||||||
|
@ -102,7 +94,8 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
TreatmentsPlugin treatmentsPlugin,
|
TreatmentsPlugin treatmentsPlugin,
|
||||||
SensitivityOref1Plugin sensitivityOref1Plugin,
|
SensitivityOref1Plugin sensitivityOref1Plugin,
|
||||||
SensitivityAAPSPlugin sensitivityAAPSPlugin,
|
SensitivityAAPSPlugin sensitivityAAPSPlugin,
|
||||||
SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin
|
SensitivityWeightedAveragePlugin sensitivityWeightedAveragePlugin,
|
||||||
|
FabricPrivacy fabricPrivacy
|
||||||
) {
|
) {
|
||||||
super(new PluginDescription()
|
super(new PluginDescription()
|
||||||
.mainType(PluginType.GENERAL)
|
.mainType(PluginType.GENERAL)
|
||||||
|
@ -112,7 +105,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
.alwaysEnabled(true),
|
.alwaysEnabled(true),
|
||||||
aapsLogger, resourceHelper, injector
|
aapsLogger, resourceHelper, injector
|
||||||
);
|
);
|
||||||
this.plugin = this;
|
|
||||||
this.injector = injector;
|
this.injector = injector;
|
||||||
this.sp = sp;
|
this.sp = sp;
|
||||||
this.rxBus = rxBus;
|
this.rxBus = rxBus;
|
||||||
|
@ -123,6 +115,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
this.sensitivityOref1Plugin = sensitivityOref1Plugin;
|
this.sensitivityOref1Plugin = sensitivityOref1Plugin;
|
||||||
this.sensitivityAAPSPlugin = sensitivityAAPSPlugin;
|
this.sensitivityAAPSPlugin = sensitivityAAPSPlugin;
|
||||||
this.sensitivityWeightedAveragePlugin = sensitivityWeightedAveragePlugin;
|
this.sensitivityWeightedAveragePlugin = sensitivityWeightedAveragePlugin;
|
||||||
|
this.fabricPrivacy = fabricPrivacy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -140,7 +133,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
autosensDataTable = new LongSparseArray<>();
|
autosensDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onEventConfigBuilderChange", System.currentTimeMillis(), false, true, event);
|
runCalculation("onEventConfigBuilderChange", System.currentTimeMillis(), false, true, event);
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventNewBasalProfile
|
// EventNewBasalProfile
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
|
@ -158,7 +151,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
basalDataTable = new LongSparseArray<>();
|
basalDataTable = new LongSparseArray<>();
|
||||||
}
|
}
|
||||||
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
|
runCalculation("onNewProfile", System.currentTimeMillis(), false, true, event);
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventNewBG
|
// EventNewBG
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
|
@ -167,7 +160,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
.subscribe(event -> {
|
.subscribe(event -> {
|
||||||
stopCalculation("onEventNewBG");
|
stopCalculation("onEventNewBG");
|
||||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventPreferenceChange
|
// EventPreferenceChange
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
|
@ -192,19 +185,19 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
}
|
}
|
||||||
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, event);
|
runCalculation("onEventPreferenceChange", System.currentTimeMillis(), false, true, event);
|
||||||
}
|
}
|
||||||
}, exception -> FabricPrivacy.getInstance().logException(exception))
|
}, fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventAppInitialized
|
// EventAppInitialized
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventAppInitialized.class)
|
.toObservable(EventAppInitialized.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(event -> runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event), exception -> FabricPrivacy.getInstance().logException(exception))
|
.subscribe(event -> runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event), fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
// EventNewHistoryData
|
// EventNewHistoryData
|
||||||
disposable.add(rxBus
|
disposable.add(rxBus
|
||||||
.toObservable(EventNewHistoryData.class)
|
.toObservable(EventNewHistoryData.class)
|
||||||
.observeOn(Schedulers.io())
|
.observeOn(Schedulers.io())
|
||||||
.subscribe(this::newHistoryData, exception -> FabricPrivacy.getInstance().logException(exception))
|
.subscribe(this::newHistoryData, fabricPrivacy::logException)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,7 +107,7 @@ class KeepAliveReceiver : DaggerBroadcastReceiver() {
|
||||||
else if (DateUtil.isOlderThan(usedAPS.lastAPSRun, 5)) shouldUploadStatus = true
|
else if (DateUtil.isOlderThan(usedAPS.lastAPSRun, 5)) shouldUploadStatus = true
|
||||||
if (DateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY) && shouldUploadStatus) {
|
if (DateUtil.isOlderThan(lastIobUpload, IOB_UPDATE_FREQUENCY) && shouldUploadStatus) {
|
||||||
lastIobUpload = DateUtil.now()
|
lastIobUpload = DateUtil.now()
|
||||||
NSUpload.uploadDeviceStatus(loopPlugin)
|
NSUpload.uploadDeviceStatus(loopPlugin, iobCobCalculatorPlugin, profileFunction, activePlugin.activePump)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue