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
2 changed files with 7 additions and 5 deletions
|
@ -1359,7 +1359,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
// **** BG ****
|
// **** BG ****
|
||||||
if (predictionsAvailable && SP.getBoolean("showprediction", false))
|
if (predictionsAvailable && SP.getBoolean("showprediction", false))
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, finalLastRun.constraintsProcessed);
|
graphData.addBgReadings(fromTime, toTime, lowLine, highLine,
|
||||||
|
finalLastRun.constraintsProcessed.getPredictions());
|
||||||
else
|
else
|
||||||
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null);
|
graphData.addBgReadings(fromTime, toTime, lowLine, highLine, null);
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.jjoe64.graphview.series.LineGraphSeries;
|
||||||
import com.jjoe64.graphview.series.Series;
|
import com.jjoe64.graphview.series.Series;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
|
@ -61,7 +62,7 @@ public class GraphData {
|
||||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
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;
|
double maxBgValue = 0d;
|
||||||
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
bgReadingsArray = MainApp.getDbHelper().getBgreadingsDataFromTime(fromTime, true);
|
||||||
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
List<DataPointWithLabelInterface> bgListArray = new ArrayList<>();
|
||||||
|
@ -74,9 +75,9 @@ public class GraphData {
|
||||||
if (bg.value > maxBgValue) maxBgValue = bg.value;
|
if (bg.value > maxBgValue) maxBgValue = bg.value;
|
||||||
bgListArray.add(bg);
|
bgListArray.add(bg);
|
||||||
}
|
}
|
||||||
if (apsResult != null) {
|
if (predictions != null) {
|
||||||
List<BgReading> predArray = apsResult.getPredictions();
|
Collections.sort(predictions, (o1, o2) -> Double.compare(o1.getX(), o2.getX()));
|
||||||
bgListArray.addAll(predArray);
|
bgListArray.addAll(predictions);
|
||||||
}
|
}
|
||||||
|
|
||||||
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
|
maxBgValue = Profile.fromMgdlToUnits(maxBgValue, units);
|
||||||
|
|
Loading…
Reference in a new issue