From 5b4d10f333278fda341cff42f7bf885b1035754f Mon Sep 17 00:00:00 2001 From: Radityo Date: Mon, 4 Dec 2023 23:48:34 +0700 Subject: [PATCH 1/2] fix descent calculation missed use subtract instead sum. rename ascent/descent variable. --- src/components/SplitPaceGraph.vue | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/components/SplitPaceGraph.vue b/src/components/SplitPaceGraph.vue index 8c33aaf..7c05999 100644 --- a/src/components/SplitPaceGraph.vue +++ b/src/components/SplitPaceGraph.vue @@ -89,7 +89,7 @@ import { Duration } from 'luxon'
- {{ formatElev(splitSummary.totalAscend, splitSummary.totalDescend) }} + {{ formatElev(splitSummary.totalAscent, splitSummary.totalDescent) }} {{ formatAvgHr(splitSummary.totalHeartRate, splitSummary.totalHeartRateRecord) }} @@ -118,8 +118,8 @@ class SplitSummary { totalDuration: number = 0 // Total duration of current split overallDuration: number = 0 // Overall duration from start till this split - totalAscend: number = 0 - totalDescend: number = 0 + totalAscent: number = 0 + totalDescent: number = 0 totalRecord: number = 0 totalHeartRate: number = 0 totalHeartRateRecord: number = 0 @@ -232,7 +232,7 @@ export default { progress = new SplitProgress() for (const record of session.records) { - if (!record.distance) continue + if (record.distance == null) continue progress.summarized = false if (progress.firstRecord == emptyRecord) { @@ -252,17 +252,20 @@ export default { } // elev delta - const deltaElev = (record.altitude ?? 0) - (progress.prevRecord.altitude ?? 0) - if (deltaElev >= 0) { - splitSummary.totalAscend += deltaElev - } else { - splitSummary.totalDescend -= Math.abs(deltaElev) + if (record.altitude != null && progress.prevRecord.altitude != null) { + const deltaElev = record.altitude - progress.prevRecord.altitude + if (deltaElev > 0) { + splitSummary.totalAscent += deltaElev + } else { + splitSummary.totalDescent += Math.abs(deltaElev) + } } if (record.heartRate != null) { progress.totalHeartRate += record.heartRate progress.totalHeartRateRecord++ } + // // test Random HR // progress.totalHeartRate += Math.floor(Math.random() * (1 + 200 - 90)) + 90 // progress.totalHeartRateRecord++ @@ -315,8 +318,8 @@ export default { const lastSplitSummary = this.summaries[this.summaries.length - 1] lastSplitSummary.overallDistance = splitSummary.overallDistance // replace lastSplitSummary.totalDistance += splitSummary.totalDistance - lastSplitSummary.totalAscend += splitSummary.totalAscend - lastSplitSummary.totalDescend += splitSummary.totalDescend + lastSplitSummary.totalAscent += splitSummary.totalAscent + lastSplitSummary.totalDescent += splitSummary.totalDescent lastSplitSummary.totalDuration += splitSummary.totalDuration lastSplitSummary.totalHeartRate += splitSummary.totalHeartRate lastSplitSummary.totalHeartRateRecord += splitSummary.totalHeartRateRecord From 3644007ff6f8ea88f559dfae1c4da7827bf60b21 Mon Sep 17 00:00:00 2001 From: Radityo Date: Wed, 6 Dec 2023 12:40:47 +0700 Subject: [PATCH 2/2] Update split pace calculate elev with current valid altitude vs valid previous latest altitude --- src/components/SplitPaceGraph.vue | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/components/SplitPaceGraph.vue b/src/components/SplitPaceGraph.vue index 7c05999..6117f5a 100644 --- a/src/components/SplitPaceGraph.vue +++ b/src/components/SplitPaceGraph.vue @@ -130,11 +130,13 @@ class SplitProgress { firstRecord: Record = emptyRecord prevRecord: Record = emptyRecord currentDuration: number = 0 - maxPace: number = 0 totalHeartRate: number = 0 totalHeartRateRecord: number = 0 - summarized: boolean = false + maxPace: number = 0 distance: number = 0 + prevAltitude: number | null = null + + summarized: boolean = false } export default { @@ -232,6 +234,7 @@ export default { progress = new SplitProgress() for (const record of session.records) { + // ignore invalid distance if (record.distance == null) continue progress.summarized = false @@ -251,14 +254,19 @@ export default { progress.currentDuration += deltaTime } - // elev delta - if (record.altitude != null && progress.prevRecord.altitude != null) { - const deltaElev = record.altitude - progress.prevRecord.altitude - if (deltaElev > 0) { - splitSummary.totalAscent += deltaElev - } else { - splitSummary.totalDescent += Math.abs(deltaElev) + // Elevation Gain, compare current altitude vs latest valid altitude + // 1st record always ignored + if (record.altitude != null) { + if (progress.prevAltitude != null) { + const deltaElev = record.altitude - progress.prevAltitude + if (deltaElev > 0) { + splitSummary.totalAscent += deltaElev + } else { + splitSummary.totalDescent += Math.abs(deltaElev) + } } + + progress.prevAltitude = record.altitude } if (record.heartRate != null) {