Skip to content

Commit

Permalink
Merge pull request #409 from jovandeginste/zero-time
Browse files Browse the repository at this point in the history
fix(database): Handle zero duration in workout average speed calculation
  • Loading branch information
jovandeginste authored Jan 21, 2025
2 parents ed549e0 + b416d87 commit 341aa2f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/database/workouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,12 @@ func (w *Workout) setData(data *MapData) {
}

func (w *Workout) UpdateAverages() {
w.Data.AverageSpeed = w.Data.TotalDistance / w.Data.TotalDuration.Seconds()
if w.Data.TotalDuration == 0 {
w.Data.AverageSpeed = 0
} else {
w.Data.AverageSpeed = w.Data.TotalDistance / w.Data.TotalDuration.Seconds()
}

w.Data.AverageSpeedNoPause = w.Data.AverageSpeed
}

Expand Down

0 comments on commit 341aa2f

Please sign in to comment.