mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 11:40:23 +02:00
fixed to show the correct regression line
This commit is contained in:
@@ -278,9 +278,10 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
newValue.setLabel(String.format("Ø %.2f", newValue.getY()));
|
newValue.setLabel(String.format("Ø %.2f", newValue.getY()));
|
||||||
|
|
||||||
pointValues.push(newValue);
|
pointValues.push(newValue);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
if (value_y != 0.0f) { // don't show zero values
|
if (value_y != 0.0f) { // don't show zero values
|
||||||
pointValues.add(new PointValue(value_x, value_y));
|
pointValues.push(new PointValue(value_x, value_y));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -410,8 +411,13 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
Stack<PointValue> valuesWeight = new Stack<PointValue>();
|
Stack<PointValue> valuesWeight = new Stack<PointValue>();
|
||||||
|
|
||||||
for (ScaleMeasurement measurement : scaleMeasurementList) {
|
for (ScaleMeasurement measurement : scaleMeasurementList) {
|
||||||
|
calDB.setTime(measurement.getDateTime());
|
||||||
|
|
||||||
addPointValue(valuesWeight, calDB.get(field), measurement.getConvertedWeight(openScale.getSelectedScaleUser().getScaleUnit()));
|
addPointValue(valuesWeight, calDB.get(field), measurement.getConvertedWeight(openScale.getSelectedScaleUser().getScaleUnit()));
|
||||||
polyFitter.addPoint(calDB.get(field), measurement.getConvertedWeight(openScale.getSelectedScaleUser().getScaleUnit()));
|
}
|
||||||
|
|
||||||
|
for (PointValue value : valuesWeight) {
|
||||||
|
polyFitter.addPoint(value.getX(), value.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
PolynomialFitter.Polynomial polynom = polyFitter.getBestFit();
|
PolynomialFitter.Polynomial polynom = polyFitter.getBestFit();
|
||||||
@@ -419,14 +425,15 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
|
|||||||
Stack<PointValue> valuesLinearRegression = new Stack<PointValue>();
|
Stack<PointValue> valuesLinearRegression = new Stack<PointValue>();
|
||||||
|
|
||||||
if (!valuesWeight.isEmpty()) {
|
if (!valuesWeight.isEmpty()) {
|
||||||
for (int i = (int)valuesWeight.peek().getX(); i <= maxDays; i++) {
|
for (int i = 0; i < maxDays+1; i++) {
|
||||||
double y_value = polynom.getY(i);
|
double y_value = polynom.getY(i);
|
||||||
valuesLinearRegression.push(new PointValue((float) i, (float) y_value));
|
valuesLinearRegression.push(new PointValue((float) i, (float) y_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Line linearRegressionLine = new Line(valuesLinearRegression)
|
Line linearRegressionLine = new Line(valuesLinearRegression)
|
||||||
.setColor(ChartUtils.COLOR_VIOLET)
|
.setColor(ChartUtils.COLOR_VIOLET)
|
||||||
.setHasPoints(false);
|
.setHasPoints(false)
|
||||||
|
.setCubic(true);
|
||||||
|
|
||||||
linearRegressionLine.setPathEffect(new DashPathEffect(new float[] {10,30}, 0));
|
linearRegressionLine.setPathEffect(new DashPathEffect(new float[] {10,30}, 0));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user