minDeviationSlope 1st try
This commit is contained in:
parent
c36587430c
commit
a097bf51aa
|
@ -56,13 +56,14 @@ public class AutosensData {
|
||||||
public double cob = 0;
|
public double cob = 0;
|
||||||
public double bgi = 0d;
|
public double bgi = 0d;
|
||||||
public double delta = 0d;
|
public double delta = 0d;
|
||||||
|
public double avgDelta = 0d;
|
||||||
|
public double avgDeviation = 0d;
|
||||||
|
|
||||||
public double autosensRatio = 1d;
|
public double autosensRatio = 1d;
|
||||||
|
|
||||||
public double minDeviationSlope;
|
public double minDeviationSlope;
|
||||||
|
|
||||||
public String log(long time) {
|
public String log(long time) {
|
||||||
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio;
|
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " avgDelta=" + avgDelta + " Bgi=" + bgi + " Deviation=" + deviation + " avgDeviation=" + avgDeviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio + " minDeviationSlope=" + minDeviationSlope;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int minOld() {
|
public int minOld() {
|
||||||
|
|
|
@ -354,10 +354,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
log.debug("Prev data time: " + new Date(prevDataTime).toLocaleString());
|
log.debug("Prev data time: " + new Date(prevDataTime).toLocaleString());
|
||||||
AutosensData previous = autosensDataTable.get(prevDataTime);
|
AutosensData previous = autosensDataTable.get(prevDataTime);
|
||||||
|
|
||||||
double currentDeviation = 0;
|
|
||||||
double minDeviationSlope = 0;
|
|
||||||
double maxDeviation = 0;
|
|
||||||
|
|
||||||
// start from oldest to be able sub cob
|
// start from oldest to be able sub cob
|
||||||
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
|
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
|
||||||
// check if data already exists
|
// check if data already exists
|
||||||
|
@ -381,49 +377,43 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
autosensData.activeCarbsList = new ArrayList<>();
|
autosensData.activeCarbsList = new ArrayList<>();
|
||||||
|
|
||||||
//console.error(bgTime , bucketed_data[i].glucose);
|
//console.error(bgTime , bucketed_data[i].glucose);
|
||||||
double bg;
|
|
||||||
double avgDelta;
|
|
||||||
double delta;
|
|
||||||
|
|
||||||
bg = bucketed_data.get(i).value;
|
double bg = bucketed_data.get(i).value;
|
||||||
if (bg < 39 || bucketed_data.get(i + 3).value < 39) {
|
if (bg < 39 || bucketed_data.get(i + 3).value < 39) {
|
||||||
log.error("! value < 39");
|
log.error("! value < 39");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
avgDelta = (bg - bucketed_data.get(i + 3).value) / 3;
|
double avgDelta = (bg - bucketed_data.get(i + 3).value) / 3;
|
||||||
delta = (bg - bucketed_data.get(i + 1).value);
|
double delta = (bg - bucketed_data.get(i + 1).value);
|
||||||
|
|
||||||
IobTotal iob = calculateFromTreatmentsAndTemps(bgTime);
|
IobTotal iob = calculateFromTreatmentsAndTemps(bgTime);
|
||||||
|
|
||||||
double bgi = -iob.activity * sens * 5;
|
double bgi = -iob.activity * sens * 5;
|
||||||
double deviation = delta - bgi;
|
double deviation = delta - bgi;
|
||||||
|
double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000;
|
||||||
|
|
||||||
/*
|
double currentDeviation;
|
||||||
TODO: SMB: i don't undestand this part
|
double minDeviationSlope = 0;
|
||||||
long ciTime = System.currentTimeMillis();
|
double maxDeviation = 0;
|
||||||
|
|
||||||
if (i == bucketed_data.size() - 4) {
|
// https://github.com/openaps/oref0/blob/master/lib/determine-basal/cob-autosens.js#L169
|
||||||
currentDeviation = Math.round((avgDelta - bgi) * 1000) / 1000;
|
if (i < bucketed_data.size() - 16) { // we need 1h of data to calculate minDeviationSlope
|
||||||
} else if (ciTime > bgTime) {
|
long hourago = bgTime + 10 * 1000 - 60 * 60 * 1000L;
|
||||||
double avgDeviation = Math.round((avgDelta - bgi) * 1000) / 1000;
|
AutosensData hourAgoData = getAutosensData(hourago);
|
||||||
double deviationSlope = (avgDeviation - currentDeviation) / (bgTime - ciTime) * 1000 * 60 * 5;
|
currentDeviation = hourAgoData.avgDeviation;
|
||||||
if (avgDeviation > maxDeviation) {
|
int initialIndex = autosensDataTable.indexOfKey(hourAgoData.time);
|
||||||
minDeviationSlope = Math.min(0, deviationSlope);
|
|
||||||
maxDeviation = avgDeviation;
|
for (int past = 1; past < 12; past++) {
|
||||||
|
AutosensData ad = autosensDataTable.valueAt(initialIndex + past);
|
||||||
|
double deviationSlope = (ad.avgDeviation - currentDeviation) / (ad.time - bgTime) * 1000 * 60 * 5;
|
||||||
|
if (ad.avgDeviation > maxDeviation) {
|
||||||
|
minDeviationSlope = Math.min(0, deviationSlope);
|
||||||
|
maxDeviation = ad.avgDeviation;
|
||||||
|
}
|
||||||
|
log.debug("Deviations: " + new Date(bgTime) + new Date(ad.time) + " avgDeviation=" + avgDeviation + " deviationSlope=" + deviationSlope + " minDeviationSlope=" + minDeviationSlope);
|
||||||
}
|
}
|
||||||
//console.error("Deviations:",bgTime, avgDeviation, deviationSlope, minDeviationSlope);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
https://github.com/openaps/oref0/blob/master/lib/determine-basal/cob-autosens.js#L169
|
|
||||||
|
|
||||||
Scott's comment
|
|
||||||
that stuff is used in UAM (unannounced meal) mode. what we're doing there is calculating the currentDeviation (how fast carbs are absorbing right now), and comparing that to the highest deviation we've seen in the last 45m to calculate the deviationSlope: the rate at which deviations are currently decreasing. We then project deviations to continue into the future starting at the currentDeviation rate and declining at deviationSlope until it gets back down to zero
|
|
||||||
that gives us an independent way to estimate how long deviations (likely carb absorption) will continue, even if we don't have (or don't want to fully trust) the user's carb estimate
|
|
||||||
the complexity comes from reusing the same COB calculation code to calculate both current and historical carb absorption rates
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
List<Treatment> recentTreatments = MainApp.getConfigBuilder().getTreatments5MinBackFromHistory(bgTime);
|
List<Treatment> recentTreatments = MainApp.getConfigBuilder().getTreatments5MinBackFromHistory(bgTime);
|
||||||
for (int ir = 0; ir < recentTreatments.size(); ir++) {
|
for (int ir = 0; ir < recentTreatments.size(); ir++) {
|
||||||
autosensData.carbsFromBolus += recentTreatments.get(ir).carbs;
|
autosensData.carbsFromBolus += recentTreatments.get(ir).carbs;
|
||||||
|
@ -453,6 +443,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
autosensData.deviation = deviation;
|
autosensData.deviation = deviation;
|
||||||
autosensData.bgi = bgi;
|
autosensData.bgi = bgi;
|
||||||
autosensData.delta = delta;
|
autosensData.delta = delta;
|
||||||
|
autosensData.avgDelta = avgDelta;
|
||||||
|
autosensData.avgDeviation = avgDeviation;
|
||||||
autosensData.minDeviationSlope = minDeviationSlope;
|
autosensData.minDeviationSlope = minDeviationSlope;
|
||||||
|
|
||||||
// calculate autosens only without COB
|
// calculate autosens only without COB
|
||||||
|
|
Loading…
Reference in a new issue