Skip to content

Use TransitMatters benchmark as replacement for MBTA on travel-time chart#1157

Open
devinmatte wants to merge 3 commits intomainfrom
tm-travel-time-benchmark-chart
Open

Use TransitMatters benchmark as replacement for MBTA on travel-time chart#1157
devinmatte wants to merge 3 commits intomainfrom
tm-travel-time-benchmark-chart

Conversation

@devinmatte
Copy link
Copy Markdown
Member

@devinmatte devinmatte commented Apr 17, 2026

Summary

Where we have enough historical data, the travel-time chart now uses the TransitMatters benchmark in place of the MBTA scheduled benchmark — one band, not two. Dot colors (on-time / 25%+ off / etc.) are computed against whichever benchmark applies to that point. When TM data is missing (bus, CR, a stop pair with <1 year of history), the chart transparently falls back to the MBTA value.

The legend header swaps "MBTA benchmark:" for "TransitMatters benchmark:" when the chart has any TM-derived points. Tooltip labels each point's benchmark honestly — a TM-mode chart can still show "MBTA Benchmark" on individual points that fell back. Departure-from-normal text switches from "25%+ over schedule" to "25%+ over benchmark" on TM-mode charts.

Depends on mbta-performance #85 producing the per-line JSON files this reads.

Changes

  • Backendserver/chalicelib/tm_benchmarks.py lazily loads Benchmarks-tm/traveltimes/{Color}.json per line (module-level cache, refreshed when the Lambda container recycles). s3_historical.travel_times() attaches tm_benchmark_travel_time_sec to each record. Existing policy already covers the new S3 prefix.
  • Chart — effective benchmark per point is tm[i] ?? mbta[i]. That value drives both the gray benchmark band and the dot-color thresholds. Dataset label swaps between "TransitMatters Benchmark" and "MBTA Benchmark" so native Chart.js elements name the right source.
  • Tooltip — per-point label names the actual benchmark source used for that point; "over schedule" → "over benchmark" when the chart is TM-mode.
  • Legend — "Compare to … MBTA benchmark:" → "Compare to … TransitMatters benchmark:" when TM is in use. Otherwise unchanged.

Scope

Travel times, rapid transit only. Other single-day charts (headways, dwells) and non-rapid-transit routes keep the MBTA benchmark unchanged, including the "over schedule" tooltip wording.

Test plan

  • Blocked on #85 merging and the benchmark JSONs landing in S3.
  • Davis → Kendall / Alewife → Ashmont: confirm the gray band sits visibly below the prior MBTA value on lines with current speed restrictions.
  • Bus / CR: confirm chart looks identical to main (no regression; legend still says "MBTA benchmark").
  • Confirm dot colors follow the new (stricter) benchmark for TM points and the MBTA benchmark for fallback points.
  • Hover a TM-mode chart: tooltip should say "TransitMatters Benchmark: 9m 30s" with "25%+ over benchmark" text.
  • Hover a non-TM chart: unchanged wording ("MBTA Benchmark", "over schedule").

Backend: read the new Benchmarks-tm/traveltimes/{Color}.json produced by
mbta-performance (cached per-color in-process) and attach
tm_benchmark_travel_time_sec to each travel-time record.

Frontend: render a dashed TM-red line on the single-day travel-time chart at
per-point min(tm_historic, mbta_benchmark), so when MBTA is faster the two
lines overlap and the TM line visually disappears. When a trip beats both
benchmarks the dot is surrounded by a subtle pulsing emerald ring (with a
2s pause between pulses to keep the animation cheap). Rename the existing
"Benchmark MBTA" label to "MBTA Benchmark" for consistency.

Legend gains "TransitMatters benchmark" and "Beat both benchmarks" entries,
only shown when tm_benchmark data is present (rapid transit only).
@github-actions github-actions bot added backend Change to backend code frontend Change to frontend code labels Apr 17, 2026
After design review, drop the dual-line / shiny-dot design. Instead of
rendering a second TransitMatters line, the single benchmark band now uses
the TM historical value per-point where we have >= 1 year of data, and
falls back to the MBTA scheduled value otherwise. Dot colors (green/yellow/
red/purple) are computed against whichever benchmark applies to that point.

Legend header now says "Compare to ... benchmark:" (no longer "MBTA
benchmark:") with a small emerald info pill appearing beside it when the
chart has any TM-benchmark points, carrying a tooltip that explains what
TransitMatters benchmarks are and when they apply. Removed the
"TransitMatters benchmark" and "Beat both benchmarks" legend rows, the
dashed red line, the gold/emerald dot borders, and the shinyPoints
animation plugin.
@devinmatte devinmatte changed the title Show TransitMatters benchmark alongside MBTA on travel-time chart Use TransitMatters benchmark as replacement for MBTA on travel-time chart Apr 19, 2026
- Tooltip shows "TransitMatters Benchmark" or "MBTA Benchmark" per point
  based on which source was used (a TM-mode chart may still fall back to
  MBTA on pairs with insufficient history).
- Dataset label switches accordingly so Chart.js's built-in legend names
  the correct benchmark.
- Departure-from-normal text says "over benchmark" when the chart uses
  the TM benchmark, and keeps the existing "over schedule" wording
  everywhere else.
- Legend header swaps "MBTA benchmark:" for "TransitMatters benchmark:"
  when the TM value is in use — no info pill, no other layout changes.
@devinmatte devinmatte marked this pull request as ready for review April 19, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Change to backend code frontend Change to frontend code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant