diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 11:21:55 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-05 11:21:55 +0200 |
| commit | bef31e1d35fe88f2698cf0e3191f26a79623f66f (patch) | |
| tree | 8d8e10b2a58fc4ca557f0312cfda60adfc308c30 /web/views.go | |
| parent | 69f317d8cb51b911732712a9fcc8ac49563326c6 (diff) | |
feat: Add web ride library with Strava sync
Diffstat (limited to 'web/views.go')
| -rw-r--r-- | web/views.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/web/views.go b/web/views.go new file mode 100644 index 0000000..29f3c4f --- /dev/null +++ b/web/views.go @@ -0,0 +1,52 @@ +package web + +import ( + "fmt" + "time" + + "github.com/martinlehoux/biking_home/rides" +) + +type RideView struct { + rides.Ride + Cotacol string + CotacolPer100Km string +} + +type SyncPageData struct { + From string + To string + Error string + Notice string + HasAuth bool +} + +func formatRideDate(value time.Time) string { + return value.Local().Format("02 Jan 2006, 15:04") +} + +func formatDistance(meters float64) string { + return fmt.Sprintf("%.1f km", meters/1000) +} + +func formatDuration(seconds int64) string { + hours := seconds / 3600 + minutes := (seconds % 3600) / 60 + return fmt.Sprintf("%dh %02dm", hours, minutes) +} + +func formatElevation(meters float64) string { + return fmt.Sprintf("%.0f m", meters) +} + +func formatCotacol(score float64) string { + return fmt.Sprintf("%.1f", score) +} + +func formatCotacolPer100Km(score, distanceM float64) string { + distanceKm := distanceM / 1000 + if distanceKm <= 0 { + return "-" + } + return fmt.Sprintf("%.1f", score*100/distanceKm) +} |