From b5104dd9cac75637b8d21f1fc1016b12bfb0a649 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Mon, 2 Sep 2024 20:38:49 +0200 Subject: [PATCH] Dashboard: Fix worn in Today widget when devices measure HR less than every minute --- .../dashboard/DashboardTodayWidget.java | 9 ++++++-- .../samples/ColmiActivitySampleProvider.java | 21 ++++++------------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java index fbc227775..68e926a73 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/dashboard/DashboardTodayWidget.java @@ -49,6 +49,7 @@ import java.util.TreeMap; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.DashboardFragment; +import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils; import nodomain.freeyourgadget.gadgetbridge.activities.charts.StepAnalysis; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary; @@ -400,7 +401,9 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { if (sample.getHeartRate() < 10 && firstTimestamp == 0) continue; if (firstTimestamp == 0) firstTimestamp = sample.getTimestamp(); if (lastTimestamp == 0) lastTimestamp = sample.getTimestamp(); - if ((sample.getHeartRate() < 10 || sample.getTimestamp() > lastTimestamp + dashboardData.hrIntervalSecs) && firstTimestamp != lastTimestamp) { + if (HeartRateUtils.getInstance().isValidHeartRateValue(sample.getHeartRate()) + && sample.getTimestamp() > lastTimestamp + dashboardData.hrIntervalSecs + && firstTimestamp != lastTimestamp) { LOG.debug("Registered worn session from {} to {}", firstTimestamp, lastTimestamp); addActivity(firstTimestamp, lastTimestamp, ActivityKind.NOT_MEASURED); if (sample.getHeartRate() < 10) { @@ -412,7 +415,9 @@ public class DashboardTodayWidget extends AbstractDashboardWidget { } continue; } - lastTimestamp = sample.getTimestamp(); + if (HeartRateUtils.getInstance().isValidHeartRateValue(sample.getHeartRate())) { + lastTimestamp = sample.getTimestamp(); + } } if (firstTimestamp != lastTimestamp) { LOG.debug("Registered worn session from {} to {}", firstTimestamp, lastTimestamp); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/samples/ColmiActivitySampleProvider.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/samples/ColmiActivitySampleProvider.java index 459f8784e..8425a7a24 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/samples/ColmiActivitySampleProvider.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/colmi/samples/ColmiActivitySampleProvider.java @@ -39,7 +39,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.ColmiSleepStageSample; import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind; -import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample; public class ColmiActivitySampleProvider extends AbstractSampleProvider { private static final Logger LOG = LoggerFactory.getLogger(ColmiActivitySampleProvider.class); @@ -100,7 +99,12 @@ public class ColmiActivitySampleProvider extends AbstractSampleProvider samples = super.getGBActivitySamples(timestamp_from, timestamp_to); + final List samples = fillGaps( + super.getGBActivitySamples(timestamp_from, timestamp_to), + timestamp_from, + timestamp_to + ); + final Map sampleByTs = new HashMap<>(); for (final ColmiActivitySample sample : samples) { sampleByTs.put(sample.getTimestamp(), sample); @@ -109,19 +113,6 @@ public class ColmiActivitySampleProvider extends AbstractSampleProvider finalSamples = new ArrayList<>(sampleByTs.values()); Collections.sort(finalSamples, (a, b) -> Integer.compare(a.getTimestamp(), b.getTimestamp()));