Move Algo to abstract class
This commit is contained in:
parent
faca79d13e
commit
07f7c00d85
7 changed files with 84 additions and 47 deletions
|
@ -20,50 +20,9 @@ import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
public interface SensitivityInterface {
|
public interface SensitivityInterface {
|
||||||
|
|
||||||
Logger LOG = LoggerFactory.getLogger(SensitivityInterface.class);
|
|
||||||
|
|
||||||
double MIN_HOURS = 1;
|
double MIN_HOURS = 1;
|
||||||
double MIN_HOURS_FULL_AUTOSENS = 4;
|
double MIN_HOURS_FULL_AUTOSENS = 4;
|
||||||
|
|
||||||
AutosensResult detectSensitivity(long fromTime, long toTime);
|
AutosensResult detectSensitivity(long fromTime, long toTime);
|
||||||
|
|
||||||
default AutosensResult fillResult(double ratio, double carbsAbsorbed, String pastSensitivity,
|
|
||||||
String ratioLimit, String sensResult, int deviationsArraySize) {
|
|
||||||
return this.fillResult(ratio, carbsAbsorbed, pastSensitivity, ratioLimit, sensResult,
|
|
||||||
deviationsArraySize,
|
|
||||||
SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7")),
|
|
||||||
SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
|
|
||||||
}
|
|
||||||
|
|
||||||
default AutosensResult fillResult(double ratio, double carbsAbsorbed, String pastSensitivity,
|
|
||||||
String ratioLimit, String sensResult, int deviationsArraySize,
|
|
||||||
double ratioMin, double ratioMax) {
|
|
||||||
double rawRatio = ratio;
|
|
||||||
ratio = Math.max(ratio, ratioMin);
|
|
||||||
ratio = Math.min(ratio, ratioMax);
|
|
||||||
|
|
||||||
//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, deviationsArraySize / 12d),
|
|
||||||
MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS);
|
|
||||||
ratio = autosensContrib * (ratio - 1) + 1;
|
|
||||||
|
|
||||||
if (autosensContrib != 1d) {
|
|
||||||
ratioLimit += "(" + deviationsArraySize + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) ";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ratio != rawRatio) {
|
|
||||||
ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio;
|
|
||||||
LOG.debug(ratioLimit);
|
|
||||||
}
|
|
||||||
|
|
||||||
AutosensResult output = new AutosensResult();
|
|
||||||
output.ratio = Round.roundTo(ratio, 0.01);
|
|
||||||
output.carbsAbsorbed = Round.roundTo(carbsAbsorbed, 0.01);
|
|
||||||
output.pastSensitivity = pastSensitivity;
|
|
||||||
output.ratioLimit = ratioLimit;
|
|
||||||
output.sensResult = sensResult;
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
package info.nightscout.androidaps.plugins.Sensitivity;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||||
|
import info.nightscout.utils.Round;
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
import info.nightscout.utils.SafeParse;
|
||||||
|
|
||||||
|
public abstract class AbstractSensitivityPlugin extends PluginBase implements SensitivityInterface {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(SensitivityInterface.class);
|
||||||
|
|
||||||
|
public AbstractSensitivityPlugin(PluginDescription pluginDescription) {
|
||||||
|
super(pluginDescription);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract AutosensResult detectSensitivity(long fromTime, long toTime);
|
||||||
|
|
||||||
|
public AutosensResult fillResult(double ratio, double carbsAbsorbed, String pastSensitivity,
|
||||||
|
String ratioLimit, String sensResult, int deviationsArraySize) {
|
||||||
|
return this.fillResult(ratio, carbsAbsorbed, pastSensitivity, ratioLimit, sensResult,
|
||||||
|
deviationsArraySize,
|
||||||
|
SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_min, "0.7")),
|
||||||
|
SafeParse.stringToDouble(SP.getString(R.string.key_openapsama_autosens_max, "1.2")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public AutosensResult fillResult(double ratio, double carbsAbsorbed, String pastSensitivity,
|
||||||
|
String ratioLimit, String sensResult, int deviationsArraySize,
|
||||||
|
double ratioMin, double ratioMax) {
|
||||||
|
double rawRatio = ratio;
|
||||||
|
ratio = Math.max(ratio, ratioMin);
|
||||||
|
ratio = Math.min(ratio, ratioMax);
|
||||||
|
|
||||||
|
//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, deviationsArraySize / 12d),
|
||||||
|
MIN_HOURS_FULL_AUTOSENS) - MIN_HOURS) / (MIN_HOURS_FULL_AUTOSENS - MIN_HOURS);
|
||||||
|
ratio = autosensContrib * (ratio - 1) + 1;
|
||||||
|
|
||||||
|
if (autosensContrib != 1d) {
|
||||||
|
ratioLimit += "(" + deviationsArraySize + " of " + MIN_HOURS_FULL_AUTOSENS * 12 + " values) ";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ratio != rawRatio) {
|
||||||
|
ratioLimit += "Ratio limited from " + rawRatio + " to " + ratio;
|
||||||
|
log.debug(ratioLimit);
|
||||||
|
}
|
||||||
|
|
||||||
|
AutosensResult output = new AutosensResult();
|
||||||
|
output.ratio = Round.roundTo(ratio, 0.01);
|
||||||
|
output.carbsAbsorbed = Round.roundTo(carbsAbsorbed, 0.01);
|
||||||
|
output.pastSensitivity = pastSensitivity;
|
||||||
|
output.ratioLimit = ratioLimit;
|
||||||
|
output.sensResult = sensResult;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ import info.nightscout.utils.SafeParse;
|
||||||
* Created by mike on 24.06.2017.
|
* Created by mike on 24.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SensitivityAAPSPlugin extends PluginBase implements SensitivityInterface {
|
public class SensitivityAAPSPlugin extends AbstractSensitivityPlugin {
|
||||||
private static Logger log = LoggerFactory.getLogger(SensitivityAAPSPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(SensitivityAAPSPlugin.class);
|
||||||
|
|
||||||
static SensitivityAAPSPlugin plugin = null;
|
static SensitivityAAPSPlugin plugin = null;
|
||||||
|
|
|
@ -30,7 +30,7 @@ import info.nightscout.utils.SafeParse;
|
||||||
* Created by mike on 24.06.2017.
|
* Created by mike on 24.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SensitivityOref0Plugin extends PluginBase implements SensitivityInterface {
|
public class SensitivityOref0Plugin extends AbstractSensitivityPlugin {
|
||||||
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
|
||||||
|
|
||||||
static SensitivityOref0Plugin plugin = null;
|
static SensitivityOref0Plugin plugin = null;
|
||||||
|
|
|
@ -30,7 +30,7 @@ import info.nightscout.utils.SafeParse;
|
||||||
* Created by mike on 19.06.2018.
|
* Created by mike on 19.06.2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SensitivityOref1Plugin extends PluginBase implements SensitivityInterface {
|
public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
|
||||||
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(IobCobCalculatorPlugin.class);
|
||||||
|
|
||||||
static SensitivityOref1Plugin plugin = null;
|
static SensitivityOref1Plugin plugin = null;
|
||||||
|
|
|
@ -28,7 +28,7 @@ import info.nightscout.utils.SafeParse;
|
||||||
* Created by mike on 24.06.2017.
|
* Created by mike on 24.06.2017.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class SensitivityWeightedAveragePlugin extends PluginBase implements SensitivityInterface {
|
public class SensitivityWeightedAveragePlugin extends AbstractSensitivityPlugin {
|
||||||
private static Logger log = LoggerFactory.getLogger(SensitivityWeightedAveragePlugin.class);
|
private static Logger log = LoggerFactory.getLogger(SensitivityWeightedAveragePlugin.class);
|
||||||
|
|
||||||
private static SensitivityWeightedAveragePlugin plugin = null;
|
private static SensitivityWeightedAveragePlugin plugin = null;
|
||||||
|
|
|
@ -2,14 +2,24 @@ package info.nightscout.androidaps.plugins.Sensitivity;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||||
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
import info.nightscout.androidaps.interfaces.SensitivityInterface;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensResult;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class SensitivityInterfaceTest {
|
public class AbstractSensitivityPluginTest {
|
||||||
|
|
||||||
|
private class SensitivityTestClass extends AbstractSensitivityPlugin {
|
||||||
|
|
||||||
|
public SensitivityTestClass() {
|
||||||
|
super(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SensitivityTestClass(PluginDescription pluginDescription) {
|
||||||
|
super(pluginDescription);
|
||||||
|
}
|
||||||
|
|
||||||
private class SensitivityTestClass implements SensitivityInterface {
|
|
||||||
@Override
|
@Override
|
||||||
public AutosensResult detectSensitivity(long fromTime, long toTime) {
|
public AutosensResult detectSensitivity(long fromTime, long toTime) {
|
||||||
return null;
|
return null;
|
Loading…
Reference in a new issue