From bef31e1d35fe88f2698cf0e3191f26a79623f66f Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 5 Aug 2026 11:21:55 +0200 Subject: feat: Add web ride library with Strava sync --- web/views.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 web/views.go (limited to 'web/views.go') 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) +} -- cgit v1.2.3