Update to use 24 and 8 hours worth of sensitivity
This commit is contained in:
parent
1b4d06101d
commit
6c70fd3a06
1 changed files with 117 additions and 76 deletions
|
@ -79,8 +79,17 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
|
|||
List<CareportalEvent> siteChanges = MainApp.getDbHelper().getCareportalEventsFromTime(fromTime, CareportalEvent.SITECHANGE, true);
|
||||
List<ProfileSwitch> profileSwitches = MainApp.getDbHelper().getProfileSwitchEventsFromTime(fromTime, true);
|
||||
|
||||
List<Double> deviationsArray = new ArrayList<>();
|
||||
String pastSensitivity = "";
|
||||
//[0] = 8 hour
|
||||
//[1] = 24 hour
|
||||
//Deviationshour has DeviationsArray
|
||||
List<ArrayList> deviationshour = Arrays.asList(new ArrayList(),new ArrayList());
|
||||
List<String> pastSensitivityArray = Arrays.asList("","");
|
||||
List<String> sensResultArray = Arrays.asList("","");
|
||||
List<Double> ratioArray = Arrays.asList(0d,0d);
|
||||
List<String> ratioLimitArray = Arrays.asList("","");
|
||||
List<Double> hoursDetection = Arrays.asList(8d,24d);
|
||||
|
||||
|
||||
int index = 0;
|
||||
while (index < autosensDataTable.size()) {
|
||||
AutosensData autosensData = autosensDataTable.valueAt(index);
|
||||
|
@ -94,6 +103,12 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
|
|||
index++;
|
||||
continue;
|
||||
}
|
||||
int hoursegment = 0;
|
||||
//hoursegment = 0 = 8 hour
|
||||
//hoursegment = 1 = 24 hour
|
||||
while (hoursegment < deviationshour.size()){
|
||||
ArrayList deviationsArray = deviationshour.get(hoursegment);
|
||||
String pastSensitivity = pastSensitivityArray.get(hoursegment);
|
||||
|
||||
// reset deviations after site change
|
||||
if (CareportalEvent.isEvent5minBack(siteChanges, autosensData.time)) {
|
||||
|
@ -114,85 +129,111 @@ public class SensitivityOref1Plugin extends AbstractSensitivityPlugin {
|
|||
deviation = 0;
|
||||
|
||||
if (autosensData.validDeviation)
|
||||
if (autosensData.time > toTime - hoursDetection.get(hoursegment) * 60 * 60 * 1000L)
|
||||
deviationsArray.add(deviation);
|
||||
|
||||
if (hoursegment == 0) {
|
||||
for (int i = 0; i < autosensData.extraDeviation.size(); i++)
|
||||
deviationsArray.add(autosensData.extraDeviation.get(i));
|
||||
if (deviationsArray.size() > 96)
|
||||
}
|
||||
if (deviationsArray.size() > hoursDetection.get(hoursegment) * 60 / 5){
|
||||
deviationsArray.remove(0);
|
||||
}
|
||||
|
||||
pastSensitivity += autosensData.pastSensitivity;
|
||||
int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time);
|
||||
|
||||
if (secondsFromMidnight % 3600 < 2.5 * 60 || secondsFromMidnight % 3600 > 57.5 * 60) {
|
||||
pastSensitivity += "(" + Math.round(secondsFromMidnight / 3600d) + ")";
|
||||
}
|
||||
|
||||
//Update the data back to the parent
|
||||
deviationshour.set(hoursegment,deviationsArray);
|
||||
pastSensitivityArray.set(hoursegment,pastSensitivity);
|
||||
hoursegment++;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
|
||||
// when we have less than 8h worth of deviation data, add up to 90m of zero deviations
|
||||
// this dampens any large sensitivity changes detected based on too little data, without ignoring them completely
|
||||
// only apply for 8 hours of devations
|
||||
ArrayList dev8h = deviationshour.get(0);
|
||||
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Using most recent " + deviationsArray.size() + " deviations");
|
||||
if (deviationsArray.size() < 96) {
|
||||
int pad = (int) Math.round((1 - (double) deviationsArray.size() / 96) * 18);
|
||||
log.debug("Using most recent " + dev8h.size() + " deviations");
|
||||
if (dev8h.size() < 96) {
|
||||
int pad = (int) Math.round((1 - (double) dev8h.size() / 96) * 18);
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Adding " + pad + " more zero deviations");
|
||||
for (int d = 0; d < pad; d++) {
|
||||
//process.stderr.write(".");
|
||||
deviationsArray.add(0d);
|
||||
for (int d = 0; d < pad; d++) { ;
|
||||
dev8h.add(0d);
|
||||
}
|
||||
}
|
||||
//Update the data back to the parent
|
||||
deviationshour.set(0,dev8h);
|
||||
|
||||
int hourused = 0;
|
||||
while (hourused < deviationshour.size()){
|
||||
ArrayList deviationsArray = deviationshour.get(hourused);
|
||||
String pastSensitivity = pastSensitivityArray.get(hourused);
|
||||
String sensResult = "(8 hours) ";
|
||||
String senstime = sensResult;
|
||||
if (hourused == 1){
|
||||
senstime = "(24 hours) ";
|
||||
sensResult = senstime;
|
||||
}
|
||||
String ratioLimit = "";
|
||||
|
||||
Double[] deviations = new Double[deviationsArray.size()];
|
||||
deviations = deviationsArray.toArray(deviations);
|
||||
deviations = (Double[]) deviationsArray.toArray(deviations);
|
||||
|
||||
double sens = profile.getIsfMgdl();
|
||||
|
||||
double ratio = 1;
|
||||
String ratioLimit = "";
|
||||
String sensResult = "";
|
||||
double sens = profile.getIsf();
|
||||
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Records: " + index + " " + pastSensitivity);
|
||||
log.debug(senstime + "Records: " + index + " " + pastSensitivity);
|
||||
|
||||
Arrays.sort(deviations);
|
||||
/* Not used in calculation
|
||||
for (double i = 0.9; i > 0.1; i = i - 0.01) {
|
||||
if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.01)) >= 0 && IobCobCalculatorPlugin.percentile(deviations, i) < 0) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug(Math.round(100 * i) + "% of non-meal deviations negative (>50% = sensitivity)");
|
||||
}
|
||||
if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.01)) > 0 && IobCobCalculatorPlugin.percentile(deviations, i) <= 0) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug(Math.round(100 * i) + "% of non-meal deviations positive (>50% = resistance)");
|
||||
}
|
||||
}
|
||||
*/
|
||||
double pSensitive = IobCobCalculatorPlugin.percentile(deviations, 0.50);
|
||||
double pResistant = IobCobCalculatorPlugin.percentile(deviations, 0.50);
|
||||
|
||||
double basalOff = 0;
|
||||
|
||||
if (pSensitive < 0) { // sensitive
|
||||
basalOff = pSensitive * (60 / 5.0) / sens;
|
||||
sensResult = "Excess insulin sensitivity detected";
|
||||
basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
||||
sensResult+= "Excess insulin sensitivity detected";
|
||||
} else if (pResistant > 0) { // resistant
|
||||
basalOff = pResistant * (60 / 5.0) / sens;
|
||||
sensResult = "Excess insulin resistance detected";
|
||||
basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
||||
sensResult+= "Excess insulin resistance detected";
|
||||
} else {
|
||||
sensResult = "Sensitivity normal";
|
||||
sensResult+= "Sensitivity normal";
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug(sensResult);
|
||||
|
||||
ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
||||
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
||||
|
||||
AutosensResult output = fillResult(ratio, current.cob, pastSensitivity, ratioLimit,
|
||||
sensResult, deviationsArray.size());
|
||||
//Update the data back to the parent
|
||||
sensResultArray.set(hourused,sensResult);
|
||||
ratioArray.set(hourused,ratio);
|
||||
ratioLimitArray.set(hourused,ratioLimit);
|
||||
hourused++;
|
||||
}
|
||||
|
||||
int key = 1;
|
||||
String comparison = " 8 h ratio " +ratioArray.get(0)+" vs 24h ratio "+ratioArray.get(1);
|
||||
//use 24 hour ratio by default
|
||||
//if the 8 hour ratio is less than the 24 hour ratio, the 8 hour ratio is used
|
||||
if(ratioArray.get(0) < ratioArray.get(1)){
|
||||
key = 0;
|
||||
}
|
||||
String message = hoursDetection.get(key)+" of sensitivity used";
|
||||
AutosensResult output = fillResult(ratioArray.get(key), current.cob, pastSensitivityArray.get(key), ratioLimitArray.get(key),
|
||||
sensResultArray.get(key)+comparison, deviationshour.get(key).size());
|
||||
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Sensitivity to: {} ratio: {} mealCOB: {}",
|
||||
log.debug(message+" Sensitivity to: {} ratio: {} mealCOB: {}",
|
||||
new Date(toTime).toLocaleString(), output.ratio, current.cob);
|
||||
|
||||
return output;
|
||||
|
|
Loading…
Reference in a new issue