Contents
1. Summary
The index measures headway adherence: how long riders on a platform wait between trains, compared with the wait WMATA's regular timetableMTA's timetable promises. It does not measure whether a given train kept to its own scheduled time.
Each scheduled train at each platform is one slot. Every night, each slot of the day just ended is marked on time, late, missed or unobserved. A score for the whole system, a line or a station is the share of its observed slots that were on time:
on-time share = on time ÷ (on time + late + missed)
Every slot counts the same; there is no weighting by ridership.
2. Terms
- Service day
- A GTFS service date: the trains of one timetable day, from the first to the last, including those after midnight. Arrivals are read from 04:00 local time on the date to 04:00 the next morning.
- 04:00 to 04:00 local time, by arrival time. The subway runs all night, so trains from midnight to 4 am count toward the evening before.
- Line
- One of Metrorail's six lines: Red, Orange, Silver, Blue, Yellow and Green.
- A route as riders know it. Express trains fold into their local line (6X into 6, 7X into 7, FX into F), and the Z into the J. The shuttles (42 St, Franklin Av and Rockaway Park) and the Staten Island Railway are not scored: their trains count toward no line, station or the system.
- Platform
- A (line, direction, station) triple. Linked station complexes, such as Metro Center's upper and lower levelsTimes Sq-42 St with 42 St-Port Authority, or any other stations MTA links for transfers, count as one station. A station served by several lines has one platform per line and direction.
- Slot
- One scheduled train at one platform, with scheduled time
t. At a trip's first station the time is its departure; elsewhere its arrival. A trip's last station has no slot, since nobody boards there. - Scheduled gaps
- For slot
iat a platform,g_in(i) = t(i) − t(i−1)andg_out(i) = t(i+1) − t(i). The first slot has nog_in; the last slot'sg_outis itsg_in. - Slack
σ= 180 seconds: how much longer than scheduled a gap may run and still be on time.- Hole
- A stretch of time in which no data source could see a platform.
The code on this page is Python (3.10 or later, standard library only). Times are in seconds. It is a shorter copy of the code that scores the index and settles the markets, and gives the same results. All of it is in one file: methodology.py. These are the shared definitions:
from collections import defaultdict
from dataclasses import dataclass
from datetime import timedelta
from fractions import Fraction
from math import floor
SLACK = 180 # seconds a gap may run over and still be on time
@dataclass(frozen=True)
class Slot:
at: int # scheduled time, seconds
g_in: int | None # scheduled gap from the slot before (None for the first)
g_out: int | None # scheduled gap to the slot after (None for the last)
@dataclass(frozen=True)
class Train:
at: float # the time scored
source: str # "rt" (feed), "board" or "both"
trip_time: int | None = None # its trip's scheduled time here, if known
3. The baseline timetable
Slots come from MTA's planned-work timetable: its supplemented GTFS, which carries the week's track work. Track work MTA announces in time therefore does not count against MTA.
- Each evening the collector saves MTA's planned-work timetable. A day is scored against the newest copy saved in the 7 days before it. With none saved, it is scored against the regular timetable in force that day.
- Each date runs the trips the timetable's calendar lists for it, so a holiday gets the schedule MTA publishes for that date (Thanksgiving runs Sunday's).
- Since a day runs from 4 am to 4 am, its slots come from its own date's trips from 04:00 and the next date's trips before 04:00.
Slots come from WMATA's published static timetable (GTFS), not from the adjusted schedule WMATA runs on a given day. Planned track work therefore counts against WMATA.
- Each date has a day type: Monday to Thursday, Friday, Saturday, Sunday, or holiday (US federal holidays).
- For each line and day type, the regular schedule is the one the timetable runs on the most dates of that type. Schedules are compared by their stop times, not by trip or service ids. Track-work schedules run on only a few dates and lose the vote.
- A holiday is scored against the schedule WMATA published for that date.
- The baseline changes only when WMATA changes its regular timetable.
def slots(trips):
"""One day's slots, by platform: (line, direction, station).
trips: the day's trips from the timetable above, each with .line,
.direction and .stops (station, arrival, departure) in order.
"""
times = defaultdict(list)
for trip in trips:
for k, stop in enumerate(trip.stops[:-1]): # no slot at the last stop
t = stop.departure if k == 0 else stop.arrival
times[(trip.line, trip.direction, stop.station)].append(t)
out = {}
for platform, ts in times.items():
ts.sort()
out[platform] = [Slot(t,
g_in=t - ts[i - 1] if i > 0 else None,
g_out=ts[i + 1] - t if i + 1 < len(ts) else None)
for i, t in enumerate(ts)]
return out
4. Observed arrivals
The index scores the trains MTA's own live feeds show. MTA publishes the subway as eight GTFS-realtime feeds, each for a group of lines, and the collector polls each one every 15 seconds. New York has no station arrival boards to merge.
For each trip with a train on it, a feed lists the stops still ahead, each with a predicted time. A stop leaves the list once the train has reached it, and the collector then records one visit:
- Arrived: the feed showed the train stopped there (scored at the first such report), or the stop dropped off close to its predicted time (scored at that time). At a trip's first stop the train is scored at its departure.
- Passed unobserved: the stop dropped off far from its predicted time: a skipped stop, a reroute or a frozen prediction.
- Trip vanished: the trip left the feed before its train reached the stop.
Then, for each platform:
- Only arrived visits are trains. A passed-unobserved or vanished visit marks a time nobody saw, never a train: a train missing from the feed counts as missing data, not as a late train.
- Each trip's last stop is dropped. The same train under two trip ids at one platform within 300 seconds counts once.
- Each train is matched to its timetable trip, which gives its scheduled time at each stop (its trip identity, § 5.3). About three in four of a weekday's trains match; added and rerouted trains go without.
def observe(visits):
"""One platform's trains for one day, and the times of passes nobody
saw (New York).
visits: feed visits, already without each trip's last stop or a train
repeated under another trip id, with .at, .outcome and .trip_time.
"""
trains = [Train(v.at, "rt", v.trip_time) for v in visits if v.outcome == "arrived"]
unseen = [v.at for v in visits if v.outcome in ("passed_unobserved", "trip_vanished")]
return sorted(trains, key=lambda t: t.at), sorted(unseen)
Holes: a gap of 60 seconds or more in one of MTA's feeds is a hole for that feed's lines, and a stretch when the collector was not running is a hole for every line.
The index scores what a rider on the platform sees. Two sources are merged, and a train counts if either shows it:
- The train feed (WMATA's GTFS-realtime feed, polled every 5 seconds), as the collector records it: one visit per trip and stop.
- The station arrival boards (WMATA's "next train" predictions, polled every 10 seconds). A board arrival is the first poll showing a train as boarding (BRD) on that track, or the last poll showing it arriving (ARR) if BRD never follows. Line terminals show only a countdown, so departures there come from the feed alone.
Before the two are merged, each is cleaned:
- Feed visits count only if the train arrived, or departed from its trip's first stop (scored at its departure there). Each trip's last stop is dropped. A vehicle seen again at the same platform under another trip within 300 seconds is one train.
- Each board train gets its direction from its track. On single-tracking days a train can run the wrong way down a track, so if its destination lies only the other way down the line, the direction comes from the destination. A train whose destination is this station is dropped.
- A
passed_unobservedvisit is a stop the feed says a train passed without seeing it there. If the boards saw a train at about that time, that is the train; otherwise it marks a stretch nobody saw.
Then, for each platform:
BOARD_LAG = 14 # median seconds from arrival to the board showing BRD
PAIR_WINDOW = 120 # feed and board arrivals further apart are different trains
UNSEEN_PASS = (-300, 30) # a board train this near a passed_unobserved visit is that train
def merge(visits, board_times):
"""One platform's trains for one day, and the times of passes nobody saw.
visits: feed visits, already without each trip's last stop or a vehicle
repeated under another trip, with .at, .outcome and .trip_time.
board_times: when the boards first showed each train boarding here.
"""
seen = [v for v in visits if v.outcome != "passed_unobserved"]
passes = [v for v in visits if v.outcome == "passed_unobserved"]
# Pair feed and board arrivals one to one, nearest first.
pairs = sorted((abs(b - v.at), i, j) for i, v in enumerate(seen)
for j, b in enumerate(board_times) if abs(b - v.at) <= PAIR_WINDOW)
used_v, used_b, trains = set(), set(), []
for _, i, j in pairs:
if i not in used_v and j not in used_b:
used_v.add(i)
used_b.add(j)
trains.append(Train(seen[i].at, "both", seen[i].trip_time))
trains += [Train(v.at, "rt", v.trip_time)
for i, v in enumerate(seen) if i not in used_v]
board_only = [Train(b - BOARD_LAG, "board")
for j, b in enumerate(board_times) if j not in used_b]
# A passed_unobserved visit is a train if the boards saw it, else a hole.
unseen = []
for p in passes:
near = [b for b in board_only if UNSEEN_PASS[0] <= b.at - p.at <= UNSEEN_PASS[1]]
if near:
b = min(near, key=lambda b: abs(b.at - p.at))
board_only.remove(b)
trains.append(Train(b.at, "board", p.trip_time))
else:
unseen.append(p.at)
trains += board_only
return sorted(trains, key=lambda t: t.at), sorted(unseen)
Holes: the collector logs when the feed and the board polling were down. At a platform the boards show, a hole is a stretch when both were down. At a platform no board covers, such as a line terminal, a hole is any stretch when the feed was down.
5. Scoring a platform
Slots at a platform are walked in time order alongside the trains seen there. The walk keeps a base: the time of the last train that served a slot. A slot is due by its deadline:
deadline(i) = base + gin(i) + σ
For the day's first slot, or the first after a hole, there is no base and the deadline is t(i) + σ. So the first train of the day is on time if it comes within 3 minutes of its scheduled time.
5.1 The four outcomes
- On time: the next unused train arrives by the deadline. Extra wait 0.
- Late: it arrives after the deadline but by deadline + gout. Extra wait = arrival − deadline.
- Missed: no train by then. It counts as late, with extra wait gout, and the base moves forward one scheduled gap. A long outage thus counts once for every scheduled train that should have come during it.
- Unobserved: the stretch since the last slot's
window overlaps a hole, or holds a pass nobody saw (
unseen). The slot is left out of the score, and the next train starts a new base. Right after a hole the stretch reaches back to when the slot before was due, so a train due during the hole never counts as late.
5.2 The code
def score_platform(slots, trains, holes=(), unseen=(), slack=SLACK):
"""One (status, extra wait in seconds) per slot at one platform.
slots and trains in time order; holes: (start, end) stretches no source
could see; unseen: times of passes nobody saw.
"""
t = [s.at for s in slots]
own = {s.at: i for i, s in enumerate(slots)} # each slot's index by its time
results = []
base = None # when the last serving train came
prev = t[0] - 1800 if t else 0 # end of the last slot's window
k = 0 # the next unused train
drift = 0 # missed slots not yet caught up
for i, slot in enumerate(slots):
g_in = slot.g_in or 0
g_out = slot.g_out if slot.g_out is not None else g_in
def due():
return t[i] + slack if base is None else base + g_in + slack
deadline = due()
# After a missed slot, a bunched train moves the base but serves no slot.
while drift and k < len(trains) and bunched_extra(trains[k], i, t, own):
base = trains[k].at
k += 1
drift -= 1
deadline = due()
end = deadline + g_out
c = trains[k] if k < len(trains) and trains[k].at <= end else None
if c and i + 1 < len(t) and c.at > t[i + 1] + slack:
c, end = None, max(deadline, t[i + 1] + slack) # it belongs to a later slot
d = c.at if c else end
# Right after a hole, reach back to when the slot before was due.
start = prev if base is not None else min(prev, t[i] - g_in)
if overlaps(holes, start, d) or any(start < u <= d for u in unseen):
results.append(("unobserved", None))
base, drift = (c.at if c else None), 0
elif c and c.at <= deadline:
results.append(("on_time", 0))
base = c.at
elif c:
results.append(("late", round(c.at - deadline)))
base = c.at
else:
results.append(("missed", g_out))
base = t[i] if base is None else base + g_in
drift += 1
# A train due at the next slot may serve that one too, so it isn't used up.
if c and own.get(c.trip_time) != i + 1:
k += 1
prev = d
return results
def bunched_extra(train, i, t, own):
"""Whether a train is the extra a missed slot left behind."""
if train.at >= t[i]:
return False # not early for this slot: let it serve
if own.get(train.trip_time) is not None:
return own[train.trip_time] < i
return i > 0 and train.at < t[i - 1] # no trip identity: early for the slot before
def overlaps(holes, a, b):
return any(h0 < b and h1 > a for h0, h1 in holes)
5.3 Keeping trains paired with their slots
The walk uses the feed's trip identity (each trip's scheduled time at this platform) so that a cancelled or bunched train does not leave every later train judged against the wrong scheduled gap:
- A train whose own slot is the next one is not used up when it serves the current slot: everyone waiting boards it, and it may serve its own slot too.
- After a missed slot, a train is a bunched extra if it came before the current slot's scheduled time and belongs to an earlier slot (by trip identity; for a train with no identity, such as a board-only train,one not matched to a timetable trip, if it came before the previous slot's scheduled time). It moves the base, as any train a rider sees does, but serves no slot. Each missed slot allows one such skip.
- A train arriving after the next slot is due (t(i+1) + σ) belongs to a later slot, so the current slot is missed and the train is kept. This keeps the walk in step on track-work days, when trains run less often than the timetable says.
The code for these is in score_platform and
bunched_extra above. On a day when every train serves its own slot, these rules change
nothing.
6. Scores and coverage
Slot results roll up to three scopes: the whole system, each line, and each station. Each slot counts toward all three; a slot is not averaged within its line or station first. For a scope X:
on-time share(X) = on time ÷ observed coverage(X) = observed ÷ slots
@dataclass
class Tally:
slots: int = 0
observed: int = 0
on_time: int = 0
extra_wait: int = 0 # seconds
@property
def share(self): # the on-time share
return Fraction(self.on_time, self.observed)
@property
def coverage(self):
return Fraction(self.observed, self.slots)
def roll_up(results):
"""{(line, direction, station): [(status, extra)]} -> {scope: Tally}, where a
scope is "system", ("line", line) or ("station", station)."""
out = defaultdict(Tally)
for (line, _, station), rs in results.items():
for status, extra in rs:
for scope in ("system", ("line", line), ("station", station)):
x = out[scope]
x.slots += 1
if status != "unobserved":
x.observed += 1
x.on_time += status == "on_time"
x.extra_wait += extra
return out
Total extra wait equals the sum, over every gap that ran long, of the actual gap less the allowed gap. The Results and History pages show it per late train: total extra wait ÷ (late + missed). Ties in settlement go by the total (§ 7).
New York's stations are scored too, but have no markets.
DC's stations are scored and shown on the History page, but no longer have markets.
7. Settlement
Each market settles on the scores of its day. Comparisons use the exact counts, not rounded percentages. Each day has three markets: best line, worst line, and which range the system's on-time share lands in (under 80%, 80 to 88%, 88 to 91%, and 91% and upunder 78%, 78 to 82%, 82 to 84%, and 84% and up, set from the first ten days of scores).
MIN_COVERAGE = Fraction(9, 10)
def covered(tally):
return tally is not None and tally.slots > 0 and tally.coverage >= MIN_COVERAGE
def result(market, scores):
"""(winners, void outcomes), or None if the market is called off.
market.kind is "line", "station" or "range"; market.pick "best" or
"worst"; a range outcome has .low and .high (None for open ends).
"""
if not covered(scores["system"]):
return None
if market.kind == "range":
p = 100 * scores["system"].share
return [o for o in market.outcomes
if (o.low is None or p >= o.low) and (o.high is None or p < o.high)], set()
live = {o: scores[(market.kind, o)] for o in market.outcomes
if covered(scores.get((market.kind, o)))}
sign = 1 if market.pick == "best" else -1
# Highest share wins a best market; ties go to the least extra wait (most, for worst).
rank = {o: (sign * x.share, -sign * x.extra_wait) for o, x in live.items()}
top = max(rank.values(), default=None)
return [o for o in live if rank[o] == top], set(market.outcomes) - set(live)
def payouts(stakes, outcome):
"""Points back to each player, from [(player, outcome, points)] stakes
with the house seed among them. Rounding leaves the rest to the house."""
back = defaultdict(int)
if outcome is None: # called off: every stake back
for player, _, points in stakes:
back[player] += points
return back
winners, void = outcome
live = []
for player, o, points in stakes:
if o in void:
back[player] += points # under 90% coverage: refunded
else:
live.append((player, o, points))
backed = {o for _, o, _ in live if o in winners}
if not backed: # nobody backed a winner
for player, _, points in live:
back[player] += points
return back
pool = sum(points for _, _, points in live)
on = {w: sum(p for _, o, p in live if o == w) for w in backed}
owed = defaultdict(Fraction)
for player, o, points in live:
if o in backed: # each backed winner: an equal part of the pool
owed[player] += Fraction(pool * points, len(backed) * on[o])
for player, x in owed.items():
back[player] += floor(x)
return back
A day's settlement uses the index run in place when the day first settles. A later re-score of that day never changes what was paid.
8. The house forecast
The house seeds each pool with 1,000 points, split across outcomes by a naive forecast built from the same rules that settle the market.
def forecast(market, day, as_of, scored, group_of,
window=30, weights=(Fraction(1, 2), Fraction(1, 2))):
"""The house's chance for each outcome of market on day, from the days
scored in the window before as_of (when the market opens).
scored: {date: scores}; group_of(date): "weekday", "weekend" or "holiday".
"""
won = {}
for n in range(window, 0, -1):
past = as_of - timedelta(days=n)
if past not in scored:
continue
r = result(market, scored[past])
if r and r[0]: # a day some outcome won
won[past] = {o: Fraction(o in r[0], len(r[0])) for o in market.outcomes}
group = [d for d in won if group_of(d) == group_of(day)]
weekday = [d for d in group if d.weekday() == day.weekday()]
halves = [(w, ds) for w, ds in zip(weights, (group, weekday)) if w and ds]
if not halves:
if not won:
return {o: Fraction(1, len(market.outcomes)) for o in market.outcomes}
halves = [(1, list(won))]
total = sum(w for w, _ in halves)
return {o: sum(w / total * Fraction(sum(won[d][o] for d in ds), len(ds))
for w, ds in halves)
for o in market.outcomes}
def seed(chances, total=1000):
"""Whole points per outcome by chance: largest remainder, ties to the earlier."""
exact = [c * total for c in chances]
points = [floor(x) for x in exact]
order = sorted(range(len(exact)), key=lambda i: (points[i] - exact[i], i))
for i in order[:total - sum(points)]:
points[i] += 1
return points
9. Parameters
| Name | Value | Used in |
|---|---|---|
Slack σ | 180 s | § 5 |
| Board lag | 14 s | § 4 |
| Feed and board pairing window | 120 s | § 4 |
| Same-train repeat window | 300 s | § 4 |
| Unseen-pass match window | −300 to +30 s | § 4 |
| Feed polling | every 15 s | § 4 |
| Feed gap that makes a hole | 60 s | § 4 |
| Day boundary | 04:00 | § 2 |
| Minimum coverage | 90% | § 7 |
| System range edges | 80, 88, 91% | § 7 |
| System range edges | 78, 82, 84% | § 7 |
| House seed | 1,000 pts | § 8 |
| Forecast window and weights | 30 days, ½ and ½ | § 8 |
10. Records and re-scoring
- Each night's run records its slack, method version, timetable version, code commit and a fingerprint of the exact collector data read.
- Observed arrivals are kept, so any past period can be re-scored under a different slack. Each re-score is a new run; days already paid stay paid.
- Stop visits are kept forever. Raw feed and board data are kept for at least 90 days after settlement.
- Each train's result stays in New York's own index database; the game reads its line and system scores.
- WMATA's own monthly on-time figure is a cross-check, not a settlement source.