show autosens result

This commit is contained in:
Milos Kozak 2017-01-18 21:40:43 +01:00
parent ba370b3cf3
commit 8586ed5adb
4 changed files with 45 additions and 13 deletions

View file

@ -76,7 +76,7 @@ public class Autosens {
double[] bgis = new double[bucketed_data.size() - 2]; double[] bgis = new double[bucketed_data.size() - 2];
double[] deviations = new double[bucketed_data.size() - 2]; double[] deviations = new double[bucketed_data.size() - 2];
String debugString = ""; String pastSensitivity = "";
for (int i = 0; i < bucketed_data.size() - 3; ++i) { for (int i = 0; i < bucketed_data.size() - 3; ++i) {
long bgTime = bucketed_data.get(i).timeIndex; long bgTime = bucketed_data.get(i).timeIndex;
int secondsFromMidnight = NSProfile.secondsFromMidnight(new Date(bgTime)); int secondsFromMidnight = NSProfile.secondsFromMidnight(new Date(bgTime));
@ -108,18 +108,18 @@ public class Autosens {
// Exclude large positive deviations (carb absorption) from autosens // Exclude large positive deviations (carb absorption) from autosens
if (avgDelta - bgi < 6) { if (avgDelta - bgi < 6) {
if (deviation > 0) { if (deviation > 0) {
debugString += "+"; pastSensitivity += "+";
} else if (deviation == 0) { } else if (deviation == 0) {
debugString += "="; pastSensitivity += "=";
} else { } else {
debugString += "-"; pastSensitivity += "-";
} }
avgDeltas[i] = avgDelta; avgDeltas[i] = avgDelta;
bgis[i] = bgi; bgis[i] = bgi;
deviations[i] = deviation; deviations[i] = deviation;
deviationSum += deviation; deviationSum += deviation;
} else { } else {
debugString += ">"; pastSensitivity += ">";
//console.error(bgTime); //console.error(bgTime);
} }
@ -134,7 +134,7 @@ public class Autosens {
} }
} }
//console.error(""); //console.error("");
log.debug(debugString); log.debug(pastSensitivity);
//console.log(JSON.stringify(avgDeltas)); //console.log(JSON.stringify(avgDeltas));
//console.log(JSON.stringify(bgis)); //console.log(JSON.stringify(bgis));
Arrays.sort(avgDeltas); Arrays.sort(avgDeltas);
@ -157,15 +157,17 @@ 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());
log.debug("Excess insulin sensitivity detected: "); sensResult = "Excess insulin sensitivity detected";
} else if (pResistant > 0) { // resistant } else if (pResistant > 0) { // resistant
basalOff = pResistant * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()); basalOff = pResistant * (60 / 5) / NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits());
log.debug("Excess insulin resistance detected: "); sensResult = "Excess insulin resistance detected";
} else { } else {
log.debug("Sensitivity normal."); sensResult = "Sensitivity normal";
} }
log.debug(sensResult);
double ratio = 1 + (basalOff / profile.getMaxDailyBasal()); double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
// don't adjust more than 1.5x // don't adjust more than 1.5x
@ -173,8 +175,10 @@ public class Autosens {
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) {
log.debug("Ratio limited from " + rawRatio + " to " + ratio); ratioLimit = "Ratio limited from " + rawRatio + " to " + ratio;
log.debug(ratioLimit);
} }
double newisf = Math.round(NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()) / ratio); double newisf = Math.round(NSProfile.toMgdl(profile.getIsf(NSProfile.secondsFromMidnight()), profile.getUnits()) / ratio);
@ -187,6 +191,9 @@ public class Autosens {
AutosensResult output = new AutosensResult(); AutosensResult output = new AutosensResult();
output.ratio = Round.roundTo(ratio, 0.01); output.ratio = Round.roundTo(ratio, 0.01);
output.carbsAbsorbed = Round.roundTo(carbsAbsorbed, 0.01); output.carbsAbsorbed = Round.roundTo(carbsAbsorbed, 0.01);
output.pastSensitivity = pastSensitivity;
output.ratioLimit = ratioLimit;
output.sensResult = sensResult;
return output; return output;
} }

View file

@ -1,9 +1,31 @@
package info.nightscout.androidaps.plugins.OpenAPSAMA; package info.nightscout.androidaps.plugins.OpenAPSAMA;
import org.json.JSONException;
import org.json.JSONObject;
/** /**
* Created by mike on 06.01.2017. * Created by mike on 06.01.2017.
*/ */
public class AutosensResult { public class AutosensResult {
public double ratio; public double ratio;
public double carbsAbsorbed; public double carbsAbsorbed;
public String sensResult;
public String pastSensitivity;
public String ratioLimit;
public JSONObject json() {
JSONObject ret = new JSONObject();
try {
ret.put("ratio", ratio);
ret.put("ratioLimit", ratioLimit);
ret.put("carbsAbsorbed", carbsAbsorbed);
ret.put("pastSensitivity", pastSensitivity);
ret.put("sensResult", sensResult);
ret.put("ratio", ratio);
} catch (JSONException e) {
e.printStackTrace();
}
return ret;
}
} }

View file

@ -125,12 +125,14 @@ public class OpenAPSAMAFragment extends Fragment implements View.OnClickListener
} }
profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam())); profileView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getProfileParam()));
mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam())); mealDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getMealDataParam()));
autosensDataView.setText(JSONFormatter.format(determineBasalAdapterAMAJS.getAutosensDataParam()));
scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug()); scriptdebugView.setText(determineBasalAdapterAMAJS.getScriptDebug());
} }
if (getPlugin().lastAPSRun != null) { if (getPlugin().lastAPSRun != null) {
lastRunView.setText(getPlugin().lastAPSRun.toLocaleString()); lastRunView.setText(getPlugin().lastAPSRun.toLocaleString());
} }
if (getPlugin().lastAutosensResult != null) {
autosensDataView.setText(JSONFormatter.format(getPlugin().lastAutosensResult.json()));
}
} }
}); });
} }

View file

@ -45,6 +45,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null; DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
Date lastAPSRun = null; Date lastAPSRun = null;
DetermineBasalResultAMA lastAPSResult = null; DetermineBasalResultAMA lastAPSResult = null;
AutosensResult lastAutosensResult = null;
boolean fragmentEnabled = false; boolean fragmentEnabled = false;
boolean fragmentVisible = true; boolean fragmentVisible = true;
@ -202,10 +203,10 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTempBasals().oldestDataAvaialable(); long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTempBasals().oldestDataAvaialable();
List<BgReading> bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia()))), false); List<BgReading> bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia()))), false);
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)");
AutosensResult autosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime()); lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(bgReadings, new Date().getTime());
determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData, determineBasalAdapterAMAJS.setData(profile, maxIob, maxBasal, minBg, maxBg, targetBg, pump, iobArray, glucoseStatus, mealData,
autosensResult.ratio, //autosensDataRatio lastAutosensResult.ratio, //autosensDataRatio
isTempTarget, isTempTarget,
Constants.MIN_5M_CARBIMPACT //min_5m_carbimpact Constants.MIN_5M_CARBIMPACT //min_5m_carbimpact
); );