use of com.health.openscale.gui.measurement.FloatMeasurementView in project openScale by oliexdev.
the class StatisticsFragment method updateStatistics.
private void updateStatistics(List<ScaleMeasurement> scaleMeasurementList) {
radarChartWeek.clear();
radarChartMonth.clear();
Calendar histDate = Calendar.getInstance();
Calendar weekPastDate = Calendar.getInstance();
Calendar monthPastDate = Calendar.getInstance();
weekPastDate.setTime(lastScaleMeasurement.getDateTime());
weekPastDate.add(Calendar.DATE, -7);
monthPastDate.setTime(lastScaleMeasurement.getDateTime());
monthPastDate.add(Calendar.DATE, -30);
ScaleMeasurement averageWeek = new ScaleMeasurement();
ScaleMeasurement averageMonth = new ScaleMeasurement();
ArrayList<RadarEntry> entriesLastMeasurement = new ArrayList<>();
ArrayList<RadarEntry> entriesAvgWeek = new ArrayList<>();
ArrayList<RadarEntry> entriesAvgMonth = new ArrayList<>();
for (ScaleMeasurement measurement : scaleMeasurementList) {
histDate.setTime(measurement.getDateTime());
if (weekPastDate.before(histDate)) {
averageWeek.add(measurement);
}
if (monthPastDate.before(histDate)) {
averageMonth.add(measurement);
}
}
averageWeek.divide(averageWeek.count());
averageMonth.divide(averageMonth.count());
for (MeasurementView view : viewMeasurementsStatistics) {
final FloatMeasurementView measurementView = (FloatMeasurementView) view;
Object[] extraData = new Object[3];
// not needed
extraData[0] = null;
// not needed
extraData[1] = null;
extraData[2] = measurementView;
measurementView.loadFrom(averageMonth, null);
entriesAvgMonth.add(new RadarEntry(measurementView.getValue(), extraData));
measurementView.loadFrom(averageWeek, null);
entriesAvgWeek.add(new RadarEntry(measurementView.getValue(), extraData));
measurementView.loadFrom(lastScaleMeasurement, null);
entriesLastMeasurement.add(new RadarEntry(measurementView.getValue(), extraData));
}
RadarDataSet setLastMeasurement = new RadarDataSet(entriesLastMeasurement, getString(R.string.label_title_last_measurement));
setLastMeasurement.setColor(ColorUtil.COLOR_BLUE);
setLastMeasurement.setFillColor(ColorUtil.COLOR_BLUE);
setLastMeasurement.setDrawFilled(true);
setLastMeasurement.setFillAlpha(180);
setLastMeasurement.setLineWidth(2f);
setLastMeasurement.setDrawHighlightCircleEnabled(true);
setLastMeasurement.setDrawHighlightIndicators(false);
RadarDataSet setAvgWeek = new RadarDataSet(entriesAvgWeek, getString(R.string.label_last_week));
setAvgWeek.setColor(ColorUtil.COLOR_GREEN);
setAvgWeek.setFillColor(ColorUtil.COLOR_GREEN);
setAvgWeek.setDrawFilled(true);
setAvgWeek.setFillAlpha(180);
setAvgWeek.setLineWidth(2f);
setAvgWeek.setDrawHighlightCircleEnabled(true);
setAvgWeek.setDrawHighlightIndicators(false);
RadarDataSet setAvgMonth = new RadarDataSet(entriesAvgMonth, getString(R.string.label_last_month));
setAvgMonth.setColor(ColorUtil.COLOR_GREEN);
setAvgMonth.setFillColor(ColorUtil.COLOR_GREEN);
setAvgMonth.setDrawFilled(true);
setAvgMonth.setFillAlpha(180);
setAvgMonth.setLineWidth(2f);
setAvgMonth.setDrawHighlightCircleEnabled(true);
setAvgMonth.setDrawHighlightIndicators(false);
ArrayList<IRadarDataSet> setsAvgWeek = new ArrayList<>();
setsAvgWeek.add(setAvgWeek);
setsAvgWeek.add(setLastMeasurement);
ArrayList<IRadarDataSet> setsAvgMonth = new ArrayList<>();
setsAvgMonth.add(setAvgMonth);
setsAvgMonth.add(setLastMeasurement);
RadarData dataAvgWeek = new RadarData(setsAvgWeek);
dataAvgWeek.setValueTextSize(8f);
dataAvgWeek.setDrawValues(false);
dataAvgWeek.setValueFormatter(new ValueFormatter() {
@Override
public String getRadarLabel(RadarEntry radarEntry) {
FloatMeasurementView measurementView = (FloatMeasurementView) radarEntry.getData();
return measurementView.getValueAsString(true);
}
});
RadarData dataAvgMonth = new RadarData(setsAvgMonth);
dataAvgMonth.setValueTextSize(8f);
dataAvgMonth.setDrawValues(false);
dataAvgMonth.setValueFormatter(new ValueFormatter() {
@Override
public String getRadarLabel(RadarEntry radarEntry) {
FloatMeasurementView measurementView = (FloatMeasurementView) radarEntry.getData();
return measurementView.getValueAsString(true);
}
});
radarChartWeek.setData(dataAvgWeek);
radarChartMonth.setData(dataAvgMonth);
radarChartWeek.animateXY(1000, 1000);
radarChartMonth.animateXY(1000, 1000);
radarChartWeek.invalidate();
radarChartMonth.invalidate();
}
Aggregations