calculate only needed data in AMA
This commit is contained in:
parent
9722130299
commit
1b2500dc6c
2 changed files with 54 additions and 49 deletions
|
@ -19,7 +19,7 @@ import info.nightscout.utils.Round;
|
||||||
public class Autosens {
|
public class Autosens {
|
||||||
private static Logger log = LoggerFactory.getLogger(Autosens.class);
|
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();
|
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);
|
//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 is more recent than mealTime
|
||||||
if (bgTime > mealTime) {
|
if (mealTime != null && bgTime > mealTime) {
|
||||||
// figure out how many carbs that represents
|
// figure out how many carbs that represents
|
||||||
// but always assume at least 3mg/dL/5m (default) absorption
|
// but always assume at least 3mg/dL/5m (default) absorption
|
||||||
double ci = Math.max(deviation, Constants.MIN_5M_CARBIMPACT);
|
double ci = Math.max(deviation, Constants.MIN_5M_CARBIMPACT);
|
||||||
|
@ -134,6 +134,12 @@ public class Autosens {
|
||||||
carbsAbsorbed += absorbed;
|
carbsAbsorbed += absorbed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double ratio = 1;
|
||||||
|
String ratioLimit = "";
|
||||||
|
String sensResult = "";
|
||||||
|
|
||||||
|
if (mealTime == null) {
|
||||||
//console.error("");
|
//console.error("");
|
||||||
log.debug(pastSensitivity);
|
log.debug(pastSensitivity);
|
||||||
//console.log(JSON.stringify(avgDeltas));
|
//console.log(JSON.stringify(avgDeltas));
|
||||||
|
@ -158,7 +164,6 @@ public class Autosens {
|
||||||
//console.error("Mean deviation: "+average.toFixed(2));
|
//console.error("Mean deviation: "+average.toFixed(2));
|
||||||
double basalOff = 0;
|
double basalOff = 0;
|
||||||
|
|
||||||
String sensResult = "";
|
|
||||||
if (pSensitive < 0) { // sensitive
|
if (pSensitive < 0) { // sensitive
|
||||||
basalOff = pSensitive * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits());
|
basalOff = pSensitive * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits());
|
||||||
sensResult = "Excess insulin sensitivity detected";
|
sensResult = "Excess insulin sensitivity detected";
|
||||||
|
@ -169,14 +174,13 @@ public class Autosens {
|
||||||
sensResult = "Sensitivity normal";
|
sensResult = "Sensitivity normal";
|
||||||
}
|
}
|
||||||
log.debug(sensResult);
|
log.debug(sensResult);
|
||||||
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
||||||
|
|
||||||
// don't adjust more than 1.5x
|
// don't adjust more than 1.5x
|
||||||
double rawRatio = ratio;
|
double rawRatio = ratio;
|
||||||
ratio = Math.max(ratio, Constants.AUTOSENS_MIN);
|
ratio = Math.max(ratio, Constants.AUTOSENS_MIN);
|
||||||
ratio = Math.min(ratio, Constants.AUTOSENS_MAX);
|
ratio = Math.min(ratio, Constants.AUTOSENS_MAX);
|
||||||
|
|
||||||
String ratioLimit = "";
|
|
||||||
if (ratio != rawRatio) {
|
if (ratio != rawRatio) {
|
||||||
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
|
ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
|
||||||
log.debug(ratioLimit);
|
log.debug(ratioLimit);
|
||||||
|
@ -188,6 +192,7 @@ public class Autosens {
|
||||||
}
|
}
|
||||||
//console.error("Basal adjustment "+basalOff.toFixed(2)+"U/hr");
|
//console.error("Basal adjustment "+basalOff.toFixed(2)+"U/hr");
|
||||||
//console.error("Ratio: "+ratio*100+"%: new ISF: "+newisf.toFixed(1)+"mg/dL/U");
|
//console.error("Ratio: "+ratio*100+"%: new ISF: "+newisf.toFixed(1)+"mg/dL/U");
|
||||||
|
}
|
||||||
|
|
||||||
AutosensResult output = new AutosensResult();
|
AutosensResult output = new AutosensResult();
|
||||||
output.ratio = Round.roundTo(ratio, 0.01);
|
output.ratio = Round.roundTo(ratio, 0.01);
|
||||||
|
|
|
@ -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)");
|
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString() + " (" + bgReadings.size() + " records)");
|
||||||
|
|
||||||
if(MainApp.getConfigBuilder().isAMAModeEnabled()){
|
if(MainApp.getConfigBuilder().isAMAModeEnabled()){
|
||||||
lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime());
|
lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, null);
|
||||||
} else {
|
} else {
|
||||||
lastAutosensResult = new AutosensResult();
|
lastAutosensResult = new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue