diff --git a/backend/internal/store/migrations/0010_pace_artifact_filter.sql b/backend/internal/store/migrations/0010_pace_artifact_filter.sql
new file mode 100644
index 0000000..517647d
--- /dev/null
+++ b/backend/internal/store/migrations/0010_pace_artifact_filter.sql
@@ -0,0 +1,9 @@
+-- Filters brief pace "artifacts" (e.g. GPS/motion still settling right as
+-- recording starts, before the run itself begins) out of the Review
+-- Queue's pace chart: a stretch of samples slower than
+-- min_representative_pace_sec_per_km is dropped unless it persists for at
+-- least min_representative_time_seconds, in which case it's treated as a
+-- real stop or walk break, not noise. Defaults match the values used to
+-- design this feature (12:00/km, 3 seconds).
+ALTER TABLE profile ADD COLUMN min_representative_pace_sec_per_km REAL NOT NULL DEFAULT 720;
+ALTER TABLE profile ADD COLUMN min_representative_time_seconds REAL NOT NULL DEFAULT 3;
diff --git a/backend/internal/store/profile.go b/backend/internal/store/profile.go
index 89d9ffd..cec892a 100644
--- a/backend/internal/store/profile.go
+++ b/backend/internal/store/profile.go
@@ -32,6 +32,15 @@ type Profile struct {
// don't use these.
WarmupMinutes, CooldownMinutes float64
+ // MinRepresentativePaceSecPerKm/MinRepresentativeTimeSeconds drive the
+ // Review Queue pace chart's artifact filter: a stretch of samples slower
+ // than MinRepresentativePaceSecPerKm is dropped from the chart (and its
+ // Y-axis scale) unless it persists for at least
+ // MinRepresentativeTimeSeconds, in which case it's treated as a real
+ // stop or walk break rather than noise (e.g. GPS/motion still settling
+ // right as recording starts, before the run itself begins).
+ MinRepresentativePaceSecPerKm, MinRepresentativeTimeSeconds float64
+
CreatedAt, UpdatedAt string
}
@@ -41,6 +50,7 @@ const profileColumns = `
hr_zone3_min_pct, hr_zone3_max_pct, hr_zone4_min_pct, hr_zone4_max_pct,
hr_zone5_min_pct, hr_zone5_max_pct,
warmup_minutes, cooldown_minutes,
+ min_representative_pace_sec_per_km, min_representative_time_seconds,
created_at, updated_at
`
@@ -53,6 +63,7 @@ func (db *DB) GetProfile(ctx context.Context) (Profile, error) {
&p.HRZone3MinPct, &p.HRZone3MaxPct, &p.HRZone4MinPct, &p.HRZone4MaxPct,
&p.HRZone5MinPct, &p.HRZone5MaxPct,
&p.WarmupMinutes, &p.CooldownMinutes,
+ &p.MinRepresentativePaceSecPerKm, &p.MinRepresentativeTimeSeconds,
&p.CreatedAt, &p.UpdatedAt,
)
if err != nil {
@@ -72,6 +83,7 @@ func (db *DB) UpdateProfile(ctx context.Context, p Profile) error {
hr_zone3_min_pct=?, hr_zone3_max_pct=?, hr_zone4_min_pct=?, hr_zone4_max_pct=?,
hr_zone5_min_pct=?, hr_zone5_max_pct=?,
warmup_minutes=?, cooldown_minutes=?,
+ min_representative_pace_sec_per_km=?, min_representative_time_seconds=?,
updated_at=datetime('now')
WHERE id = 1`,
p.GarminEmail, p.GarminPassword, p.RollingWindowDays, p.BackfillHorizonDays, p.MaxHeartRate, p.RestingHeartRate,
@@ -79,6 +91,7 @@ func (db *DB) UpdateProfile(ctx context.Context, p Profile) error {
p.HRZone3MinPct, p.HRZone3MaxPct, p.HRZone4MinPct, p.HRZone4MaxPct,
p.HRZone5MinPct, p.HRZone5MaxPct,
p.WarmupMinutes, p.CooldownMinutes,
+ p.MinRepresentativePaceSecPerKm, p.MinRepresentativeTimeSeconds,
)
if err != nil {
return fmt.Errorf("update profile: %w", err)
diff --git a/backend/internal/store/profile_test.go b/backend/internal/store/profile_test.go
index 2433e7a..68e7628 100644
--- a/backend/internal/store/profile_test.go
+++ b/backend/internal/store/profile_test.go
@@ -25,6 +25,9 @@ func TestProfile_DefaultsThenUpdate(t *testing.T) {
if p.BackfillHorizonDays != 1095 {
t.Errorf("BackfillHorizonDays = %d, want 1095 (migration default)", p.BackfillHorizonDays)
}
+ if p.MinRepresentativePaceSecPerKm != 720 || p.MinRepresentativeTimeSeconds != 3 {
+ t.Errorf("pace artifact filter defaults = %+v, want pace=720, time=3", p)
+ }
maxHR, restingHR := 190.0, 50.0
p.GarminEmail = "runner@example.com"
@@ -34,6 +37,8 @@ func TestProfile_DefaultsThenUpdate(t *testing.T) {
p.RestingHeartRate = &restingHR
p.WarmupMinutes = 8
p.BackfillHorizonDays = 14
+ p.MinRepresentativePaceSecPerKm = 600
+ p.MinRepresentativeTimeSeconds = 5
if err := db.UpdateProfile(ctx, p); err != nil {
t.Fatalf("UpdateProfile: %v", err)
@@ -55,4 +60,7 @@ func TestProfile_DefaultsThenUpdate(t *testing.T) {
if got.BackfillHorizonDays != 14 {
t.Errorf("BackfillHorizonDays = %v, want 14", got.BackfillHorizonDays)
}
+ if got.MinRepresentativePaceSecPerKm != 600 || got.MinRepresentativeTimeSeconds != 5 {
+ t.Errorf("pace artifact filter after update = %+v, want pace=600, time=5", got)
+ }
}
diff --git a/frontend/src/components/charts/ExpectedVsActualChart.tsx b/frontend/src/components/charts/ExpectedVsActualChart.tsx
index be1cd31..fb8e9a9 100644
--- a/frontend/src/components/charts/ExpectedVsActualChart.tsx
+++ b/frontend/src/components/charts/ExpectedVsActualChart.tsx
@@ -1,17 +1,46 @@
import { Area, AreaChart, Line, ReferenceArea, ReferenceLine, ResponsiveContainer, Tooltip, XAxis, YAxis } from "recharts";
import type { Lap, Sample } from "../../types/api";
-// Speeds below this read as an implausibly slow "pace" (20:00/km is well
-// past even a very slow walk) -- in practice these come from GPS/motion
-// still settling right as recording starts, before the run itself begins,
-// not a real pace. Treating them as unknown keeps that artifact out of both
-// the trace and the axis scale it would otherwise blow out.
-const MAX_PLAUSIBLE_PACE_SEC_PER_KM = 1200;
-
function paceSecPerKm(mps: number | null): number | null {
if (mps == null || mps <= 0) return null;
- const pace = 1000 / mps;
- return pace <= MAX_PLAUSIBLE_PACE_SEC_PER_KM ? pace : null;
+ return 1000 / mps;
+}
+
+// Drops brief pace "artifacts" -- e.g. GPS/motion still settling right as
+// recording starts, before the run itself begins -- without hiding a real
+// stop or walk break. A stretch of consecutive points slower than
+// minRepresentativePaceSecPerKm (including points with no pace at all,
+// i.e. truly stationary) is nulled out unless it lasts at least
+// minRepresentativeTimeSeconds, in which case it's kept as-is: long enough
+// to be a real part of the run, not noise. A pace threshold of 0 (or below)
+// disables filtering entirely.
+function filterPaceArtifacts(
+ points: Array<{ t: number; pace: number | null }>,
+ minRepresentativePaceSecPerKm: number,
+ minRepresentativeTimeSeconds: number,
+): Array