From ff3cd6248f2b78dc76f1ce8cc2337907188fd401 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Tue, 25 Aug 2026 11:24:51 +0200 Subject: Expose ride data as components and make algorithms consume only the slices they read Ride now exposes its columns as component getters (Distances, Elevations, Coords, Timestamps, and the optional Powers, Cadences, HeartRates) with the coords field unexported. difficultyScore, movingTime, Slope and the climb detection internals are pure functions over the specific slices they use, and Climb carries only the component slices it needs instead of a whole Ride. --- ride/moving_time.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'ride/moving_time.go') diff --git a/ride/moving_time.go b/ride/moving_time.go index 84cc28e..2ab07bf 100644 --- a/ride/moving_time.go +++ b/ride/moving_time.go @@ -19,25 +19,25 @@ const movingTimeMaxGap = 120 * time.Second // Bench (104 rides, `-backtest`, distance >= 10 km, moving/elapsed ratio >= 0.8): // absMean 0.4%, stderr 0.1, p50 0.2, p75 0.4, p90 0.8, p95 1.4, p99 2.9. func MovingTime(r Ride) time.Duration { - return movingTime(r, movingTimeMinSpeedMps, movingTimeMaxGap) + return movingTime(r.timestamps, r.distances, r.powers, r.cadences, movingTimeMinSpeedMps, movingTimeMaxGap) } -func movingTime(r Ride, minSpeedMps float64, maxGap time.Duration) time.Duration { +func movingTime(timestamps []time.Time, distances, powers, cadences []float64, minSpeedMps float64, maxGap time.Duration) time.Duration { var moving time.Duration - for i := 1; i < r.Len(); i++ { - dt := r.Timestamp(i).Sub(r.Timestamp(i - 1)) + for i := 1; i < len(timestamps); i++ { + dt := timestamps[i].Sub(timestamps[i-1]) if dt <= 0 || dt > maxGap { continue } - dd := r.DistanceM(i) - r.DistanceM(i-1) + dd := distances[i] - distances[i-1] gpsMoving := dd/dt.Seconds() > minSpeedMps powerMoving := false - if power, ok := r.PowerW(i); ok { - powerMoving = power >= movingTimeMinPowerW + if len(powers) > 0 { + powerMoving = powers[i] >= movingTimeMinPowerW } cadenceMoving := false - if cadence, ok := r.CadenceRpm(i); ok { - cadenceMoving = cadence > 0 + if len(cadences) > 0 { + cadenceMoving = cadences[i] > 0 } if gpsMoving || powerMoving || cadenceMoving { moving += dt -- cgit v1.3