mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +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:
parent
a0d7c8b77b
commit
2abe7e5b2f
@ -8,11 +8,13 @@ import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
|||||||
public class BarChartStackedTimeValueFormatter extends StackedValueFormatter {
|
public class BarChartStackedTimeValueFormatter extends StackedValueFormatter {
|
||||||
private float[] processedValues;
|
private float[] processedValues;
|
||||||
private BarEntry lastEntry;
|
private BarEntry lastEntry;
|
||||||
|
private int ignoreLast;
|
||||||
private int lastNonZeroIndex;
|
private int lastNonZeroIndex;
|
||||||
private int index = 0;
|
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);
|
super(drawWholeStack, suffix, decimals);
|
||||||
|
this.ignoreLast = ignoreLast;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getLastNonZeroIndex(float[] array) {
|
private int getLastNonZeroIndex(float[] array) {
|
||||||
@ -44,7 +46,7 @@ public class BarChartStackedTimeValueFormatter extends StackedValueFormatter {
|
|||||||
|
|
||||||
String getFormattedValue(float[] values) {
|
String getFormattedValue(float[] values) {
|
||||||
float sum = 0;
|
float sum = 0;
|
||||||
for (int i = 0; i < values.length - 1; i++) {
|
for (int i = 0; i < values.length - ignoreLast; i++) {
|
||||||
sum += values[i];
|
sum += values[i];
|
||||||
}
|
}
|
||||||
return DateTimeUtils.minutesToHHMM((int) sum);
|
return DateTimeUtils.minutesToHHMM((int) sum);
|
||||||
|
@ -152,7 +152,10 @@ public class WeekSleepChartFragment extends AbstractWeekChartFragment {
|
|||||||
mWeekChart.setData(mcd.getWeekBeforeData().getData());
|
mWeekChart.setData(mcd.getWeekBeforeData().getData());
|
||||||
mWeekChart.getXAxis().setValueFormatter(mcd.getWeekBeforeData().getXValueFormatter());
|
mWeekChart.getXAxis().setValueFormatter(mcd.getWeekBeforeData().getXValueFormatter());
|
||||||
mWeekChart.getBarData().setValueTextSize(10f);
|
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) {
|
if (TOTAL_DAYS_FOR_AVERAGE > 0) {
|
||||||
float avgDeep = Math.abs(this.mySleepWeeklyData.getTotalDeep() / TOTAL_DAYS_FOR_AVERAGE);
|
float avgDeep = Math.abs(this.mySleepWeeklyData.getTotalDeep() / TOTAL_DAYS_FOR_AVERAGE);
|
||||||
|
Loading…
Reference in New Issue
Block a user