feat(transit): add the TTC Toronto surface feed

TTC BusTime publishes keyless GTFS-Realtime VehiclePositions with real
coordinates for the surface network: ~1,180 buses and streetcars with
bearing and per-vehicle timestamps. Registering it is one registry row.

The subway is deliberately absent. BusTime covers surface vehicles only
and the subway publishes no positions, so Lines 1/2/4 are left out rather
than inferred from schedules — the same rule that keeps NYCT out.

Route numbers establish the mode: the three-digit 500-series is streetcar,
as are the four Blue Night routes on streetcar trackage. A leading 5 alone
would misclassify bus routes 50-59, so the rule is anchored and tested.

Licensing is the portal-wide Open Government Licence - Toronto; the CKAN
record for the BusTime NVAS dataset leaves its own licence field blank,
and the terms note says so rather than overstating the grant.

Refs #70
This commit is contained in:
Cliff Flood committed 2026-10-15 20:18:15 -04:00
1 parent a0400b52fb
commit c5f7fe285b
4 files changed
+91 -3

No files matched your search

+36
View File
@@ -115,6 +115,21 @@ function metroTransitRouteMode(routeId) {
return 'bus';
}
/**
* TTC BusTime is the SURFACE feed: buses and streetcars, never the subway.
* Streetcar routes are the 500-series, plus the four Blue Night routes that
* run on streetcar trackage (301 Queen, 304 King, 306 Carlton, 310 Spadina);
* the rest of the 300-series is night buses.
* @param {string|null} routeId
* @returns {string}
*/
function ttcRouteMode(routeId) {
if (!routeId) return 'unknown';
if (/^5\d\d$/.test(routeId)) return 'tram';
if (/^(301|304|306|310)$/.test(routeId)) return 'tram';
return 'bus';
}
/**
* Registry of feeds. Order is presentation order in the stats/credit text.
* `loadRadiusKm` is the distance from `center` inside which the feed is polled.
@@ -270,6 +285,27 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([
}),
defaultMode: 'bus',
}),
Object.freeze({
id: 'ttc-toronto',
name: 'TTC',
operator: 'Toronto Transit Commission',
region: 'Toronto, ON',
center: Object.freeze({ lat: 43.6532, lon: -79.3832 }),
loadRadiusKm: 45,
url: 'https://bustime.ttc.ca/gtfsrt/vehicles',
license: 'Open Government Licence \u2013 Toronto',
licenseUrl: 'https://open.toronto.ca/open-data-licence/',
attribution:
'Toronto Transit Commission \u2014 City of Toronto Open Data (Open Government Licence \u2013 Toronto)',
defaultEnabled: true,
terms: Object.freeze({
quote:
'The Information Provider grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the Information, including for commercial purposes ... Acknowledge the source of the Information by including any attribution statement specified by the Information Provider.',
note: 'The City publishes this endpoint from the TTC BusTime NVAS catalogue entry, whose own licence field reads \"License not specified\"; the quote above is the portal-wide Open Government Licence \u2013 Toronto the City applies to its open data, so the credit carries the licence name the way the Metro Transit entry carries its public-domain note. BusTime is the surface system: buses and streetcars report real positions, the subway reports none, so Lines 1/2/4 are simply absent rather than inferred. The endpoint sends no ETag or Last-Modified, so conditional requests fall through to the proxy snapshot TTL.',
}),
defaultMode: 'bus',
routeMode: ttcRouteMode,
}),
]);
/**
+50
View File
@@ -239,3 +239,53 @@ test('published transit history scope agrees with the catalog capability', () =>
/four fixes|0\.95x|guaranteed lower|one poll interval behind/,
);
});
test('the TTC feed is registered, routable, and covers Toronto', () => {
const ttc = getTransitFeed('ttc-toronto');
assert.equal(ttc?.url, 'https://bustime.ttc.ca/gtfsrt/vehicles');
assert.equal(ttc.defaultEnabled, true);
assert.match(ttc.attribution, /Toronto Transit Commission/);
assert.equal(ttc.historyRetention, undefined, 'no proxy retention');
assert.ok(
transitFeedsInRange(43.6532, -79.3832).some(
(feed) => feed.id === 'ttc-toronto',
),
'downtown Toronto is inside the load radius',
);
});
test('TTC route numbers tell a streetcar from a bus', () => {
// BusTime is the surface feed: 500-series are streetcar routes and the
// streetcar-operated Blue Night routes keep their own numbers. Everything
// else on this feed is a bus, so the mode is established, not defaulted.
const ttc = getTransitFeed('ttc-toronto');
assert.equal(transitModeFor(ttc, '501'), 'tram');
assert.equal(transitModeFor(ttc, '512'), 'tram');
assert.equal(transitModeFor(ttc, '304'), 'tram');
assert.equal(transitModeFor(ttc, '36'), 'bus');
// 52 Lawrence West is a bus. Only the three-digit 500-series is streetcar,
// so the rule must not match on a leading 5 alone.
assert.equal(transitModeFor(ttc, '52'), 'bus');
assert.equal(transitModeFor(ttc, '59'), 'bus');
assert.equal(transitModeFor(ttc, '900'), 'bus');
assert.equal(transitModeFor(ttc, '352'), 'bus');
assert.equal(transitModeResolved(ttc, '501'), true);
assert.equal(transitModeResolved(ttc, null), false);
assert.equal(
transitModeFor(ttc, null),
'bus',
'an unrouted vehicle falls back to the feed default, unresolved',
);
});
test('the TTC row records that BusTime carries no subway', () => {
const sources = readFileSync(
new URL('../../DATA_SOURCES.md', import.meta.url),
'utf8',
);
const row = sources.split('\n').find((line) => line.startsWith('| **TTC**'));
assert.ok(row, 'TTC has a DATA_SOURCES row');
assert.match(row, /Toronto/);
assert.match(sources, /surface vehicles \(buses and streetcars\) only/);
assert.match(sources, /Open Government Licence – Toronto/);
});