Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug split pace elevation calculation #67

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/components/SplitPaceGraph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import { Duration } from 'luxon'
<div class="position-relative"></div>
</td>
<td class="small text-end">
{{ formatElev(splitSummary.totalAscend, splitSummary.totalDescend) }}
{{ formatElev(splitSummary.totalAscent, splitSummary.totalDescent) }}
</td>
<td class="small text-end">
{{ formatAvgHr(splitSummary.totalHeartRate, splitSummary.totalHeartRateRecord) }}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -232,7 +234,8 @@ export default {
progress = new SplitProgress()

for (const record of session.records) {
if (!record.distance) continue
// ignore invalid distance
if (record.distance == null) continue
progress.summarized = false

if (progress.firstRecord == emptyRecord) {
Expand All @@ -251,18 +254,26 @@ export default {
progress.currentDuration += deltaTime
}

// elev delta
const deltaElev = (record.altitude ?? 0) - (progress.prevRecord.altitude ?? 0)
if (deltaElev >= 0) {
splitSummary.totalAscend += deltaElev
} else {
splitSummary.totalDescend -= 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) {
progress.totalHeartRate += record.heartRate
progress.totalHeartRateRecord++
}

// // test Random HR
// progress.totalHeartRate += Math.floor(Math.random() * (1 + 200 - 90)) + 90
// progress.totalHeartRateRecord++
Expand Down Expand Up @@ -315,8 +326,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
Expand Down
Loading