autosens call refactor
This commit is contained in:
parent
8f8e91f2de
commit
d17ffc334d
7 changed files with 17 additions and 9 deletions
|
@ -70,7 +70,7 @@ public class AutosensData implements DataPointWithLabelInterface {
|
|||
public double avgDelta = 0d;
|
||||
public double avgDeviation = 0d;
|
||||
|
||||
public double autosensRatio = 1d;
|
||||
public AutosensResult autosensResult = new AutosensResult();
|
||||
public double slopeFromMaxDeviation = 0;
|
||||
public double slopeFromMinDeviation = 999;
|
||||
public double usedMinCarbsImpact = 0d;
|
||||
|
@ -86,7 +86,7 @@ public class AutosensData implements DataPointWithLabelInterface {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
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 + " slopeFromMaxDeviation=" + slopeFromMaxDeviation + " slopeFromMinDeviation =" + slopeFromMinDeviation;
|
||||
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " avgDelta=" + avgDelta + " Bgi=" + bgi + " Deviation=" + deviation + " avgDeviation=" + avgDeviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensResult.ratio + " slopeFromMaxDeviation=" + slopeFromMaxDeviation + " slopeFromMinDeviation =" + slopeFromMinDeviation;
|
||||
}
|
||||
|
||||
public int minOld() {
|
||||
|
|
|
@ -137,6 +137,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
void loadBgData(long start) {
|
||||
if (start < oldestDataAvailable()) {
|
||||
start = oldestDataAvailable();
|
||||
log.debug("Limiting BG data to oldest data available: " + DateUtil.dateAndTimeString(start));
|
||||
}
|
||||
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime((long) (start - 60 * 60 * 1000L * (24 + dia)), false);
|
||||
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
|
||||
}
|
||||
|
@ -399,6 +403,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
|
||||
@Nullable
|
||||
public AutosensData getLastAutosensDataSynchronized(String reason) {
|
||||
while (thread != null && thread.getState() != Thread.State.TERMINATED) {
|
||||
SystemClock.sleep(100);
|
||||
log.debug("getLastAutosensDataSynchronized is waiting for calculation thread");
|
||||
}
|
||||
synchronized (dataLock) {
|
||||
return getLastAutosensData(reason);
|
||||
}
|
||||
|
|
|
@ -341,7 +341,7 @@ public class IobCobOref1Thread extends Thread {
|
|||
AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime);
|
||||
if (Config.logAutosensData)
|
||||
log.debug("Sensitivity result: " + sensitivity.toString());
|
||||
autosensData.autosensRatio = sensitivity.ratio;
|
||||
autosensData.autosensResult = sensitivity;
|
||||
if (Config.logAutosensData)
|
||||
log.debug(autosensData.toString());
|
||||
}
|
||||
|
|
|
@ -268,7 +268,7 @@ public class IobCobThread extends Thread {
|
|||
AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime);
|
||||
if (Config.logAutosensData)
|
||||
log.debug("Sensitivity result: " + sensitivity.toString());
|
||||
autosensData.autosensRatio = sensitivity.ratio;
|
||||
autosensData.autosensResult = sensitivity;
|
||||
if (Config.logAutosensData)
|
||||
log.debug(autosensData.toString());
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
startPart = new Date();
|
||||
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis());
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin").autosensResult;
|
||||
} else {
|
||||
lastAutosensResult = new AutosensResult();
|
||||
lastAutosensResult.sensResult = "autosens disabled";
|
||||
|
|
|
@ -180,7 +180,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
startPart = new Date();
|
||||
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis());
|
||||
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin").autosensResult;
|
||||
} else {
|
||||
lastAutosensResult = new AutosensResult();
|
||||
lastAutosensResult.sensResult = "autosens disabled";
|
||||
|
|
|
@ -490,9 +490,9 @@ public class GraphData {
|
|||
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time);
|
||||
if (autosensData != null) {
|
||||
ratioArray.add(new ScaledDataPoint(time, autosensData.autosensRatio - 1, ratioScale));
|
||||
maxRatioValueFound = Math.max(maxRatioValueFound, autosensData.autosensRatio - 1);
|
||||
minRatioValueFound = Math.min(minRatioValueFound, autosensData.autosensRatio - 1);
|
||||
ratioArray.add(new ScaledDataPoint(time, autosensData.autosensResult.ratio - 1, ratioScale));
|
||||
maxRatioValueFound = Math.max(maxRatioValueFound, autosensData.autosensResult.ratio - 1);
|
||||
minRatioValueFound = Math.min(minRatioValueFound, autosensData.autosensResult.ratio - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue