Search in sources :

Example 1 with SleepSession

use of nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepAnalysis.SleepSession in project Gadgetbridge by Freeyourgadget.

the class SleepChartFragment method buildYouSleptText.

private String buildYouSleptText(MySleepChartsData pieData) {
    final StringBuilder result = new StringBuilder();
    if (pieData.getSleepSessions().isEmpty()) {
        result.append(getContext().getString(R.string.you_did_not_sleep));
    } else {
        for (SleepSession sleepSession : pieData.getSleepSessions()) {
            result.append(getContext().getString(R.string.you_slept, DateTimeUtils.timeToString(sleepSession.getSleepStart()), DateTimeUtils.timeToString(sleepSession.getSleepEnd())));
            result.append('\n');
        }
    }
    return result.toString();
}
Also used : SleepSession(nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepAnalysis.SleepSession)

Example 2 with SleepSession

use of nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepAnalysis.SleepSession in project Gadgetbridge by Freeyourgadget.

the class SleepChartFragment method refreshSleepAmounts.

private MySleepChartsData refreshSleepAmounts(GBDevice mGBDevice, List<? extends ActivitySample> samples) {
    SleepAnalysis sleepAnalysis = new SleepAnalysis();
    List<SleepSession> sleepSessions = sleepAnalysis.calculateSleepSessions(samples);
    PieData data = new PieData();
    final long lightSleepDuration = calculateLightSleepDuration(sleepSessions);
    final long deepSleepDuration = calculateDeepSleepDuration(sleepSessions);
    final long totalSeconds = lightSleepDuration + deepSleepDuration;
    final List<PieEntry> entries;
    final List<Integer> colors;
    if (sleepSessions.isEmpty()) {
        entries = Collections.emptyList();
        colors = Collections.emptyList();
    } else {
        entries = Arrays.asList(new PieEntry(lightSleepDuration, getActivity().getString(R.string.abstract_chart_fragment_kind_light_sleep)), new PieEntry(deepSleepDuration, getActivity().getString(R.string.abstract_chart_fragment_kind_deep_sleep)));
        colors = Arrays.asList(getColorFor(ActivityKind.TYPE_LIGHT_SLEEP), getColorFor(ActivityKind.TYPE_DEEP_SLEEP));
    }
    String totalSleep = DateTimeUtils.formatDurationHoursMinutes(totalSeconds, TimeUnit.SECONDS);
    PieDataSet set = new PieDataSet(entries, "");
    set.setValueFormatter(new ValueFormatter() {

        @Override
        public String getFormattedValue(float value) {
            return DateTimeUtils.formatDurationHoursMinutes((long) value, TimeUnit.SECONDS);
        }
    });
    set.setColors(colors);
    set.setValueTextColor(DESCRIPTION_COLOR);
    set.setValueTextSize(13f);
    set.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    set.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
    data.setDataSet(set);
    // setupLegend(pieChart);
    return new MySleepChartsData(totalSleep, data, sleepSessions);
}
Also used : PieEntry(com.github.mikephil.charting.data.PieEntry) SleepSession(nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepAnalysis.SleepSession) PieDataSet(com.github.mikephil.charting.data.PieDataSet) PieData(com.github.mikephil.charting.data.PieData) ValueFormatter(com.github.mikephil.charting.formatter.ValueFormatter)

Aggregations

SleepSession (nodomain.freeyourgadget.gadgetbridge.activities.charts.SleepAnalysis.SleepSession)2 PieData (com.github.mikephil.charting.data.PieData)1 PieDataSet (com.github.mikephil.charting.data.PieDataSet)1 PieEntry (com.github.mikephil.charting.data.PieEntry)1 ValueFormatter (com.github.mikephil.charting.formatter.ValueFormatter)1