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:
parent
5ef7506e5f
commit
ee61a71181
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue