mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-08-24 16:21:16 +02:00
merge new activity samples with samples from database on overlap
This commit is contained in:
parent
86f77e05a9
commit
67eac90f69
@ -9,6 +9,10 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PineTimeActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.List;
|
||||
|
||||
public class PineTimeActivitySampleProvider extends AbstractSampleProvider<PineTimeActivitySample> {
|
||||
private GBDevice mDevice;
|
||||
@ -68,4 +72,12 @@ public class PineTimeActivitySampleProvider extends AbstractSampleProvider<PineT
|
||||
public PineTimeActivitySample createActivitySample() {
|
||||
return new PineTimeActivitySample();
|
||||
}
|
||||
|
||||
public Optional<PineTimeActivitySample> getSampleForTimestamp(int timestamp) {
|
||||
List<PineTimeActivitySample> foundSamples = this.getGBActivitySamples(timestamp, timestamp, ActivityKind.TYPE_ALL);
|
||||
if (foundSamples.size() == 0) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(foundSamples.get(0));
|
||||
}
|
||||
}
|
||||
|
@ -51,6 +51,7 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
import java.util.Optional;
|
||||
|
||||
import co.nstant.in.cbor.CborBuilder;
|
||||
import co.nstant.in.cbor.CborEncoder;
|
||||
@ -1143,6 +1144,12 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
||||
|
||||
sample.setRawIntensity(ActivitySample.NOT_MEASURED);
|
||||
|
||||
Optional<PineTimeActivitySample> storedSample = provider.getSampleForTimestamp(sample.getTimestamp());
|
||||
if (storedSample.isPresent()) {
|
||||
sample.setHeartRate(Math.max(sample.getHeartRate(), storedSample.get().getHeartRate()));
|
||||
sample.setSteps(Math.max(sample.getSteps(), storedSample.get().getSteps()));
|
||||
}
|
||||
|
||||
provider.addGBActivitySample(sample);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user