downweight Autosens if not enough data

This commit is contained in:
AdrianLxM 2018-06-23 14:05:12 +02:00
parent 53ba6d46d5
commit 064a8915a0
5 changed files with 48 additions and 6 deletions

View file

@ -7,5 +7,8 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
*/
public interface SensitivityInterface {
double MIN_HOURS = 1;
double MIN_HOURS_FULL_AUTOSENS = 4;
AutosensResult detectSensitivity(long fromTime, long toTime);
}

View file

@ -158,8 +158,18 @@ public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInte
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7")));
ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
//If not-excluded data <= MIN_HOURS -> don't do Autosens
//If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens
//Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens
double autosensContrib = (Math.min(Math.max(MIN_HOURS, deviationsArray.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS);
ratio = autosensContrib * (ratio - 1) + 1;
if (autosensContrib != 1d) {
ratioLimit += "(" + deviationsArray.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) ";
}
if (ratio != rawRatio) {
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio;
log.debug(ratioLimit);
}

View file

@ -170,8 +170,18 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7")));
ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
//If not-excluded data <= MIN_HOURS -> don't do Autosens
//If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens
//Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens
double autosensContrib = (Math.min(Math.max(MIN_HOURS, deviationsArray.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS);
ratio = autosensContrib * (ratio - 1) + 1;
if (autosensContrib != 1d) {
ratioLimit += "(" + deviationsArray.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) ";
}
if (ratio != rawRatio) {
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio;
log.debug(ratioLimit);
}

View file

@ -179,8 +179,18 @@ public class SensitivityOref1Plugin extends PluginBase implements SensitivityInt
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7")));
ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
//If not-excluded data <= MIN_HOURS -> don't do Autosens
//If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens
//Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens
double autosensContrib = (Math.min(Math.max(MIN_HOURS, deviationsArray.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS);
ratio = autosensContrib * (ratio - 1) + 1;
if (autosensContrib != 1d) {
ratioLimit += "(" + deviationsArray.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) ";
}
if (ratio != rawRatio) {
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio;
log.debug(ratioLimit);
}

View file

@ -180,9 +180,18 @@ public class SensitivityWeightedAveragePlugin extends PluginBase implements Sens
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7")));
ratio = Math.min(ratio, SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
//If not-excluded data <= MIN_HOURS -> don't do Autosens
//If not-excluded data >= MIN_HOURS_FULL_AUTOSENS -> full Autosens
//Between MIN_HOURS and MIN_HOURS_FULL_AUTOSENS: gradually increase autosens
double autosensContrib = (Math.min(Math.max(MIN_HOURS, data.size() / 12d), MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS);
ratio = autosensContrib * (ratio - 1) + 1;
if (autosensContrib != 1d) {
ratioLimit += "(" + data.size() + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) ";
}
if (ratio != rawRatio) {
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
if (Config.logAutosensData)
ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio;
log.debug(ratioLimit);
}