1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-09 03:37:03 +01:00

Garmin: Fix over-counting of distance at turn of day

This commit is contained in:
José Rebelo 2024-10-05 18:00:57 +01:00
parent cbd6fe2145
commit 7de97a49b0

View File

@ -190,12 +190,22 @@ public abstract class AbstractSampleProvider<T extends AbstractActivitySample> i
protected abstract Property getDeviceIdentifierSampleProperty(); protected abstract Property getDeviceIdentifierSampleProperty();
public void convertCumulativeSteps(final List<T> samples, final Property stepsSampleProperty) { public void convertCumulativeSteps(final List<T> samples, final Property stepsSampleProperty) {
// Fix over-counting at the turn of day
final T lastSample = getLastSampleWithStepsBefore(samples.get(0).getTimestamp(), stepsSampleProperty); final T lastSample = getLastSampleWithStepsBefore(samples.get(0).getTimestamp(), stepsSampleProperty);
if (lastSample != null && sameDay(lastSample, samples.get(0)) && samples.get(0).getSteps() > 0) { if (lastSample != null && sameDay(lastSample, samples.get(0))) {
samples.get(0).setSteps(samples.get(0).getSteps() - lastSample.getSteps()); if (samples.get(0).getSteps() > 0) {
samples.get(0).setSteps(samples.get(0).getSteps() - lastSample.getSteps());
}
if (samples.get(0).getDistanceCm() > 0) {
samples.get(0).setDistanceCm(samples.get(0).getDistanceCm() - lastSample.getDistanceCm());
}
if (samples.get(0).getActiveCalories() > 0) {
samples.get(0).setActiveCalories(samples.get(0).getActiveCalories() - lastSample.getActiveCalories());
}
} }
// Steps on the Garmin Watch are reported cumulatively per day - convert them to
// This slightly breaks activity recognition, because we don't have per-minute granularity... // This slightly breaks activity recognition, because we don't have per-minute granularity...
int prevSteps = samples.get(0).getSteps(); int prevSteps = samples.get(0).getSteps();
int prevDistance = samples.get(0).getDistanceCm(); int prevDistance = samples.get(0).getDistanceCm();