summaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-08 10:05:05 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-08 10:05:05 +0200
commit2c00b74cc02b55e26d68fef108596aae56080d5a (patch)
tree793b37a40979b13f05135151814783003ba6bf44 /web
parent7aa64b0917130fcc1dc9f3da30d8f825136fe541 (diff)
feat: Persist Cotacol ride values
Diffstat (limited to 'web')
-rw-r--r--web/server.go2
-rw-r--r--web/server_test.go18
2 files changed, 15 insertions, 5 deletions
diff --git a/web/server.go b/web/server.go
index c7b585e..f8388b9 100644
--- a/web/server.go
+++ b/web/server.go
@@ -89,7 +89,7 @@ func buildRideViews(items []rides.Ride) []RideView {
if err != nil {
slog.Warn("Failed to compute Cotacol", "ride", item.ExternalID, "file", item.GPXPath, "error", err)
} else {
- score := parsed.DifficultyScore()
+ score := ride.Cotacol(parsed)
view.Cotacol = formatCotacol(score)
view.CotacolPer100Km = formatCotacolPer100Km(score, item.DistanceM)
view.cotacolScore = score
diff --git a/web/server_test.go b/web/server_test.go
index b6799cd..98ea681 100644
--- a/web/server_test.go
+++ b/web/server_test.go
@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
+ "os"
"path/filepath"
"strings"
"testing"
@@ -35,6 +36,8 @@ func newWebTestServer(t *testing.T) (*Server, *sql.DB) {
elapsed_time_s integer not null,
total_elevation_gain_m real not null,
average_speed_mps real not null,
+ cotacol_score real,
+ cotacol_algo_version text,
created_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')),
updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now'))
)
@@ -48,11 +51,18 @@ func newWebTestServer(t *testing.T) (*Server, *sql.DB) {
return NewServer(db, configPath), db
}
+func testGPXPath(t *testing.T, name string) string {
+ t.Helper()
+ path := filepath.Join(t.TempDir(), name)
+ require.NoError(t, os.WriteFile(path, []byte(`<?xml version="1.0"?><gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1"><trk><trkseg><trkpt lat="43.0" lon="5.0"><ele>100</ele></trkpt><trkpt lat="43.001" lon="5.001"><ele>200</ele></trkpt></trkseg></trk></gpx>`), 0o600))
+ return path
+}
+
func TestHandlerRendersRidesPage(t *testing.T) {
server, db := newWebTestServer(t)
require.NoError(t, rides.Save(db, rides.Ride{
ExternalID: "strava:1234",
- GPXPath: "missing.gpx",
+ GPXPath: testGPXPath(t, "long.gpx"),
Name: "Long Ride",
Type: "Ride",
StartDate: time.Date(2026, 8, 1, 7, 0, 0, 0, time.UTC),
@@ -60,7 +70,7 @@ func TestHandlerRendersRidesPage(t *testing.T) {
}))
require.NoError(t, rides.Save(db, rides.Ride{
ExternalID: "strava:5678",
- GPXPath: "short.gpx",
+ GPXPath: testGPXPath(t, "short.gpx"),
Name: "Short Ride",
Type: "Ride",
StartDate: time.Date(2026, 8, 2, 7, 0, 0, 0, time.UTC),
@@ -192,7 +202,7 @@ func TestHandlerSortsRidesByDistance(t *testing.T) {
server, db := newWebTestServer(t)
require.NoError(t, rides.Save(db, rides.Ride{
ExternalID: "strava:550e8400-e29b-41d4-a716-446655440000",
- GPXPath: "near.gpx",
+ GPXPath: testGPXPath(t, "near.gpx"),
Name: "Near Ride",
Type: "Ride",
StartDate: time.Date(2026, 8, 1, 7, 0, 0, 0, time.UTC),
@@ -200,7 +210,7 @@ func TestHandlerSortsRidesByDistance(t *testing.T) {
}))
require.NoError(t, rides.Save(db, rides.Ride{
ExternalID: "strava:6ba7b810-9dad-41d1-80b4-00c04fd430c8",
- GPXPath: "far.gpx",
+ GPXPath: testGPXPath(t, "far.gpx"),
Name: "Far Ride",
Type: "Ride",
StartDate: time.Date(2026, 8, 2, 7, 0, 0, 0, time.UTC),