aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-20 17:23:34 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-20 17:23:34 +0200
commit8af7f81622ce5505f4c29ac24d63f4261e845f52 (patch)
treeb77d82357de04efecf22c74e8a1b10df19dd041d
parent862f71901c3e11f9d21a33b39a110357ccc6d4c4 (diff)
chore(bench): exclude short rides
-rw-r--r--cli/cli.go13
-rw-r--r--cli/cli_test.go9
-rw-r--r--ride/moving_time.go4
3 files changed, 19 insertions, 7 deletions
diff --git a/cli/cli.go b/cli/cli.go
index d3aff22..4459946 100644
--- a/cli/cli.go
+++ b/cli/cli.go
@@ -32,6 +32,8 @@ var (
backtest = flag.Bool("backtest", false, "run data benchmarks comparing computed values against stored reference values")
)
+const backtestMinimumElapsedTimeS = 15 * 60
+
func Run(db *sql.DB, configPath string, appConfig config.Config) {
switch {
case *download:
@@ -84,7 +86,7 @@ func runBacktest(db *sql.DB) error {
if i > 0 && i%50 == 0 {
slog.Info("Backtest progress", "processed", i, "total", len(items))
}
- if item.GPXPath == "" {
+ if !isBacktestEligible(item) {
continue
}
parsed, err := ride.ParseFile(ride.GPXRideParser{}, item.GPXPath)
@@ -93,9 +95,6 @@ func runBacktest(db *sql.DB) error {
continue
}
reference := time.Duration(item.MovingTimeS) * time.Second
- if reference <= 0 {
- continue
- }
computed := ride.MovingTime(parsed)
samples = append(samples, backtestSample{
externalID: item.ExternalID,
@@ -135,10 +134,14 @@ func runBacktest(db *sql.DB) error {
fmt.Fprintf(table, "p%g\t%.1f\n", p, distribution[p])
}
table.Flush()
- slog.Info("Moving time backtest", "rides", len(samples), "mean_err_pct", math.Round(meanAbsErr(absErrors)*10)/10, "stderr_pct", math.Round(stdErrAbsErr(absErrors)*10)/10)
+ slog.Info("Moving time backtest", "rides", len(samples), "min_elapsed_s", backtestMinimumElapsedTimeS, "mean_err_pct", math.Round(meanAbsErr(absErrors)*10)/10, "stderr_pct", math.Round(stdErrAbsErr(absErrors)*10)/10)
return nil
}
+func isBacktestEligible(item rides.Ride) bool {
+ return item.GPXPath != "" && item.ElapsedTimeS >= backtestMinimumElapsedTimeS && item.MovingTimeS > 0
+}
+
func meanAbsErr(absErrors []float64) float64 {
var sum float64
for _, err := range absErrors {
diff --git a/cli/cli_test.go b/cli/cli_test.go
index 8290bce..ae59c6c 100644
--- a/cli/cli_test.go
+++ b/cli/cli_test.go
@@ -3,9 +3,18 @@ package cli
import (
"testing"
+ "github.com/martinlehoux/biking_home/rides"
"github.com/stretchr/testify/assert"
)
+func TestBacktestEligibilityExcludesShortRides(t *testing.T) {
+ short := rides.Ride{GPXPath: "ride.gpx", ElapsedTimeS: 15*60 - 1, MovingTimeS: 1}
+ minimum := rides.Ride{GPXPath: "ride.gpx", ElapsedTimeS: 15 * 60, MovingTimeS: 1}
+
+ assert.False(t, isBacktestEligible(short))
+ assert.True(t, isBacktestEligible(minimum))
+}
+
func TestBacktestStatsUseUnroundedSamples(t *testing.T) {
absErrors := []float64{0, 0.1, 0.1}
diff --git a/ride/moving_time.go b/ride/moving_time.go
index c98e6b1..9ac6c05 100644
--- a/ride/moving_time.go
+++ b/ride/moving_time.go
@@ -16,8 +16,8 @@ const movingTimeMinPowerW = 20
// that can count as moving. Longer gaps are pauses (stops, lost signal).
const movingTimeMaxGap = 120 * time.Second
-// Bench (356 rides, `-backtest`):
-// absMean 2.4%, stderr 0.2, p50 0.7, p75 2.9, p90 6.7, p95 9.6, p99 19.9.
+// Bench (237 rides, `-backtest`, elapsed time >= 15 minutes):
+// absMean 2.4%, stderr 0.3, p50 0.6, p75 2.9, p90 7.1, p95 10.7, p99 19.9.
func MovingTime(r Ride) time.Duration {
return movingTime(r, movingTimeMinSpeedMps, movingTimeMaxGap)
}