From c4e44df2c46f52d6259b818d95c1737b3592349d Mon Sep 17 00:00:00 2001 From: a0z Date: Sat, 7 Dec 2024 00:04:47 +0100 Subject: [PATCH] Workout heart rate chart: line chart gap instead of drawing when no data for longer than max gap --- .../ActivitySummariesChartFragment.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesChartFragment.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesChartFragment.java index 2eae36ef9..256a49958 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesChartFragment.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ActivitySummariesChartFragment.java @@ -268,17 +268,26 @@ public class ActivitySummariesChartFragment extends AbstractActivityChartFragmen } final List heartRateEntries = new ArrayList<>(activityPoints.size()); - int lastHrSampleTs = -1; + final List heartRateDataSets = new ArrayList<>(); + int lastTsShorten = 0; for (final ActivityPoint activityPoint : activityPoints) { - int ts = tsTranslation.shorten((int) (activityPoint.getTime().getTime() / 1000)); - if (lastHrSampleTs > -1 && ts - lastHrSampleTs > 1800 * HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) { - heartRateEntries.add(createLineEntry(0, lastHrSampleTs + 1)); - heartRateEntries.add(createLineEntry(0, ts - 1)); + int tsShorten = tsTranslation.shorten((int) (activityPoint.getTime().getTime() / 1000)); + if (lastTsShorten == 0 || (tsShorten - lastTsShorten) <= 60 * HeartRateUtils.MAX_HR_MEASUREMENTS_GAP_MINUTES) { + heartRateEntries.add(new Entry(tsShorten, activityPoint.getHeartRate())); + } else { + if (!heartRateEntries.isEmpty()) { + List clone = new ArrayList<>(heartRateEntries.size()); + clone.addAll(heartRateEntries); + heartRateDataSets.add(createHeartrateSet(clone, "Heart Rate")); + heartRateEntries.clear(); + } } - heartRateEntries.add(createLineEntry(activityPoint.getHeartRate(), ts)); - lastHrSampleTs = ts; + lastTsShorten = tsShorten; + heartRateEntries.add(new Entry(tsShorten, activityPoint.getHeartRate())); + } + if (!heartRateEntries.isEmpty()) { + heartRateDataSets.add(createHeartrateSet(heartRateEntries, "Heart Rate")); } - final LineDataSet heartRateSet = createHeartrateSet(heartRateEntries, "Heart Rate"); if (activitySamplesData != null) { // if we have activity samples, replace the heart rate dataset @@ -287,7 +296,7 @@ public class ActivitySummariesChartFragment extends AbstractActivityChartFragmen for (final ILineDataSet dataSet : dataSets) { if ("Heart Rate".equals(dataSet.getLabel())) { dataSets.remove(dataSet); - dataSets.add(heartRateSet); + dataSets.addAll(heartRateDataSets); return activitySamplesData; } } @@ -295,7 +304,7 @@ public class ActivitySummariesChartFragment extends AbstractActivityChartFragmen //dataSets.add(heartRateSet); return activitySamplesData; } else { - final LineData lineData = new LineData(Collections.singletonList(heartRateSet)); + final LineData lineData = new LineData(heartRateDataSets); final ValueFormatter xValueFormatter = new SampleXLabelFormatter(tsTranslation, "HH:mm"); return new DefaultChartsData<>(lineData, xValueFormatter); }