Task group 2 (part a) of elevation-profile-hardening — wire the group-1 primitives into the headline stat and the chart. - computeElevation (parse.ts): despike each segment's elevation sequence, then take filteredTotals; gain/loss are now noise-filtered (no more 20–50% inflation from per-point jitter), the profile is built from the despiked data, and additive gainRaw/lossRaw expose the unfiltered sums. - elevationSeries: despike per segment (no cross-trkseg interpolation) before downsampling, so the chart and the headline totals derive from the same cleaned data. - types.ts: GpxData.elevation gains gainRaw/lossRaw (additive). Well-formed monotonic climbs are unchanged (steps exceed the 5 m threshold → filtered == raw); a shared noisy-track test proves jitter is filtered and a 300 m single-point spike is interpolated out of both the totals and the chart. Verified: gpx 111/111; full pnpm typecheck 13/13, lint 13/13, test 11/11 (journal + planner compile with the additive fields). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2.1 KiB
2.1 KiB
1. Cleaning primitives
- 1.1 Create
packages/gpx/src/elevation-clean.tswithdespike(points, opts?)— opposite-sign slope-outlier detection (defaultMAX_SLOPE_PERCENT = 100) with linear interpolation, operating per segment on{ distance, elevation }sequences - 1.2 Add
filteredTotals(points, opts?)to the same module — hysteresis accumulator (defaultNOISE_THRESHOLD_M = 5) returning{ gain, loss, gainRaw, lossRaw }with the raw-fallback rule (filtered zero + raw non-zero → report raw) - 1.3 Add
cumulativeFilteredTotals(points, opts?)returning per-point running filtered ascent/descent arrays (for per-day splits) - 1.4 Write
elevation-clean.test.ts: isolated spike interpolated; steep monotonic climb untouched; no cross-segment interpolation; ±2 m jitter → 0 totals; multi-leg climb counted fully; near-flat raw fallback; cumulative arrays sum to totals
2. Wire into existing computations
- 2.1 Update
computeElevationinpackages/gpx/src/parse.tsto despike per segment, then usefilteredTotals; keepgain/loss/profileshape and exposegainRaw/lossRawas additional fields (profile built from despiked data) - 2.2 Update
elevationSeriesinpackages/gpx/src/elevation-series.tsto build from despiked points (despike per segment before flattening) - 2.3 Update
compute-days.tsto build its cumulative ascent/descent arrays viacumulativeFilteredTotalsover the despiked track - 2.4 Update/extend existing tests (
parse.test.ts,elevation-series.test.ts,compute-days.test.ts) with a shared noisy-track fixture; assert chart series, totals, and day sums agree
3. Verification
- 3.1 Confirm no consumer changes needed: typecheck journal + planner; spot-check
gpx-save.server.ts, detail loaders, and plannercomputeDaysusage compile and behave - 3.2 Manual sanity check: parse a real noisy activity GPX (e.g. an existing import fixture) and compare gain before/after — filtered value should drop noticeably and match the chart
- 3.3 Run
pnpm typecheck && pnpm lint && pnpm testand the journal/planner e2e suites