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 fdcc1cef28..c5da7fb7b0 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt +++ b/app/src/main/java/info/nightscout/androidaps/activities/MyPreferenceFragment.kt @@ -82,7 +82,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 @@ -164,7 +163,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 16f454393e..6918e2d9e3 100644 --- a/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt +++ b/app/src/main/java/info/nightscout/androidaps/dependencyInjection/PluginsModule.kt @@ -47,7 +47,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.* @@ -97,90 +96,84 @@ 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 diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java index 78c79d691f..68c9ee7112 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/constraints/objectives/objectives/Objective2.java @@ -130,14 +130,12 @@ public class Objective2 extends Objective { ); tasks.add(new ExamTask(R.string.sensitivity_label, R.string.sensitivity_which,"sensitivity") .option(new Option(R.string.sensitivityweightedaverage, true)) - .option(new Option(R.string.sensitivityoref0, false)) .option(new Option(R.string.sensitivityoref1, false)) .option(new Option(R.string.sensitivityaaps, true)) .hint(new Hint(R.string.sensitivity_hint1)) ); tasks.add(new ExamTask(R.string.sensitivity_label, R.string.sensitivityuam_which,"sensitivityuam") .option(new Option(R.string.sensitivityweightedaverage, false)) - .option(new Option(R.string.sensitivityoref0, false)) .option(new Option(R.string.sensitivityoref1, true)) .option(new Option(R.string.sensitivityaaps, false)) .hint(new Hint(R.string.sensitivity_hint1)) 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 778129715c..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 @@ -27,6 +27,7 @@ import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.resources.ResourceHelper; import info.nightscout.androidaps.utils.sharedPreferences.SP; + /** * Created by mike on 19.06.2018. */ @@ -49,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; @@ -83,8 +85,18 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { List siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true); List profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true); - List deviationsArray = new ArrayList<>(); - String pastSensitivity = ""; + //[0] = 8 hour + //[1] = 24 hour + //Deviationshour has DeviationsArray + List deviationsHour = Arrays.asList(new ArrayList(),new ArrayList()); + List pastSensitivityArray = Arrays.asList("",""); + List sensResultArray = Arrays.asList("",""); + List ratioArray = Arrays.asList(0d,0d); + List deviationCategory = Arrays.asList(96d,288d); + List ratioLimitArray = Arrays.asList("",""); + List hoursDetection = Arrays.asList(8d,24d); + + int index = 0; while (index < autosensDataTable.size()) { AutosensData autosensData = autosensDataTable.valueAt(index); @@ -98,98 +110,133 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin { index++; continue; } + int hoursegment = 0; + //hoursegment = 0 = 8 hour + //hoursegment = 1 = 24 hour + while (hoursegment < deviationsHour.size()){ + ArrayList deviationsArray = deviationsHour.get(hoursegment); + String pastSensitivity = pastSensitivityArray.get(hoursegment); - // reset deviations after site change - if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) { - deviationsArray.clear(); - pastSensitivity += "(SITECHANGE)"; - } + // 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)"; - } + // reset deviations after profile switch + if (ProfileSwitch.isEvent5minBack(getAapsLogger(),profileSwitches, autosensData.time, true)) { + deviationsArray.clear(); + pastSensitivity += "(PROFILESWITCH)"; + } - double deviation = autosensData.deviation; + double deviation = autosensData.deviation; - //set positive deviations to zero if bg < 80 - if (autosensData.bg < 80 && deviation > 0) - deviation = 0; + //set positive deviations to zero if bg < 80 + if (autosensData.bg < 80 && deviation > 0) + deviation = 0; - if (autosensData.validDeviation) - deviationsArray.add(deviation); + if (autosensData.validDeviation) + if (autosensData.time > toTime - hoursDetection.get(hoursegment) * 60 * 60 * 1000L) + deviationsArray.add(deviation); - for (int i = 0; i < autosensData.extraDeviation.size(); i++) - deviationsArray.add(autosensData.extraDeviation.get(i)); - if (deviationsArray.size() > 96) - 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++; + for (int i = 0; i < autosensData.extraDeviation.size(); i++) + deviationsArray.add(autosensData.extraDeviation.get(i)); + + if (deviationsArray.size() > deviationCategory.get(hoursegment)){ + 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) + ")"; + } + + //Update the data back to the parent + deviationsHour.set(hoursegment,deviationsArray); + pastSensitivityArray.set(hoursegment,pastSensitivity); + hoursegment++; + } + index++; } - // when we have less than 8h worth of deviation data, add up to 90m of zero deviations + // when we have less than 8h/24 worth of deviation data, add up to 90m of zero deviations // this dampens any large sensitivity changes detected based on too little data, without ignoring them completely - getAapsLogger().debug(LTag.AUTOSENS, "Using most recent " + deviationsArray.size() + " deviations"); - if (deviationsArray.size() < 96) { - int pad = (int) Math.round((1 - (double) deviationsArray.size() / 96) * 18); - getAapsLogger().debug(LTag.AUTOSENS, "Adding " + pad + " more zero deviations"); - for (int d = 0; d < pad; d++) { - //process.stderr.write("."); - deviationsArray.add(0d); + + for (int i = 0; i < deviationsHour.size(); i++) { + ArrayList deviations = deviationsHour.get(i); + getAapsLogger().debug(LTag.AUTOSENS,"Using most recent " + deviations.size() + " deviations"); + if (deviations.size() < deviationCategory.get(i)) { + int pad = (int) Math.round((1 - (double) deviations.size() / deviationCategory.get(i)) * 18); + getAapsLogger().debug(LTag.AUTOSENS,"Adding " + pad + " more zero deviations"); + for (int d = 0; d < pad; d++) { ; + deviations.add(0d); + } } + //Update the data back to the parent + deviationsHour.set(i,deviations); + } - Double[] deviations = new Double[deviationsArray.size()]; - deviations = deviationsArray.toArray(deviations); - - double sens = profile.getIsfMgdl(); - - double ratio = 1; - String ratioLimit = ""; - String sensResult = ""; - - getAapsLogger().debug(LTag.AUTOSENS, "Records: " + index + " " + pastSensitivity); - - Arrays.sort(deviations); - /* Not used in calculation - for (double i = 0.9; i > 0.1; i = i - 0.01) { - if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.01)) >= 0 && IobCobCalculatorPlugin.percentile(deviations, i) < 0) { - if (L.isEnabled(L.AUTOSENS)) - log.debug(Math.round(100 * i) + "% of non-meal deviations negative (>50% = sensitivity)"); + int hourused = 0; + while (hourused < deviationsHour.size()){ + ArrayList deviationsArray = deviationsHour.get(hourused); + String pastSensitivity = pastSensitivityArray.get(hourused); + String sensResult = "(8 hours) "; + String senstime = sensResult; + if (hourused == 1){ + senstime = "(24 hours) "; + sensResult = senstime; } - if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.01)) > 0 && IobCobCalculatorPlugin.percentile(deviations, i) <= 0) { - if (L.isEnabled(L.AUTOSENS)) - log.debug(Math.round(100 * i) + "% of non-meal deviations positive (>50% = resistance)"); + String ratioLimit = ""; + + Double[] deviations = new Double[deviationsArray.size()]; + deviations = (Double[]) deviationsArray.toArray(deviations); + + double sens = profile.getIsfMgdl(); + + + getAapsLogger().debug(LTag.AUTOSENS,"Records: " + index + " " + pastSensitivity); + + Arrays.sort(deviations); + double pSensitive = IobCobCalculatorPlugin.percentile(deviations, 0.50); + double pResistant = IobCobCalculatorPlugin.percentile(deviations, 0.50); + + double basalOff = 0; + + if (pSensitive < 0) { // sensitive + basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + sensResult+= "Excess insulin sensitivity detected"; + } else if (pResistant > 0) { // resistant + basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits()); + sensResult+= "Excess insulin resistance detected"; + } else { + sensResult+= "Sensitivity normal"; } - } - */ - double pSensitive = IobCobCalculatorPlugin.percentile(deviations, 0.50); - double pResistant = IobCobCalculatorPlugin.percentile(deviations, 0.50); - double basalOff = 0; + getAapsLogger().debug(LTag.AUTOSENS,sensResult); - 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"; + double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); + + //Update the data back to the parent + sensResultArray.set(hourused,sensResult); + ratioArray.set(hourused,ratio); + ratioLimitArray.set(hourused,ratioLimit); + hourused++; } - getAapsLogger().debug(LTag.AUTOSENS, sensResult); - - ratio = 1 + (basalOff / profile.getMaxDailyBasal()); - - AutosensResult output = fillResult(ratio, current.cob, pastSensitivity, ratioLimit, - sensResult, deviationsArray.size()); + int key = 1; + String comparison = " 8 h ratio " +ratioArray.get(0)+" vs 24h ratio "+ratioArray.get(1); + //use 24 hour ratio by default + //if the 8 hour ratio is less than the 24 hour ratio, the 8 hour ratio is used + if(ratioArray.get(0) < ratioArray.get(1)){ + key = 0; + } + String message = hoursDetection.get(key)+" of sensitivity used"; + AutosensResult output = fillResult(ratioArray.get(key), current.cob, pastSensitivityArray.get(key), ratioLimitArray.get(key), + sensResultArray.get(key)+comparison, deviationsHour.get(key).size()); getAapsLogger().debug(LTag.AUTOSENS, "Sensitivity to: " + DateUtil.dateAndTimeString(toTime) + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 47f535c51a..148b1e538f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -66,8 +66,7 @@ Pump integration for people who do multiple daily injections for their diabetes therapy Pump integration for pumps which don\'t have any driver yet (Open Loop) Sensitivity is calculated the same way like Oref0, but you can specify timeframe to the past. Minimal carb absorption is calculated from max carb absorption time from preferences. - Sensitivity is calculated from 24h data in the past and carbs (if not absorbed) are cut after time specified in preferences. - Sensitivity is calculated from 8h data in the past and carbs (if not absorbed) are cut after time specified in preferences. Plugin also calculates UAM. + Sensitivity is calculated from 8h or 24h data in the past (using either which is more sensitive). Carbs (if not absorbed) are cut after time specified in preferences. Plugin also calculates UAM. Sensitivity is calculated as a weighted average from deviations. Newer deviations have higher weight. Minimal carb absorption is calculated from max carb absorption time from preferences. This algorithm is the fastest in following sensitivity changes. Receive BG values from the patched Eversense app. Receive BG values from Glimp.