mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 08:05:55 +01:00
Workout heart rate chart: line chart gap instead of drawing when no data for longer than max gap
This commit is contained in:
parent
1b78ebfad9
commit
c4e44df2c4
@ -268,17 +268,26 @@ public class ActivitySummariesChartFragment extends AbstractActivityChartFragmen
|
||||
}
|
||||
|
||||
final List<Entry> heartRateEntries = new ArrayList<>(activityPoints.size());
|
||||
int lastHrSampleTs = -1;
|
||||
final List<ILineDataSet> 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<Entry> 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user