Sort predictions so they're properly displayed in the graph.

GraphView library requires a series to be ordered by the x-value.
This commit is contained in:
Johannes Mockenhaupt 2018-05-01 19:23:12 +02:00
parent 5ef7506e5f
commit ee61a71181
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
2 changed files with 7 additions and 5 deletions

View file

@ -1359,7 +1359,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// **** BG ****
if (predictionsAvailable && SP.getBoolean("showprediction", false))
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed);
graphData.addBgReadings(fromTime, toTime, lowLine, highLine,
finalLastRun.constraintsProcessed.getPredictions());
else
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null);

View file

@ -12,6 +12,7 @@ import com.jjoe64.graphview.series.LineGraphSeries;
import com.jjoe64.graphview.series.Series;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import info.nightscout.androidaps.Constants;
@ -61,7 +62,7 @@ public class GraphData {
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
}
public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, APSResult apsResult) {
public void addBgReadings(long fromTime, long toTime, double lowLine, double highLine, List<BgReading> predictions) {
double maxBgValue = 0d;
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
@ -74,9 +75,9 @@ public class GraphData {
if (bg.value > maxBgValue) maxBgValue = bg.value;
bgListArray.add(bg);
}
if (apsResult != null) {
List<BgReading> predArray = apsResult.getPredictions();
bgListArray.addAll(predArray);
if (predictions != null) {
Collections.sort(predictions, (o1, o2) -> Double.compare(o1.getX(), o2.getX()));
bgListArray.addAll(predictions);
}
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);