Search in sources :

Example 1 with FloatMeasurementView

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();
}
Also used : RadarEntry(com.github.mikephil.charting.data.RadarEntry) RadarDataSet(com.github.mikephil.charting.data.RadarDataSet) IRadarDataSet(com.github.mikephil.charting.interfaces.datasets.IRadarDataSet) BMIMeasurementView(com.health.openscale.gui.measurement.BMIMeasurementView) WeightMeasurementView(com.health.openscale.gui.measurement.WeightMeasurementView) FloatMeasurementView(com.health.openscale.gui.measurement.FloatMeasurementView) FatMeasurementView(com.health.openscale.gui.measurement.FatMeasurementView) MuscleMeasurementView(com.health.openscale.gui.measurement.MuscleMeasurementView) WaterMeasurementView(com.health.openscale.gui.measurement.WaterMeasurementView) BoneMeasurementView(com.health.openscale.gui.measurement.BoneMeasurementView) MeasurementView(com.health.openscale.gui.measurement.MeasurementView) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) RadarData(com.github.mikephil.charting.data.RadarData) ScaleMeasurement(com.health.openscale.core.datatypes.ScaleMeasurement) IRadarDataSet(com.github.mikephil.charting.interfaces.datasets.IRadarDataSet) ValueFormatter(com.github.mikephil.charting.formatter.ValueFormatter) FloatMeasurementView(com.health.openscale.gui.measurement.FloatMeasurementView)

Aggregations

RadarData (com.github.mikephil.charting.data.RadarData)1 RadarDataSet (com.github.mikephil.charting.data.RadarDataSet)1 RadarEntry (com.github.mikephil.charting.data.RadarEntry)1 ValueFormatter (com.github.mikephil.charting.formatter.ValueFormatter)1 IRadarDataSet (com.github.mikephil.charting.interfaces.datasets.IRadarDataSet)1 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)1 BMIMeasurementView (com.health.openscale.gui.measurement.BMIMeasurementView)1 BoneMeasurementView (com.health.openscale.gui.measurement.BoneMeasurementView)1 FatMeasurementView (com.health.openscale.gui.measurement.FatMeasurementView)1 FloatMeasurementView (com.health.openscale.gui.measurement.FloatMeasurementView)1 MeasurementView (com.health.openscale.gui.measurement.MeasurementView)1 MuscleMeasurementView (com.health.openscale.gui.measurement.MuscleMeasurementView)1 WaterMeasurementView (com.health.openscale.gui.measurement.WaterMeasurementView)1 WeightMeasurementView (com.health.openscale.gui.measurement.WeightMeasurementView)1 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1