diff options
Diffstat (limited to 'ride/moving_time.go')
| -rw-r--r-- | ride/moving_time.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ride/moving_time.go b/ride/moving_time.go new file mode 100644 index 0000000..8403772 --- /dev/null +++ b/ride/moving_time.go @@ -0,0 +1,28 @@ +package ride + +import "time" + +const MovingTimeAlgorithmVersion = "v1" + +// movingTimeMinSpeedMps is the minimum implied speed between two consecutive +// track points for the interval to count as moving (1 km/h). +const movingTimeMinSpeedMps = 1.0 / 3.6 + +// Baseline backtest (356 rides, `-backtest`): mean err 3.9% (stderr 0.4), +// p50 1.6, p75 4.6, p90 8.4, p95 12.1, p99 44.9. +// Worst offenders overcount stationary GPS jitter (lunch stops) and +// undercount trainer rides with little GPS movement. Tuned in future commits. +func MovingTime(r Ride) time.Duration { + var moving time.Duration + for i := 1; i < r.Len(); i++ { + dt := r.Timestamp(i).Sub(r.Timestamp(i - 1)) + if dt <= 0 { + continue + } + dd := r.DistanceM(i) - r.DistanceM(i - 1) + if dd/dt.Seconds() > movingTimeMinSpeedMps { + moving += dt + } + } + return moving +}
\ No newline at end of file |
