Fix target line performance regression.

This commit is contained in:
Johannes Mockenhaupt 2018-08-06 17:34:07 +02:00
parent 409acd0721
commit 9af0bc2976
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1

View file

@ -243,7 +243,7 @@ public class GraphData {
targetsScale.setMultiplier(1); targetsScale.setMultiplier(1);
List<DataPoint> targetsSeriesArray = new ArrayList<>(); List<DataPoint> targetsSeriesArray = new ArrayList<>();
double lastTarget = 0; double lastTarget = -1;
if (LoopPlugin.lastRun != null && LoopPlugin.lastRun.constraintsProcessed != null) { if (LoopPlugin.lastRun != null && LoopPlugin.lastRun.constraintsProcessed != null) {
APSResult apsResult = LoopPlugin.lastRun.constraintsProcessed; APSResult apsResult = LoopPlugin.lastRun.constraintsProcessed;
@ -253,22 +253,22 @@ public class GraphData {
} }
} }
for (long time = fromTime; time < toTime; time += 60 * 1000L) { for (long time = fromTime; time < toTime; time += 5 * 60 * 1000L) {
TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time); TempTarget tt = TreatmentsPlugin.getPlugin().getTempTargetFromHistory(time);
double value; double value;
if (tt == null) { if (tt == null) {
value = (profile.getTargetLow(time) + profile.getTargetHigh(time)) / 2; value = (profile.getTargetLow(time) + profile.getTargetHigh(time)) / 2;
} else { } else {
value = tt.target(); value = Profile.fromMgdlToUnits(tt.target(), profile.getUnits());
value = Profile.fromMgdlToUnits(value, profile.getUnits());
} }
if (lastTarget > 0 && lastTarget != value) { if (lastTarget != value) {
targetsSeriesArray.add(new DataPoint(time, lastTarget)); if (lastTarget != -1)
targetsSeriesArray.add(new DataPoint(time, lastTarget));
targetsSeriesArray.add(new DataPoint(time, value));
} }
lastTarget = value; lastTarget = value;
targetsSeriesArray.add(new DataPoint(time, value));
} }
targetsSeriesArray.add(new DataPoint(toTime, lastTarget));
DataPoint[] targets = new DataPoint[targetsSeriesArray.size()]; DataPoint[] targets = new DataPoint[targetsSeriesArray.size()];
targets = targetsSeriesArray.toArray(targets); targets = targetsSeriesArray.toArray(targets);