autosens call refactor

This commit is contained in:
Milos Kozak 2018-07-20 00:19:13 +02:00
parent 8f8e91f2de
commit d17ffc334d
7 changed files with 17 additions and 9 deletions

View file

@ -70,7 +70,7 @@ public class AutosensData implements DataPointWithLabelInterface {
public double avgDelta = 0d; public double avgDelta = 0d;
public double avgDeviation = 0d; public double avgDeviation = 0d;
public double autosensRatio = 1d; public AutosensResult autosensResult = new AutosensResult();
public double slopeFromMaxDeviation = 0; public double slopeFromMaxDeviation = 0;
public double slopeFromMinDeviation = 999; public double slopeFromMinDeviation = 999;
public double usedMinCarbsImpact = 0d; public double usedMinCarbsImpact = 0d;
@ -86,7 +86,7 @@ public class AutosensData implements DataPointWithLabelInterface {
@Override @Override
public String toString() { 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() { public int minOld() {

View file

@ -137,6 +137,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
} }
void loadBgData(long start) { 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); 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)); log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
} }
@ -399,6 +403,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
@Nullable @Nullable
public AutosensData getLastAutosensDataSynchronized(String reason) { 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) { synchronized (dataLock) {
return getLastAutosensData(reason); return getLastAutosensData(reason);
} }

View file

@ -341,7 +341,7 @@ public class IobCobOref1Thread extends Thread {
AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime); AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime);
if (Config.logAutosensData) if (Config.logAutosensData)
log.debug("Sensitivity result: " + sensitivity.toString()); log.debug("Sensitivity result: " + sensitivity.toString());
autosensData.autosensRatio = sensitivity.ratio; autosensData.autosensResult = sensitivity;
if (Config.logAutosensData) if (Config.logAutosensData)
log.debug(autosensData.toString()); log.debug(autosensData.toString());
} }

View file

@ -268,7 +268,7 @@ public class IobCobThread extends Thread {
AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime); AutosensResult sensitivity = iobCobCalculatorPlugin.detectSensitivityWithLock(oldestTimeWithData, bgTime);
if (Config.logAutosensData) if (Config.logAutosensData)
log.debug("Sensitivity result: " + sensitivity.toString()); log.debug("Sensitivity result: " + sensitivity.toString());
autosensData.autosensRatio = sensitivity.ratio; autosensData.autosensResult = sensitivity;
if (Config.logAutosensData) if (Config.logAutosensData)
log.debug(autosensData.toString()); log.debug(autosensData.toString());
} }

View file

@ -173,7 +173,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
startPart = new Date(); startPart = new Date();
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis()); lastAutosensResult = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin").autosensResult;
} else { } else {
lastAutosensResult = new AutosensResult(); lastAutosensResult = new AutosensResult();
lastAutosensResult.sensResult = "autosens disabled"; lastAutosensResult.sensResult = "autosens disabled";

View file

@ -180,7 +180,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface {
startPart = new Date(); startPart = new Date();
if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) { if (MainApp.getConstraintChecker().isAutosensModeEnabled().value()) {
lastAutosensResult = IobCobCalculatorPlugin.getPlugin().detectSensitivityWithLock(IobCobCalculatorPlugin.getPlugin().oldestDataAvailable(), System.currentTimeMillis()); lastAutosensResult = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin").autosensResult;
} else { } else {
lastAutosensResult = new AutosensResult(); lastAutosensResult = new AutosensResult();
lastAutosensResult.sensResult = "autosens disabled"; lastAutosensResult.sensResult = "autosens disabled";

View file

@ -490,9 +490,9 @@ public class GraphData {
for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) { for (long time = fromTime; time <= toTime; time += 5 * 60 * 1000L) {
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time); AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getAutosensData(time);
if (autosensData != null) { if (autosensData != null) {
ratioArray.add(new ScaledDataPoint(time, autosensData.autosensRatio - 1, ratioScale)); ratioArray.add(new ScaledDataPoint(time, autosensData.autosensResult.ratio - 1, ratioScale));
maxRatioValueFound = Math.max(maxRatioValueFound, autosensData.autosensRatio - 1); maxRatioValueFound = Math.max(maxRatioValueFound, autosensData.autosensResult.ratio - 1);
minRatioValueFound = Math.min(minRatioValueFound, autosensData.autosensRatio - 1); minRatioValueFound = Math.min(minRatioValueFound, autosensData.autosensResult.ratio - 1);
} }
} }