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

Show what other metrics are contained in the workout #195

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
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
20 changes: 20 additions & 0 deletions assets/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,10 @@ table {
justify-content: center;
}

.gap-1 {
gap: 0.25rem;
}

.gap-2 {
gap: 0.5rem;
}
Expand Down Expand Up @@ -2636,6 +2640,14 @@ table {
content: "\f450";
}

.icon-heart-pulse::before {
content: "\f21e";
}

.icon-heart-pulse::after {
content: "\f21e";
}

.icon-hourglass::before {
content: "\f254";
}
Expand Down Expand Up @@ -2740,6 +2752,14 @@ table {
content: "\f10d";
}

.icon-rectangle-list::before {
content: "\f022";
}

.icon-rectangle-list::after {
content: "\f022";
}

.icon-right-from-bracket::before {
content: "\f2f5";
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/database/extra_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ func (em ExtraMetrics) Set(key string, value float64) {
}

func (em ExtraMetrics) Get(key string) float64 {
v, ok := em[key]
if ok {
return v
}

return v
return em[key]
}

func (em ExtraMetrics) ParseGPXExtensions(extension gpx.Extension) {
Expand Down
29 changes: 29 additions & 0 deletions pkg/database/workouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/parser"
"github.com/jovandeginste/workout-tracker/pkg/converters"
"github.com/labstack/gommon/log"
"github.com/microcosm-cc/bluemonday"
"github.com/tkrajina/gpxgo/gpx"
"gorm.io/gorm"
Expand Down Expand Up @@ -265,6 +266,34 @@ func (w *Workout) UpdateData(db *gorm.DB) error {
return w.Save(db)
}

func (w *Workout) HasElevation() bool {
return w.HasExtraMetric("Elevation")
}

func (w *Workout) HasCadence() bool {
return w.HasExtraMetric("ns3:cad")
}

func (w *Workout) HasHeartRate() bool {
return w.HasExtraMetric("ns3:hr")
}

func (w *Workout) HasExtraMetric(name string) bool {
if w.Data == nil || w.Data.Details == nil {
return false
}

for _, d := range w.Data.Details.Points {
log.Info(d)

if _, ok := d.ExtraMetrics[name]; ok {
return true
}
}

return false
}

func (w *Workout) EquipmentIDs() []uint {
var ids []uint

Expand Down
22 changes: 14 additions & 8 deletions pkg/templatehelpers/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ func categoryIcon(what string) string {
switch what {
case "source":
return iconDefaults + " icon-solid icon-bookmark"
case "units":
return iconDefaults + " icon-solid icon-ruler"
case "file":
return iconDefaults + " icon-solid icon-file"
case "distance":
return iconDefaults + " icon-solid icon-road"
case "speed":
Expand All @@ -48,25 +44,35 @@ func categoryIcon(what string) string {
return iconDefaults + " icon-solid icon-calculator"
case "weight":
return iconDefaults + " icon-solid icon-weight-hanging"
case "heartrate":
return iconDefaults + " icon-solid icon-heart-pulse"
case "cadence":
return iconDefaults + " icon-solid icon-stopwatch"
case "date":
return iconDefaults + " icon-regular icon-calendar"
case "pause":
return iconDefaults + " icon-regular icon-hourglass"
case "up":
return iconDefaults + " icon-solid icon-chevron-up"
case "down":
return iconDefaults + " icon-solid icon-chevron-down"
default:
return ""
}
}

func miscIcon(what string) string {
switch what {
case "units":
return iconDefaults + " icon-solid icon-ruler"
case "file":
return iconDefaults + " icon-solid icon-file"
case "best":
return iconDefaults + " icon-solid icon-arrow-up-long"
case "worst":
return iconDefaults + " icon-solid icon-arrow-down-long"
case "up":
return iconDefaults + " icon-solid icon-chevron-up"
case "down":
return iconDefaults + " icon-solid icon-chevron-down"
case "metrics":
return iconDefaults + " icon-regular icon-rectangle-list"
default:
return ""
}
Expand Down
1 change: 1 addition & 0 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Enable API access": "API-Zugriff aktivieren",
"Encountered %d problems while adding workouts: %s": "Beim Hinzufügen vom Training %s sind folgende Probleme aufgetreten %d",
"Equipment": "Ausrüstung",
"Extra metrics": "Extra metrics",
"File": "Datei",
"Heart rate": "Herzfrequenz",
"I completed a workout: %s.": "Ich habe das Training %s absolviert.",
Expand Down
1 change: 1 addition & 0 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Enable API access": "Activer l'accès à l'API",
"Encountered %d problems while adding workouts: %s": "%d problèmes rencontrés lors de l'ajout d'entraînements : %s",
"Equipment": "Équipement",
"Extra metrics": "Extra metrics",
"File": "Fichier",
"Heart rate": "Rythme cardiaque",
"I completed a workout: %s.": "J'ai terminé une séance d'entraînement : %s.",
Expand Down
1 change: 1 addition & 0 deletions translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Enable API access": "Abilita l'accesso API",
"Encountered %d problems while adding workouts: %s": "Riscontrati %d problemi durante l'aggiunta degli allenamenti: %s",
"Equipment": "Attrezzatura",
"Extra metrics": "Extra metrics",
"File": "File",
"Heart rate": "Frequenza cardiaca",
"I completed a workout: %s.": "Ho completato un allenamento: %s.",
Expand Down
1 change: 1 addition & 0 deletions translations/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Enable API access": "Enable API access",
"Encountered %d problems while adding workouts: %s": "Encountered %d problems while adding workouts: %s",
"Equipment": "Equipment",
"Extra metrics": "Extra metrics",
"File": "File",
"Heart rate": "Heart rate",
"I completed a workout: %s.": "I completed a workout: %s.",
Expand Down
1 change: 1 addition & 0 deletions translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"Enable API access": "API toegang inschakelen",
"Encountered %d problems while adding workouts: %s": "Problemen bij het toevoegen van %d workouts: %s",
"Equipment": "Materiaal",
"Extra metrics": "Extra metrics",
"File": "Bestand",
"Heart rate": "Hartslag",
"I completed a workout: %s.": "Ik heb een workout voltooid: %s.",
Expand Down
14 changes: 14 additions & 0 deletions views/partials/workout_details.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@
{{ end }} {{ else }} <i>{{ i18n "no equipment" }}</i> {{ end }}
</td>
</tr>
<tr>
<td class="{{ IconFor `metrics` }}"></td>
<td>{{ i18n "Extra metrics" }}</td>
<td class="flex flex-wrap gap-1">
{{ if .HasHeartRate }}
<div
title="{{ i18n `Heart rate` }}"
class="{{ IconFor `heartrate` }}"
></div>
{{ end }} {{ if .HasCadence }}
<div title="{{ i18n `Cadence` }}" class="{{ IconFor `cadence` }}"></div>
{{ end }}
</td>
</tr>
</tbody>
</table>
{{end}}
Loading