1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-15 13:14:22 +02:00

check if different x positions are added to the polynomial fitter, see #645

This commit is contained in:
oliexdev
2020-12-11 07:12:34 +01:00
parent 40a7f4e739
commit d187079432

View File

@@ -525,20 +525,28 @@ public class ChartMeasurementView extends LineChart {
PolynomialFitter polyFitter = new PolynomialFitter(lineEntries.size() == 2 ? 2 : 3);
// add last point to polynomial fitter first
int lastPos = lineEntries.size() - 1;
Entry lastEntry = lineEntries.get(lastPos);
polyFitter.addPoint((double) lastEntry.getX(), (double) lastEntry.getY());
// use only the last 30 values for the polynomial fitter
for (int i=1; i<30; i++) {
for (int i=2; i<30; i++) {
int pos = lineEntries.size() - i;
if (pos >= 0) {
Entry entry = lineEntries.get(pos);
Entry prevEntry = lineEntries.get(pos+1);
polyFitter.addPoint((double) entry.getX(), (double) entry.getY());
// check if x position is different otherwise that point is useless for the polynomial calculation.
if (entry.getX() != prevEntry.getX()) {
polyFitter.addPoint((double) entry.getX(), (double) entry.getY());
}
}
}
PolynomialFitter.Polynomial polynomial = polyFitter.getBestFit();
Entry lastEntry = lineEntries.get(lineEntries.size() - 1);
int maxX = (int) lastEntry.getX()+1;
List<Entry> predictionValues = new Stack<>();