mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
Dashboard: Fix worn in Today widget when devices measure HR less than every minute
This commit is contained in:
parent
d4e34c5982
commit
b5104dd9ca
@ -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);
|
||||
|
@ -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<ColmiActivitySample> {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ColmiActivitySampleProvider.class);
|
||||
@ -100,7 +99,12 @@ public class ColmiActivitySampleProvider extends AbstractSampleProvider<ColmiAct
|
||||
);
|
||||
final long nanoStart = System.nanoTime();
|
||||
|
||||
final List<ColmiActivitySample> samples = super.getGBActivitySamples(timestamp_from, timestamp_to);
|
||||
final List<ColmiActivitySample> samples = fillGaps(
|
||||
super.getGBActivitySamples(timestamp_from, timestamp_to),
|
||||
timestamp_from,
|
||||
timestamp_to
|
||||
);
|
||||
|
||||
final Map<Integer, ColmiActivitySample> sampleByTs = new HashMap<>();
|
||||
for (final ColmiActivitySample sample : samples) {
|
||||
sampleByTs.put(sample.getTimestamp(), sample);
|
||||
@ -109,19 +113,6 @@ public class ColmiActivitySampleProvider extends AbstractSampleProvider<ColmiAct
|
||||
overlayHeartRate(sampleByTs, timestamp_from, timestamp_to);
|
||||
overlaySleep(sampleByTs, timestamp_from, timestamp_to);
|
||||
|
||||
// Add empty dummy samples every 5 min to make sure the charts and stats aren't too malformed
|
||||
// This is necessary due to the Colmi rings just reporting steps/calories/distance aggregates per hour
|
||||
for (int i=timestamp_from; i<=timestamp_to; i+=300) {
|
||||
ColmiActivitySample sample = sampleByTs.get(i);
|
||||
if (sample == null) {
|
||||
sample = new ColmiActivitySample();
|
||||
sample.setTimestamp(i);
|
||||
sample.setProvider(this);
|
||||
sample.setRawKind(ActivitySample.NOT_MEASURED);
|
||||
sampleByTs.put(i, sample);
|
||||
}
|
||||
}
|
||||
|
||||
final List<ColmiActivitySample> finalSamples = new ArrayList<>(sampleByTs.values());
|
||||
Collections.sort(finalSamples, (a, b) -> Integer.compare(a.getTimestamp(), b.getTimestamp()));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user