calculate only needed data in AMA

This commit is contained in:
Milos Kozak 2017-01-31 09:40:05 +01:00
parent 9722130299
commit 1b2500dc6c
2 changed files with 54 additions and 49 deletions

View file

@ -19,7 +19,7 @@ import info.nightscout.utils.Round;
public class Autosens {
private static Logger log = LoggerFactory.getLogger(Autosens.class);
public static AutosensResult detectSensitivityandCarbAbsorption(List<BgReading> glucose_data, long mealTime) {
public static AutosensResult detectSensitivityandCarbAbsorption(List<BgReading> glucose_data, Long mealTime) {
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
@ -125,7 +125,7 @@ public class Autosens {
//log.debug("TIME: " + new Date(bgTime).toString() + " BG: " + bg + " SENS: " + sens + " DELTA: " + delta + " AVGDELTA: " + avgDelta + " IOB: " + iob.iob + " ACTIVITY: " + iob.activity + " BGI: " + bgi + " DEVIATION: " + deviation);
// if bgTime is more recent than mealTime
if (bgTime > mealTime) {
if (mealTime != null && bgTime > mealTime) {
// figure out how many carbs that represents
// but always assume at least 3mg/dL/5m (default) absorption
double ci = Math.max(deviation, Constants.MIN_5M_CARBIMPACT);
@ -134,6 +134,12 @@ public class Autosens {
carbsAbsorbed += absorbed;
}
}
double ratio = 1;
String ratioLimit = "";
String sensResult = "";
if (mealTime == null) {
//console.error("");
log.debug(pastSensitivity);
//console.log(JSON.stringify(avgDeltas));
@ -158,7 +164,6 @@ public class Autosens {
//console.error("Mean deviation: "+average.toFixed(2));
double basalOff = 0;
String sensResult = "";
if (pSensitive < 0) { // sensitive
basalOff = pSensitive * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits());
sensResult = "Excess insulin sensitivity detected";
@ -169,14 +174,13 @@ public class Autosens {
sensResult = "Sensitivity normal";
}
log.debug(sensResult);
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
ratio = 1 + (basalOff / profile.getMaxDailyBasal());
// don't adjust more than 1.5x
double rawRatio = ratio;
ratio = Math.max(ratio, Constants.AUTOSENS_MIN);
ratio = Math.min(ratio, Constants.AUTOSENS_MAX);
String ratioLimit = "";
if (ratio != rawRatio) {
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
log.debug(ratioLimit);
@ -188,6 +192,7 @@ public class Autosens {
}
//console.error("Basal adjustment "+basalOff.toFixed(2)+"U/hr");
//console.error("Ratio: "+ratio*100+"%: new ISF: "+newisf.toFixed(1)+"mg/dL/U");
}
AutosensResult output = new AutosensResult();
output.ratio = Round.roundTo(ratio, 0.01);

View file

@ -217,7 +217,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString() + " (" + bgReadings.size() + " records)");
if(MainApp.getConfigBuilder().isAMAModeEnabled()){
lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime());
lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, null);
} else {
lastAutosensResult = new AutosensResult();
}