use of com.health.openscale.gui.views.FloatMeasurementView in project openScale by oliexdev.
the class GraphFragment method generateLineData.
private void generateLineData(int field, List<ScaleMeasurement> scaleMeasurementList) {
SimpleDateFormat day_date = new SimpleDateFormat("D", Locale.getDefault());
if (field == Calendar.DAY_OF_MONTH) {
day_date = new SimpleDateFormat("dd", Locale.getDefault());
if (prefs.getBoolean("showWeek", false)) {
field = Calendar.WEEK_OF_MONTH;
day_date = new SimpleDateFormat("w", Locale.getDefault());
}
} else if (field == Calendar.DAY_OF_YEAR) {
day_date = new SimpleDateFormat("D", Locale.getDefault());
if (prefs.getBoolean("averageData", true)) {
field = Calendar.MONTH;
day_date = new SimpleDateFormat("MMM", Locale.getDefault());
}
if (prefs.getBoolean("showWeek", false)) {
field = Calendar.WEEK_OF_YEAR;
day_date = new SimpleDateFormat("w", Locale.getDefault());
}
}
Calendar calDays = (Calendar) calLastSelected.clone();
calDays.setMinimalDaysInFirstWeek(7);
calDays.set(field, calDays.getMinimum(field));
int maxDays = calDays.getMaximum(field);
List<AxisValue> axisValues = new ArrayList<>();
for (int i = 0; i < calDays.getMaximum(field) + 1; i++) {
String day_name = day_date.format(calDays.getTime());
AxisValue xAxisValue = new AxisValue(i + calDays.getActualMinimum(field));
xAxisValue.setLabel(day_name);
axisValues.add(xAxisValue);
calDays.add(field, 1);
}
List<Line> diagramLineList = new ArrayList<Line>();
Calendar calDB = Calendar.getInstance();
pointIndexScaleMeasurementList = new ArrayList<>();
floatingActionBar.removeAllViews();
PolynomialFitter polyFitter = new PolynomialFitter(Integer.parseInt(prefs.getString("regressionLineOrder", "1")));
for (MeasurementView view : measurementViews) {
if (view instanceof FloatMeasurementView) {
FloatMeasurementView measurementView = (FloatMeasurementView) view;
if (measurementView instanceof BMRMeasurementView) {
continue;
}
Stack<PointValue> valuesStack = new Stack<>();
ArrayList<Float>[] avgBins = new ArrayList[maxDays + 1];
ScaleMeasurement[] indexScaleMeasurement = new ScaleMeasurement[maxDays + 1];
for (ScaleMeasurement measurement : scaleMeasurementList) {
measurementView.loadFrom(measurement, null);
calDB.setTime(measurement.getDateTime());
calDB.setMinimalDaysInFirstWeek(7);
if (avgBins[calDB.get(field)] == null) {
avgBins[calDB.get(field)] = new ArrayList<>();
}
if (measurementView.getValue() != 0.0f) {
avgBins[calDB.get(field)].add(measurementView.getValue());
indexScaleMeasurement[calDB.get(field)] = measurement;
}
}
for (int i = 0; i < maxDays + 1; i++) {
ArrayList avgBin = avgBins[i];
if (avgBin == null) {
continue;
}
float sum = 0.0f;
for (int j = 0; j < avgBin.size(); j++) {
sum += (float) avgBin.get(j);
}
PointValue avgValue = new PointValue(i, sum / avgBin.size());
if (prefs.getBoolean("regressionLine", false) && measurementView instanceof WeightMeasurementView) {
polyFitter.addPoint((double) avgValue.getX(), (double) avgValue.getY());
}
if (avgBin.size() > 1) {
avgValue.setLabel(String.format("Ø %.2f", avgValue.getY()));
}
valuesStack.push(avgValue);
pointIndexScaleMeasurementList.add(indexScaleMeasurement[i]);
}
Line diagramLine = new Line(valuesStack).setColor(measurementView.getColor()).setHasLabels(prefs.getBoolean("labelsEnable", true)).setHasPoints(prefs.getBoolean("pointsEnable", true)).setFormatter(new SimpleLineChartValueFormatter(1));
if (measurementView.isVisible()) {
addFloatingActionButton(measurementView);
if (measurementView.getSettings().isInGraph()) {
diagramLineList.add(diagramLine);
}
}
}
}
LineChartData lineData = new LineChartData(diagramLineList);
lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(textColor));
lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(5).setTextColor(textColor));
chartBottom.setLineChartData(lineData);
defaultTopViewport = new Viewport(calDays.getActualMinimum(field), chartBottom.getCurrentViewport().top, calDays.getMaximum(field) + 1, chartBottom.getCurrentViewport().bottom);
if (prefs.getBoolean("goalLine", true)) {
Stack<PointValue> valuesGoalLine = new Stack<PointValue>();
float goalWeight = openScale.getSelectedScaleUser().getGoalWeight();
valuesGoalLine.push(new PointValue(0, goalWeight));
valuesGoalLine.push(new PointValue(maxDays, goalWeight));
Line goalLine = new Line(valuesGoalLine).setHasPoints(false);
goalLine.setPathEffect(new DashPathEffect(new float[] { 10, 30 }, 0));
diagramLineList.add(goalLine);
}
if (prefs.getBoolean("regressionLine", false)) {
PolynomialFitter.Polynomial polynom = polyFitter.getBestFit();
Stack<PointValue> valuesLinearRegression = new Stack<>();
for (int i = 0; i < maxDays; i++) {
double y_value = polynom.getY(i);
valuesLinearRegression.push(new PointValue((float) i, (float) y_value));
}
Line linearRegressionLine = new Line(valuesLinearRegression).setColor(ChartUtils.COLOR_VIOLET).setHasPoints(false).setCubic(true);
linearRegressionLine.setPathEffect(new DashPathEffect(new float[] { 10, 30 }, 0));
diagramLineList.add(linearRegressionLine);
}
chartBottom.setLineChartData(lineData);
chartBottom.setCurrentViewport(defaultTopViewport);
}
use of com.health.openscale.gui.views.FloatMeasurementView in project openScale by oliexdev.
the class OverviewFragment method updateLastLineChart.
private void updateLastLineChart(List<ScaleMeasurement> scaleMeasurementList) {
final Calendar now = Calendar.getInstance();
Calendar histCalendar = Calendar.getInstance();
scaleMeasurementLastDays = new ArrayList<>();
List<AxisValue> axisValues = new ArrayList<>();
int max_i = Math.min(7, scaleMeasurementList.size());
for (int i = 0; i < max_i; ++i) {
ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
scaleMeasurementLastDays.add(measurement);
histCalendar.setTime(measurement.getDateTime());
int days = DateTimeHelpers.daysBetween(now, histCalendar);
String label = getResources().getQuantityString(R.plurals.label_days, Math.abs(days), days);
axisValues.add(new AxisValue(i, label.toCharArray()));
}
List<Line> diagramLineList = new ArrayList<>();
for (MeasurementView view : measurementViews) {
if (!view.isVisible() || !view.getSettings().isInOverviewGraph() || !(view instanceof FloatMeasurementView)) {
continue;
}
FloatMeasurementView measurementView = (FloatMeasurementView) view;
Stack<PointValue> valuesStack = new Stack<PointValue>();
for (int i = 0; i < max_i; ++i) {
ScaleMeasurement measurement = scaleMeasurementList.get(max_i - i - 1);
measurementView.loadFrom(measurement, null);
if (measurementView.getValue() != 0.0f) {
valuesStack.push(new PointValue(i, measurementView.getValue()));
}
}
diagramLineList.add(new Line(valuesStack).setColor(measurementView.getColor()).setHasLabels(prefs.getBoolean("labelsEnable", true)).setHasPoints(prefs.getBoolean("pointsEnable", true)).setFormatter(new SimpleLineChartValueFormatter(1)));
}
LineChartData lineData = new LineChartData(diagramLineList);
lineData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
lineData.setAxisYLeft(new Axis().setHasLines(true).setMaxLabelChars(5).setTextColor(txtTitleLastMeasurement.getCurrentTextColor()));
lineChartLast.setLineChartData(lineData);
lineChartLast.setViewportCalculationEnabled(true);
lineChartLast.setZoomEnabled(false);
}
use of com.health.openscale.gui.views.FloatMeasurementView in project openScale by oliexdev.
the class OverviewFragment method updateLastPieChart.
private void updateLastPieChart() {
List<SliceValue> arcValuesLast = new ArrayList<>();
for (MeasurementView view : measurementViews) {
if (view instanceof FloatMeasurementView) {
FloatMeasurementView measurementView = (FloatMeasurementView) view;
if (measurementView instanceof BMRMeasurementView) {
continue;
}
measurementView.loadFrom(lastScaleMeasurement, null);
if (measurementView.getValue() != 0) {
arcValuesLast.add(new SliceValue(measurementView.getValue(), measurementView.getColor()));
}
}
}
final Converters.WeightUnit unit = currentScaleUser.getScaleUnit();
PieChartData pieChartData = new PieChartData(arcValuesLast);
pieChartData.setHasLabels(false);
pieChartData.setHasCenterCircle(true);
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleMeasurement.getConvertedWeight(unit), unit.toString()));
pieChartData.setCenterText2(DateFormat.getDateInstance(DateFormat.MEDIUM).format(lastScaleMeasurement.getDateTime()));
pieChartData.setCenterText1Color(txtTitleLastMeasurement.getCurrentTextColor());
pieChartData.setCenterText2Color(txtTitleLastMeasurement.getCurrentTextColor());
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE || (getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {
pieChartData.setCenterText1FontSize(20);
pieChartData.setCenterText2FontSize(14);
} else {
pieChartData.setCenterText1FontSize(15);
pieChartData.setCenterText2FontSize(12);
pieChartData.setValueLabelTextSize(12);
}
pieChartLast.setPieChartData(pieChartData);
}
Aggregations