calculateFromTreatmentsAndTempsSynchronized
This commit is contained in:
parent
f1f7a6ca6c
commit
848863aca5
2 changed files with 12 additions and 10 deletions
|
@ -12,7 +12,6 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -34,9 +33,6 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
|
||||||
import info.nightscout.utils.Round;
|
|
||||||
import info.nightscout.utils.SP;
|
|
||||||
import info.nightscout.utils.SafeParse;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by mike on 24.04.2017.
|
* Created by mike on 24.04.2017.
|
||||||
|
@ -390,7 +386,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
}
|
}
|
||||||
delta = (bg - bucketed_data.get(i + 1).value);
|
delta = (bg - bucketed_data.get(i + 1).value);
|
||||||
|
|
||||||
IobTotal iob = calulateFromTreatmentsAndTemps(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;
|
||||||
|
@ -463,14 +459,20 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
return getBGDataFrom;
|
return getBGDataFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IobTotal calulateFromTreatmentsAndTemps(long time) {
|
public static IobTotal calculateFromTreatmentsAndTempsSynchronized(long time) {
|
||||||
|
synchronized (dataLock) {
|
||||||
|
return calculateFromTreatmentsAndTemps(time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IobTotal calculateFromTreatmentsAndTemps(long time) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
time = roundUpTime(time);
|
time = roundUpTime(time);
|
||||||
if (time < now && iobTable.get(time) != null) {
|
if (time < now && iobTable.get(time) != null) {
|
||||||
//og.debug(">>> calulateFromTreatmentsAndTemps Cache hit " + new Date(time).toLocaleString());
|
//og.debug(">>> calculateFromTreatmentsAndTemps Cache hit " + new Date(time).toLocaleString());
|
||||||
return iobTable.get(time);
|
return iobTable.get(time);
|
||||||
} else {
|
} else {
|
||||||
//log.debug(">>> calulateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString());
|
//log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString());
|
||||||
}
|
}
|
||||||
IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round();
|
IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round();
|
||||||
IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round();
|
IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round();
|
||||||
|
@ -559,7 +561,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
long t = time + i * 5 * 60000;
|
long t = time + i * 5 * 60000;
|
||||||
IobTotal iob = calulateFromTreatmentsAndTemps(t);
|
IobTotal iob = calculateFromTreatmentsAndTempsSynchronized(t);
|
||||||
array[pos] = iob;
|
array[pos] = iob;
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1403,7 +1403,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
int lastCob = 0;
|
int lastCob = 0;
|
||||||
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
||||||
if (showIobView.isChecked()) {
|
if (showIobView.isChecked()) {
|
||||||
double iob = IobCobCalculatorPlugin.calulateFromTreatmentsAndTemps(time).iob;
|
double iob = IobCobCalculatorPlugin.calculateFromTreatmentsAndTempsSynchronized(time).iob;
|
||||||
if (Math.abs(lastIob - iob) > 0.02) {
|
if (Math.abs(lastIob - iob) > 0.02) {
|
||||||
if (Math.abs(lastIob - iob) > 0.2)
|
if (Math.abs(lastIob - iob) > 0.2)
|
||||||
iobArray.add(new DataPoint(time, lastIob));
|
iobArray.add(new DataPoint(time, lastIob));
|
||||||
|
|
Loading…
Reference in a new issue