diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-25 11:24:51 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-08-25 11:24:51 +0200 |
| commit | ff3cd6248f2b78dc76f1ce8cc2337907188fd401 (patch) | |
| tree | 59cb08531d7a7087a0a71c2306ce73330527c8d4 /ride/moving_time.go | |
| parent | 9c2337b50a52ee95011028f6193e0c56aa1fc9d4 (diff) | |
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.
Diffstat (limited to 'ride/moving_time.go')
| -rw-r--r-- | ride/moving_time.go | 18 |
1 files changed, 9 insertions, 9 deletions
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 |
