From f8fec5a378cd7bed651d8503b1a12a652748cae4 Mon Sep 17 00:00:00 2001 From: Jo Vandeginste Date: Mon, 29 Jul 2024 17:17:39 +0200 Subject: [PATCH 1/3] Show what other metrics are contained in the workout This should visualize in the details what else can be graphed. Signed-off-by: Jo Vandeginste --- assets/output.css | 20 ++++++++++++++++++++ pkg/database/extra_metrics.go | 7 +------ pkg/database/workouts.go | 29 +++++++++++++++++++++++++++++ pkg/templatehelpers/icons.go | 6 ++++++ views/partials/workout_details.html | 14 ++++++++++++++ 5 files changed, 70 insertions(+), 6 deletions(-) diff --git a/assets/output.css b/assets/output.css index fd37ac60..2d9529ed 100644 --- a/assets/output.css +++ b/assets/output.css @@ -1995,6 +1995,10 @@ table { justify-content: center; } +.gap-1 { + gap: 0.25rem; +} + .gap-2 { gap: 0.5rem; } @@ -2636,6 +2640,14 @@ table { content: "\f450"; } +.icon-heart-pulse::before { + content: "\f21e"; +} + +.icon-heart-pulse::after { + content: "\f21e"; +} + .icon-hourglass::before { content: "\f254"; } @@ -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"; } diff --git a/pkg/database/extra_metrics.go b/pkg/database/extra_metrics.go index 53b53abc..197541b7 100644 --- a/pkg/database/extra_metrics.go +++ b/pkg/database/extra_metrics.go @@ -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) { diff --git a/pkg/database/workouts.go b/pkg/database/workouts.go index e3a6b108..a2fd7676 100644 --- a/pkg/database/workouts.go +++ b/pkg/database/workouts.go @@ -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" @@ -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 diff --git a/pkg/templatehelpers/icons.go b/pkg/templatehelpers/icons.go index f46758e1..4828ddae 100644 --- a/pkg/templatehelpers/icons.go +++ b/pkg/templatehelpers/icons.go @@ -48,6 +48,10 @@ 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": @@ -56,6 +60,8 @@ func categoryIcon(what string) string { 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 "" } diff --git a/views/partials/workout_details.html b/views/partials/workout_details.html index b60c7bce..f9062f75 100644 --- a/views/partials/workout_details.html +++ b/views/partials/workout_details.html @@ -144,6 +144,20 @@ {{ end }} {{ else }} {{ i18n "no equipment" }} {{ end }} + + + {{ i18n "Extra metrics" }} + + {{ if .HasHeartRate }} +
+ {{ end }} {{ if .HasCadence }} +
+ {{ end }} + + {{end}} From b05cd1ed8beca62cb5b34f35986ede5075c732d3 Mon Sep 17 00:00:00 2001 From: Jo Vandeginste Date: Mon, 29 Jul 2024 17:19:25 +0200 Subject: [PATCH 2/3] Restructure the icon switch case Signed-off-by: Jo Vandeginste --- pkg/templatehelpers/icons.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/templatehelpers/icons.go b/pkg/templatehelpers/icons.go index 4828ddae..dfefe451 100644 --- a/pkg/templatehelpers/icons.go +++ b/pkg/templatehelpers/icons.go @@ -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": @@ -56,12 +52,6 @@ func categoryIcon(what string) string { 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" - case "metrics": - return iconDefaults + " icon-regular icon-rectangle-list" default: return "" } @@ -69,10 +59,20 @@ func categoryIcon(what string) string { 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 "" } From 263f9d95922cdee96f43da587ec68e644fe3c24c Mon Sep 17 00:00:00 2001 From: Jo Vandeginste Date: Mon, 29 Jul 2024 17:19:38 +0200 Subject: [PATCH 3/3] Update translation strings Signed-off-by: Jo Vandeginste --- translations/de.json | 1 + translations/fr.json | 1 + translations/it.json | 1 + translations/messages.json | 1 + translations/nl.json | 1 + 5 files changed, 5 insertions(+) diff --git a/translations/de.json b/translations/de.json index c53700d5..519a8573 100644 --- a/translations/de.json +++ b/translations/de.json @@ -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.", diff --git a/translations/fr.json b/translations/fr.json index 17441957..a4ffa536 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -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.", diff --git a/translations/it.json b/translations/it.json index f918c70b..80d4683a 100644 --- a/translations/it.json +++ b/translations/it.json @@ -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.", diff --git a/translations/messages.json b/translations/messages.json index 5a12ea9c..a45c4521 100644 --- a/translations/messages.json +++ b/translations/messages.json @@ -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.", diff --git a/translations/nl.json b/translations/nl.json index c8f64d5b..de3dac0f 100644 --- a/translations/nl.json +++ b/translations/nl.json @@ -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.",