1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 12:26:48 +01:00

Fix weekly and monthly sleep times for devices without awake sleep

The last sleep stage on these is not "awake sleep" and should be
included.
This commit is contained in:
José Rebelo 2024-10-16 23:07:39 +01:00
parent a0d7c8b77b
commit 2abe7e5b2f
2 changed files with 8 additions and 3 deletions

View File

@ -8,11 +8,13 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class BarChartStackedTimeValueFormatter extends StackedValueFormatter {
private float[] processedValues;
private BarEntry lastEntry;
private int ignoreLast;
private int lastNonZeroIndex;
private int index = 0;
public BarChartStackedTimeValueFormatter(boolean drawWholeStack, String suffix, int decimals) {
public BarChartStackedTimeValueFormatter(boolean drawWholeStack, String suffix, int decimals, int ignoreLast) {
super(drawWholeStack, suffix, decimals);
this.ignoreLast = ignoreLast;
}
private int getLastNonZeroIndex(float[] array) {
@ -44,7 +46,7 @@ public class BarChartStackedTimeValueFormatter extends StackedValueFormatter {
String getFormattedValue(float[] values) {
float sum = 0;
for (int i = 0; i < values.length - 1; i++) {
for (int i = 0; i < values.length - ignoreLast; i++) {
sum += values[i];
}
return DateTimeUtils.minutesToHHMM((int) sum);

View File

@ -152,7 +152,10 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
mWeekChart.setData(mcd.getWeekBeforeData().getData());
mWeekChart.getXAxis().setValueFormatter(mcd.getWeekBeforeData().getXValueFormatter());
mWeekChart.getBarData().setValueTextSize(10f);
mWeekChart.getBarData().setValueFormatter(new BarChartStackedTimeValueFormatter(false, "", 0));
// The last value is for awake time, which we do not want to include in the "total sleep time"
final int barIgnoreLast = supportsAwakeSleep(getChartsHost().getDevice()) ? 1 : 0;
mWeekChart.getBarData().setValueFormatter(new BarChartStackedTimeValueFormatter(false, "", 0, barIgnoreLast));
if (TOTAL_DAYS_FOR_AVERAGE > 0) {
float avgDeep = Math.abs(this.mySleepWeeklyData.getTotalDeep() / TOTAL_DAYS_FOR_AVERAGE);