From f707c7263422967a03066277dbbb614b0f37696c Mon Sep 17 00:00:00 2001 From: Tim Gunn <2896311+Tornado-Tim@users.noreply.github.com> Date: Sun, 5 Apr 2020 22:02:37 +1200 Subject: [PATCH] Remove oref0 sensitivity --- .../activities/MyPreferenceFragment.kt | 2 - .../dependencyInjection/PluginsModule.kt | 45 ++--- .../sensitivity/SensitivityOref0Plugin.java | 182 ------------------ .../sensitivity/SensitivityOref1Plugin.java | 3 +- 4 files changed, 21 insertions(+), 211 deletions(-) delete mode 100644 app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java diff --git a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt index 187ab7b33d..fd8487f8d1 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -84,7 +84,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang @Inject lateinit var openAPSSMBPlugin: OpenAPSSMBPlugin @Inject lateinit var safetyPlugin: SafetyPlugin @Inject lateinit var sensitivityAAPSPlugin: SensitivityAAPSPlugin - @Inject lateinit var sensitivityOref0Plugin: SensitivityOref1Plugin @Inject lateinit var sensitivityOref1Plugin: SensitivityOref1Plugin @Inject lateinit var sensitivityWeightedAveragePlugin: SensitivityWeightedAveragePlugin @Inject lateinit var dexcomPlugin: DexcomPlugin @@ -167,7 +166,6 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang addPreferencesFromResourceIfEnabled(openAPSSMBPlugin, rootKey, Config.APS) addPreferencesFromResourceIfEnabled(sensitivityAAPSPlugin, rootKey) addPreferencesFromResourceIfEnabled(sensitivityWeightedAveragePlugin, rootKey) - addPreferencesFromResourceIfEnabled(sensitivityOref0Plugin, rootKey) addPreferencesFromResourceIfEnabled(sensitivityOref1Plugin, rootKey) addPreferencesFromResourceIfEnabled(danaRPlugin, rootKey, Config.PUMPDRIVERS) addPreferencesFromResourceIfEnabled(danaRKoreanPlugin, rootKey, Config.PUMPDRIVERS) diff --git a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt index cc3694874f..8e9fe08d87 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -48,7 +48,6 @@ import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin -import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin import info.nightscout.androidaps.plugins.source.* @@ -98,126 +97,120 @@ abstract class PluginsModule { @AllConfigs @IntoMap @IntKey(60) - abstract fun bindSensitivityOref0Plugin(plugin: SensitivityOref0Plugin): PluginBase - - @Binds - @AllConfigs - @IntoMap - @IntKey(70) abstract fun bindSensitivityAAPSPlugin(plugin: SensitivityAAPSPlugin): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(80) + @IntKey(70) abstract fun bindSensitivityWeightedAveragePlugin(plugin: SensitivityWeightedAveragePlugin): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(90) + @IntKey(80) abstract fun bindSensitivityOref1Plugin(plugin: SensitivityOref1Plugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(100) + @IntKey(90) abstract fun bindDanaRPlugin(plugin: DanaRPlugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(110) + @IntKey(100) abstract fun bindDanaRKoreanPlugin(plugin: DanaRKoreanPlugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(120) + @IntKey(110) abstract fun bindDanaRv2Plugin(plugin: DanaRv2Plugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(130) + @IntKey(120) abstract fun bindDanaRSPlugin(plugin: DanaRSPlugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(140) + @IntKey(130) abstract fun bindLocalInsightPlugin(plugin: LocalInsightPlugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(150) + @IntKey(140) abstract fun bindComboPlugin(plugin: ComboPlugin): PluginBase @Binds @PumpDriver @IntoMap - @IntKey(160) + @IntKey(150) abstract fun bindMedtronicPumpPlugin(plugin: MedtronicPumpPlugin): PluginBase @Binds @NotNSClient @IntoMap - @IntKey(170) + @IntKey(160) abstract fun bindMDIPlugin(plugin: MDIPlugin): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(180) + @IntKey(170) abstract fun bindVirtualPumpPlugin(plugin: VirtualPumpPlugin): PluginBase @Binds @NotNSClient @IntoMap - @IntKey(190) + @IntKey(180) abstract fun bindCareportalPlugin(plugin: CareportalPlugin): PluginBase @Binds @APS @IntoMap - @IntKey(200) + @IntKey(190) abstract fun bindLoopPlugin(plugin: LoopPlugin): PluginBase @Binds @APS @IntoMap - @IntKey(210) + @IntKey(200) abstract fun bindOpenAPSMAPlugin(plugin: OpenAPSMAPlugin): PluginBase @Binds @APS @IntoMap - @IntKey(220) + @IntKey(210) abstract fun bindOpenAPSAMAPlugin(plugin: OpenAPSAMAPlugin): PluginBase @Binds @APS @IntoMap - @IntKey(230) + @IntKey(220) abstract fun bindOpenAPSSMBPlugin(plugin: OpenAPSSMBPlugin): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(240) + @IntKey(230) abstract fun bindNSProfilePlugin(plugin: NSProfilePlugin): PluginBase @Binds @NotNSClient @IntoMap - @IntKey(250) + @IntKey(240) abstract fun bindLocalProfilePlugin(plugin: LocalProfilePlugin): PluginBase @Binds @AllConfigs @IntoMap - @IntKey(255) + @IntKey(250) abstract fun bindAutomationPlugin(plugin: AutomationPlugin): PluginBase @Binds diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java deleted file mode 100644 index 423be4f548..0000000000 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref0Plugin.java +++ /dev/null @@ -1,182 +0,0 @@ -package info.nightscout.androidaps.plugins.sensitivity; - -import androidx.annotation.NonNull; -import androidx.collection.LongSparseArray; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import dagger.android.HasAndroidInjector; -import info.nightscout.androidaps.MainApp; -import info.nightscout.androidaps.R; -import info.nightscout.androidaps.data.Profile; -import info.nightscout.androidaps.db.CareportalEvent; -import info.nightscout.androidaps.db.ProfileSwitch; -import info.nightscout.androidaps.interfaces.PluginDescription; -import info.nightscout.androidaps.interfaces.PluginType; -import info.nightscout.androidaps.logging.AAPSLogger; -import info.nightscout.androidaps.logging.LTag; -import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult; -import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; -import info.nightscout.androidaps.utils.DateUtil; -import info.nightscout.androidaps.utils.resources.ResourceHelper; -import info.nightscout.androidaps.utils.sharedPreferences.SP; - -/** - * Created by mike on 24.06.2017. - */ -@Singleton -public class SensitivityOref0Plugin extends AbstractSensitivityPlugin { - - private ProfileFunction profileFunction; - - @Inject - public SensitivityOref0Plugin( - HasAndroidInjector injector, - AAPSLogger aapsLogger, - ResourceHelper resourceHelper, - SP sp, - ProfileFunction profileFunction - ) { - super(new PluginDescription() - .mainType(PluginType.SENSITIVITY) - .pluginName(R.string.sensitivityoref0) - .shortName(R.string.sensitivity_shortname) - .preferencesId(R.xml.pref_absorption_oref0) - .description(R.string.description_sensitivity_oref0) - .setDefault(), - injector, aapsLogger, resourceHelper, sp - ); - this.profileFunction = profileFunction; - } - - @NonNull @Override - public AutosensResult detectSensitivity(IobCobCalculatorPlugin iobCobCalculatorPlugin, long fromTime, long toTime) { - LongSparseArray autosensDataTable = iobCobCalculatorPlugin.getAutosensDataTable(); - - int hoursForDetection = 24; - - Profile profile = profileFunction.getProfile(); - - if (profile == null) { - getAapsLogger().error("No profile"); - return new AutosensResult(); - } - - if (autosensDataTable == null || autosensDataTable.size() < 4) { - getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. lastDataTime=" + iobCobCalculatorPlugin.lastDataTime()); - return new AutosensResult(); - } - - AutosensData current = iobCobCalculatorPlugin.getAutosensData(toTime); // this is running inside lock already - if (current == null) { - getAapsLogger().debug(LTag.AUTOSENS, "No autosens data available. toTime: " + DateUtil.dateAndTimeString(toTime) + " lastDataTime: " + iobCobCalculatorPlugin.lastDataTime()); - return new AutosensResult(); - } - - - List siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true); - List profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true); - - List deviationsArray = new ArrayList<>(); - String pastSensitivity = ""; - int index = 0; - while (index < autosensDataTable.size()) { - AutosensData autosensData = autosensDataTable.valueAt(index); - - if (autosensData.time < fromTime) { - index++; - continue; - } - - if (autosensData.time > toTime) { - index++; - continue; - } - - // reset deviations after site change - if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) { - deviationsArray.clear(); - pastSensitivity += "(SITECHANGE)"; - } - - // reset deviations after profile switch - if (ProfileSwitch.isEvent5minBack(getAapsLogger(), profileSwitches, autosensData.time, true)) { - deviationsArray.clear(); - pastSensitivity += "(PROFILESWITCH)"; - } - - double deviation = autosensData.deviation; - - //set positive deviations to zero if bg < 80 - if (autosensData.bg < 80 && deviation > 0) - deviation = 0; - - if (autosensData.validDeviation) - if (autosensData.time > toTime - hoursForDetection * 60 * 60 * 1000L) - deviationsArray.add(deviation); - if (deviationsArray.size() > hoursForDetection * 60 / 5) - deviationsArray.remove(0); - - pastSensitivity += autosensData.pastSensitivity; - int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time); - if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) { - pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")"; - } - index++; - } - - Double[] deviations = new Double[deviationsArray.size()]; - deviations = deviationsArray.toArray(deviations); - - double sens = profile.getIsfMgdl(); - - double ratio; - String ratioLimit = ""; - String sensResult; - - getAapsLogger().debug(LTag.AUTOSENS, "Records: " + index + " " + pastSensitivity); - - Arrays.sort(deviations); - - for (double i = 0.9; i > 0.1; i = i - 0.02) { - if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.02)) >= 0 && IobCobCalculatorPlugin.percentile(deviations, i) < 0) { - getAapsLogger().debug(LTag.AUTOSENS, Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)"); - } - } - double pSensitive = IobCobCalculatorPlugin.percentile(deviations, 0.50); - double pResistant = IobCobCalculatorPlugin.percentile(deviations, 0.45); - - double basalOff = 0; - - if (pSensitive < 0) { // sensitive - basalOff = pSensitive * (60 / 5.0) / sens; - sensResult = "Excess insulin sensitivity detected"; - } else if (pResistant > 0) { // resistant - basalOff = pResistant * (60 / 5.0) / sens; - sensResult = "Excess insulin resistance detected"; - } else { - sensResult = "Sensitivity normal"; - } - - getAapsLogger().debug(LTag.AUTOSENS, sensResult); - - ratio = 1 + (basalOff / profile.getMaxDailyBasal()); - - AutosensResult output = fillResult(ratio, current.cob, pastSensitivity, ratioLimit, - sensResult, deviationsArray.size()); - - getAapsLogger().debug(LTag.AUTOSENS, "Sensitivity to: " - + DateUtil.dateAndTimeString(toTime) + - " ratio: " + output.ratio - + " mealCOB: " + current.cob); - - return output; - } -} diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java index a0c52c195d..f83e17fd7a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/sensitivity/SensitivityOref1Plugin.java @@ -50,7 +50,8 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { .shortName(R.string.sensitivity_shortname) .enableByDefault(true) .preferencesId(R.xml.pref_absorption_oref1) - .description(R.string.description_sensitivity_oref1), + .description(R.string.description_sensitivity_oref1) + .setDefault(), injector, aapsLogger, resourceHelper, sp ); this.profileFunction = profileFunction;