aboutsummaryrefslogtreecommitdiff
path: root/rideanalysis/analysis.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-09-24 08:37:33 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-09-24 08:37:33 +0200
commit90614736f2a0c556f31eca5361b3c032f5f309f6 (patch)
tree81fda954dc2bff8ae8b0023b502343c455995272 /rideanalysis/analysis.go
parente3d0beee5be3dd2854b0f4fc10905a4fcdc08f47 (diff)
Match official climbs against their recorded sample
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.
Diffstat (limited to 'rideanalysis/analysis.go')
-rw-r--r--rideanalysis/analysis.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/rideanalysis/analysis.go b/rideanalysis/analysis.go
index bf3c2bb..81c9a98 100644
--- a/rideanalysis/analysis.go
+++ b/rideanalysis/analysis.go
@@ -17,6 +17,9 @@ const (
passCrossingElevationToleranceM = 25
)
+// PassMarginM is how far around a ride's track mountain passes are loaded for matching and display.
+const PassMarginM = 10_000
+
type Result struct {
Climbs []AnalyzedClimb
Crossings []mountain_pass.Crossing
@@ -27,6 +30,7 @@ type AnalyzedClimb struct {
Name string
Category string
DistanceM float64
+ ElevationGainM float64
SlopePercent float64
Cotacol float64
OfficialClimbID int64
@@ -42,7 +46,7 @@ func Analyze(parsed ride.Ride, passes []mountain_pass.MountainPass, officialClim
claimedClimbs := make([]AnalyzedClimb, 0)
claimedRanges := make([]geo.Interval, 0)
for _, official := range officialClimbs {
- for _, matched := range official_climb.MatchClimbs(parsed.Coords, official, matchPolicy.EndpointRadiusM) {
+ for _, matched := range official_climb.MatchClimbs(parsed.Route, official, matchPolicy.EndpointRadiusM) {
interval := geo.NewInterval(matched.StartIndex, matched.EndIndex)
claimedRanges = append(claimedRanges, interval)
claimedClimbs = append(claimedClimbs, analyzedClimb(routeClimb(parsed.Route, interval), interval, official.Name, official.ID))
@@ -81,11 +85,13 @@ func routeClimb(route climb.Route, interval geo.Interval) climb.Climb {
func analyzedClimb(segment climb.Climb, interval geo.Interval, name string, officialID int64) AnalyzedClimb {
cotacol := segment.DifficultyScore()
+ sample := segment.Sample(0, len(segment.Distances)-1)
return AnalyzedClimb{
Segment: segment,
Name: name,
Category: climb.CategoryOf(cotacol).String(),
- DistanceM: segment.Distances[len(segment.Distances)-1] - segment.Distances[0],
+ DistanceM: sample.DistanceM,
+ ElevationGainM: sample.ElevationGainM,
SlopePercent: climb.Slope(segment.Distances, segment.Elevations) * 100,
Cotacol: cotacol,
OfficialClimbID: officialID,