From d26aa2dca1b14b7d52070825bfc73c5e8aed7a16 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Fri, 21 Aug 2026 11:04:57 +0200 Subject: refactor(ride,rideanalysis): replace magic numbers with named constants --- ride/ride.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'ride/ride.go') diff --git a/ride/ride.go b/ride/ride.go index 278880f..a10d8a2 100644 --- a/ride/ride.go +++ b/ride/ride.go @@ -230,6 +230,10 @@ func metricValue(point gpx.GPXPoint, name string) (*float64, error) { const CotacolAlgorithmVersion = "v1" +// cotacolSegmentLengthM is the fixed length of the elevation segments the +// Cotacol score is computed over. +const cotacolSegmentLengthM = 100 + func Cotacol(ride Ride) float64 { return difficultyScore(ride, 0, ride.Len()-1) } @@ -245,8 +249,8 @@ func difficultyScore(r Ride, startIndex, endIndex int) float64 { } cotacol := 0.0 i := startIndex - for start := startDistance; start < lastDistance; start += 100 { - end := math.Min(start+100, lastDistance) + for start := startDistance; start < lastDistance; start += cotacolSegmentLengthM { + end := math.Min(start+cotacolSegmentLengthM, lastDistance) for i < endIndex && r.DistanceM(i+1) <= start { i++ } -- cgit v1.3