Skip to content

Commit

Permalink
Move mps to kph calculation to Go
Browse files Browse the repository at this point in the history
Signed-off-by: Jo Vandeginste <Jo.Vandeginste@kuleuven.be>
  • Loading branch information
jovandeginste committed Feb 28, 2024
1 parent cf87211 commit 4b64bf4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
12 changes: 12 additions & 0 deletions pkg/database/user_statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ type (
}
)

func (t *Totals) AverageSpeedKPH() float64 {
return 3.6 * t.AverageSpeed
}

func (t *Totals) AverageSpeedNoPauseKPH() float64 {
return 3.6 * t.AverageSpeedNoPause
}

func (t *Totals) MaxSpeedKPH() float64 {
return 3.6 * t.MaxSpeed
}

func NewWorkoutStatistic(t WorkoutType) *WorkoutStatistic {
return &WorkoutStatistic{
WorkoutType: t,
Expand Down
4 changes: 4 additions & 0 deletions pkg/database/workouts_statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type StatisticsItem struct {
IsWorst bool
}

func (si *StatisticsItem) SpeedKPH() float64 {
return 3.6 * si.Speed
}

func (si *StatisticsItem) createNext(fp *MapPoint) StatisticsItem {
return StatisticsItem{
Unit: si.Unit,
Expand Down
6 changes: 3 additions & 3 deletions views/user/user_statistics.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ <h3 class="{{ IconFor `max-speed` }}">{{ i18n "Max speed" }}</h3>
data: [
{{ range $y, $yv := $stats.PerMonth -}}
{{- range $m, $mv := $yv -}}
{ x: "{{ $y }}-{{ printf "%02d" $m }}", y: 3.6 * {{ $mv.AverageSpeed }} },
{ x: "{{ $y }}-{{ printf "%02d" $m }}", y: {{ $mv.AverageSpeedKPH }} },
{{ end -}}
{{- end }}
],
Expand All @@ -274,7 +274,7 @@ <h3 class="{{ IconFor `max-speed` }}">{{ i18n "Max speed" }}</h3>
data: [
{{ range $y, $yv := $stats.PerMonth -}}
{{- range $m, $mv := $yv -}}
{ x: "{{ $y }}-{{ printf "%02d" $m }}", y: 3.6 * {{ $mv.AverageSpeedNoPause }} },
{ x: "{{ $y }}-{{ printf "%02d" $m }}", y: {{ $mv.AverageSpeedNoPauseKPH }} },
{{ end -}}
{{- end }}
],
Expand All @@ -297,7 +297,7 @@ <h3 class="{{ IconFor `max-speed` }}">{{ i18n "Max speed" }}</h3>
data: [
{{ range $y, $yv := $stats.PerMonth -}}
{{- range $m, $mv := $yv -}}
{ x: "{{ $y }}-{{ printf "%02d" $m }}", y: 3.6 * {{ $mv.MaxSpeed }} },
{ x: "{{ $y }}-{{ printf "%02d" $m }}", y: {{ $mv.MaxSpeedKPH }} },
{{ end -}}
{{- end }}
],
Expand Down
2 changes: 1 addition & 1 deletion views/workouts/workouts_show.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ <h3 class="{{ IconFor `elevation` }}">{{ i18n "Elevation" }}</h3>
label: "{{ i18n `Average speed` }}",
data: [
{{ range $.workoutStatisticsPerMin -}}
{ "x": {{ .FirstPoint.Time }}, "y": 3.6 * {{ .Speed }}, },
{ "x": {{ .FirstPoint.Time }}, "y": {{ .SpeedKPH }}, },
{{- end }}
],
}],
Expand Down

0 comments on commit 4b64bf4

Please sign in to comment.