From 90614736f2a0c556f31eca5361b3c032f5f309f6 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Thu, 24 Sep 2026 08:37:33 +0200 Subject: Match official climbs against their recorded sample MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An official climb matched on endpoint coordinates alone. On a loop ridden the other way the route meets the climb's top before its bottom, so pairing each start with the first end inside its lap window credited a 5.9 km passage as the 850 m Chemin de la Tour Pey Blanc, and a 49 km one on another ride. Climbs now keep the sample of the segment they were created from: the recorded length and elevation gain of the selected route points, captured by the ride detail and preview handlers and stored NOT NULL. Matching takes the whole route and drops any candidate outside ±50% of that sample on either axis, and attempts are refreshed by upsert and prune so re-analyzing a ride keeps the recorded-at stamp of the passages that survive. The backfill leaves the web package: backfill.Run recomputes ride values then official climb attempts as a single `go run . backfill` command (climbs-backfill is gone), rideanalysis owns the attempt snapshot, and the mountain-pass loading margin is shared. Applied to the stored rides it stamps 78 samples, drops the four bogus attempts and leaves ride 800 with its three Pont Rout passages. --- web/official-climbs_test.go | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) (limited to 'web/official-climbs_test.go') diff --git a/web/official-climbs_test.go b/web/official-climbs_test.go index ba71f19..8fab49c 100644 --- a/web/official-climbs_test.go +++ b/web/official-climbs_test.go @@ -18,7 +18,7 @@ var testRideStart = time.Date(2026, 9, 1, 8, 0, 0, 0, time.UTC) func testRideForClimb(t *testing.T) (ride.Ride, official_climb.OfficialClimb) { t.Helper() parsed := ridetest.MustRide("1km at 14.7% | 1km at -6.7%", ridetest.StartCoord(43.61, 5.42), ridetest.StartElevation(300), ridetest.Sampling(1000), ridetest.StartTime(testRideStart)) - return parsed, official_climb.OfficialClimb{Name: "Col de Test", StartCoord: parsed.Coords[0], EndCoord: parsed.Coords[1]} + return parsed, official_climb.OfficialClimb{Name: "Col de Test", StartCoord: parsed.Coords[0], EndCoord: parsed.Coords[1], Sample: parsed.Sample(0, 1)} } func insertTestRide(t *testing.T, db *sql.DB) int64 { @@ -33,32 +33,6 @@ func insertTestRide(t *testing.T, db *sql.DB) int64 { return id } -func TestAttemptsFromAnalysisSnapshotsOfficialClimbs(t *testing.T) { - parsed, climb := testRideForClimb(t) - analysis := rideanalysis.Analyze(parsed, nil, []official_climb.OfficialClimb{{ID: 42, Name: climb.Name, StartCoord: climb.StartCoord, EndCoord: climb.EndCoord}}, official_climb.DefaultMatchPolicy()) - - attempts := attemptsFromAnalysis(7, analysis, parsed) - require.Len(t, attempts, 1) - assert.Equal(t, int64(7), attempts[0].RideID) - assert.Equal(t, int64(42), attempts[0].ClimbID) - assert.Equal(t, 0, attempts[0].Occurrence) - assert.InDelta(t, 1000, attempts[0].DistanceM, 1) - assert.InDelta(t, 147, attempts[0].ElevationGainM, 1) - assert.InDelta(t, 14.7, attempts[0].SlopePercent, 0.1) - assert.Positive(t, attempts[0].Cotacol) - assert.Equal(t, "v1", attempts[0].CotacolAlgoVersion) - assert.Equal(t, testRideStart, attempts[0].StartedAt.UTC()) - assert.False(t, attempts[0].EndedAt.IsZero(), "attempt end must come from ride timestamps") -} - -func TestAttemptsFromAnalysisSkipsUnmatchedClimbs(t *testing.T) { - parsed, _ := testRideForClimb(t) - analysis := rideanalysis.Analyze(parsed, nil, nil, official_climb.DefaultMatchPolicy()) - - attempts := attemptsFromAnalysis(7, analysis, parsed) - assert.Empty(t, attempts) -} - func TestRecordOfficialClimbAttemptsPersistsAndReplaces(t *testing.T) { server, db := newWebTestServer(t) rideID := insertTestRide(t, db) -- cgit v1.3