diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-21 19:02:05 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-21 19:02:05 +0200 |
| commit | 1e63f5c91f0e5ff7dfc582b67d262d5939cc34bc (patch) | |
| tree | 7965a98e4bd286df502d658e687fa83230895c39 /web/views.go | |
| parent | 9ec4d3dbc1f55ca412f6df67b8576b087b15887c (diff) | |
Add global analytics page shell and split server.go by concern
Diffstat (limited to 'web/views.go')
| -rw-r--r-- | web/views.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/web/views.go b/web/views.go index 5422421..9771a4d 100644 --- a/web/views.go +++ b/web/views.go @@ -26,6 +26,36 @@ type RidesPageData struct { Sort RideSort } +type AnalyticsPageData struct { + Points []AnalyticsPoint +} + +type AnalyticsPoint struct { + ID int64 `json:"id"` + Name string `json:"name"` + URL string `json:"url"` + SpeedKmh float64 `json:"speedKmh"` + CotacolPer100Km float64 `json:"cotacolPer100Km"` +} + +func buildAnalyticsPoints(items []rides.Ride) []AnalyticsPoint { + points := make([]AnalyticsPoint, 0, len(items)) + for _, item := range items { + cotacol, ready := item.CotacolScore() + if !ready || item.CotacolAlgorithmVersion() != ride.CotacolAlgorithmVersion || item.DistanceM <= 0 { + continue + } + points = append(points, AnalyticsPoint{ + ID: item.ID, + Name: item.Name, + URL: rideDetailURL(item.ID), + SpeedKmh: item.AverageSpeedMps * 3.6, + CotacolPer100Km: cotacol * 100 / (item.DistanceM / 1000), + }) + } + return points +} + type RideDetailView struct { RideView Route GeoJSONFeatureCollection |
