From c5f7fe285b340627c6e191857c5096d49c20482e Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Tue, 15 Sep 2026 23:43:44 -0400 Subject: [PATCH 01/12] feat(transit): add the TTC Toronto surface feed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- DATA_SOURCES.md | 3 +- docs/CURRENT-STATE.md | 5 ++-- src/data/transitFeeds.js | 36 ++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 50 ++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 3 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 8f3b55dbf..463034e97 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -77,6 +77,7 @@ How to read this: | **Entur** (api.entur.io) | Transit layer live vehicles, Norway | Entur open realtime vehicle data, used for the live view; published for developer use and not against their use. The client sends the `ET-Client-Name` identifying header. | Attribution to Entur (courtesy text) | | **TransLink** (Queensland Government) | Transit layer live vehicles, South East Queensland | TransLink / Queensland Government open realtime vehicle data, used for the live view; published for developer use and not against their use. | Attribution to TransLink / Queensland Government (courtesy text) | | **HSL** (realtime.hsl.fi) | Transit layer live vehicles, Helsinki | HSL (Helsinki Region Transport) open realtime vehicle data, used for the live view; published for developer use and not against their use. | Attribution to HSL (Helsinki Region Transport) (courtesy text) | +| **TTC** (bustime.ttc.ca) | Transit layer live vehicles, Toronto — surface vehicles (buses and streetcars) only | Toronto Transit Commission BusTime open realtime vehicle data, published through City of Toronto Open Data and used for the live view. The subway publishes no vehicle positions, so Lines 1/2/4 are absent rather than inferred. | Attribution to Toronto Transit Commission — City of Toronto Open Data, under the Open Government Licence – Toronto | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OSRM on the FOSSGIS routing servers** (`routing.openstreetmap.de`) | Street-following routes for the Directions layer and voice route annotations, via `/api/route` | [FOSSGIS routing usage policy](https://routing.openstreetmap.de/about.html): "Display the required attribution and display a link to 'fix the map'", "Use a valid user agent and, if applicable, a correct referrer", "One request per second max", "No scraping, no heavy usage". The full policy is the German [FOSSGIS Nutzungsbedingungen](https://www.fossgis.de/arbeitsgruppen/osm-server/nutzungsbedingungen/); FOSSGIS also states that the server may be embedded in your own pages but "eine gewerbliche Nutzung ist nur mit Einschränkungen erlaubt" (commercial use only with restrictions). Route data derives from OpenStreetMap (ODbL 1.0) | "Routing: OSRM on the FOSSGIS servers" + a "fix the map" link — shown in the Data attribution popover | @@ -155,7 +156,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **NYC DOT Traffic Management Center cameras.** Off by default. NYC DOT's [developer data feeds page](https://www.nyc.gov/html/dot/html/about/datafeeds.shtml) asks developers who want the camera feed to contact `tmcdot@dot.nyc.gov` and sign a data-sharing agreement. This project does not hold one that covers downstream installations, so the pack loads only when an operator who holds their own agreement sets `CCTV_NYC_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to NYC DOT. The endpoint needs no key. The camera list is the public `webcams.nyctmc.org/api/cameras` catalog (~980 cameras across the five boroughs); frames are stills at `webcams.nyctmc.org/api/cameras//image`, synthesized from a validated UUID rather than taken from the payload, and only that host is registered. Cameras the feed reports as offline are dropped. The catalog publishes no camera facing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. Once enabled, the 250 cameras nearest the borough cores load; `CCTV_NYC_MAX_SOURCES` (8–400) changes the cap. Frames are fetched at request time and never stored or redistributed. NYC DOT asks every application that uses its data to carry its disclaimer; it is registered verbatim in the Data attribution popover. - **City of Toronto RESCU cameras.** Keyless. The camera list is the City's public `tmcearthcameras.json` on `opendata.toronto.ca` (dataset "Traffic Cameras", Transportation Services), served as JSONP and unwrapped with an anchored pattern. This is the municipal network the Ontario 511 pack does not carry: downtown arterials plus the Gardiner, DVP, Allen and Lake Shore. The list publishes no frame URL, so frame URLs are BUILT from the documented `CameraImages/loc####.jpg` convention and a strictly-digits camera number, pinning the frame proxy to the portal origin by construction; the list fetch refuses redirects and bounds the body it buffers. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `D1`-`D4` fields are the directions of the *comparison* images (static reference stills captured in 2016 under a different path), not a bearing for the live pan-tilt-zoom frame, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. A camera that is temporarily out of service still answers 200 with a byte-identical "Image Unavailable" placeholder rather than an error (about 6% of the network at any moment), so such a camera reads as healthy; the frame it shows is the agency's, not a synthesized one. The licence requires the attribution statement above. Disable with `CCTV_TORONTO_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All seven registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All eight registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. - **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. - **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app). - **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 0af075a6d..68530ffae 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3659,8 +3659,9 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Seven keyless regions are available: Boston, Austin, Minneapolis–St Paul, -Helsinki, the Netherlands, Norway and South East Queensland. Mode silhouettes +gate. Eight keyless regions are available: Boston, Austin, Minneapolis–St Paul, +Helsinki, the Netherlands, Norway, South East Queensland and Toronto (TTC +surface vehicles; the subway publishes no positions). Mode silhouettes identify buses, trams, subways, trains, ferries and unclassified vehicles. Retained transit history uses the same outlier quarantine as live observations and diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 2858efa62..10d087747 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -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, + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index d0e38524f..1f364b924 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -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/); +}); From 9fc4a5ac04d2bcf0265d8ca6cdbd2b82cffe87f9 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Tue, 15 Sep 2026 23:58:51 -0400 Subject: [PATCH 02/12] feat(transit): let a feed name its own modes, and call TTC trams streetcars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Toronto 501 and a Helsinki 1010 are both the `tram` mode. Only one of them is called a tram by the people who ride it, and the detection label is documented as "what a person standing at the stop would call it". So the mode stays shared — same silhouette, same speed limits — and a registry entry may carry `modeWords` naming the modes it runs. Everything without an override falls through to the shared table, so this renames one word for one operator and nothing else. Threading the feed to the detection metric needed a resolver in queries.js, since the cached-contact path has only the entry. It answers from live feeds first, so a feed disabled mid-session stops supplying vocabulary. --- src/data/transitFeeds.js | 6 +++ src/layers/transit/policy.js | 46 +++++++++++++++++++++-- src/layers/transit/queries.js | 30 ++++++++++++--- src/layers/transit/vocabulary.test.mjs | 52 ++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 9 deletions(-) create mode 100644 src/layers/transit/vocabulary.test.mjs diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 10d087747..5cbdac82d 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -304,6 +304,12 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ 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', + // Toronto rides streetcars. The vehicles are the shared `tram` mode and + // share its silhouette and speed limits; only the word a reader sees + // changes, because "tram" is not what anyone at Queen and Spadina says. + modeWords: Object.freeze({ + tram: Object.freeze({ word: 'Streetcar', abbr: 'STREETCAR' }), + }), routeMode: ttcRouteMode, }), ]); diff --git a/src/layers/transit/policy.js b/src/layers/transit/policy.js index b672581bb..33352bf2d 100644 --- a/src/layers/transit/policy.js +++ b/src/layers/transit/policy.js @@ -345,7 +345,7 @@ export function buildTransitSelectionCopy( // The mode is said in words on its own line. A glyph and a route id do not // tell a reader that the dot on Tremont Street is a subway train, and a // subway drawn on a street reads as a bug until the card says what it is. - const kindWord = TRANSIT_MODE_WORD[mode] || TRANSIT_MODE_WORD.unknown; + const kindWord = transitModeWord(mode, feed); const details = [`${kindWord} · ${feed.name} · ${feed.region}`]; const motion = []; // What the SCREEN is doing leads, because that is what the reader can check. @@ -479,6 +479,37 @@ export const TRANSIT_MODE_ABBR = Object.freeze({ unknown: 'TRANSIT', }); +/** + * The mode in the operator's own vocabulary. A Toronto 501 and a Helsinki 1010 + * are both the `tram` mode, but only one of them is called a tram by the people + * who ride it. A feed may name the modes it runs; everything else falls through + * to the shared table, so an override renames one word and nothing else. + * @param {string} mode Resolved transit mode. + * @param {object|null} [feed] Registry entry. + * @returns {string} + */ +export function transitModeWord(mode, feed = null) { + return ( + feed?.modeWords?.[mode]?.word || + TRANSIT_MODE_WORD[mode] || + TRANSIT_MODE_WORD.unknown + ); +} + +/** + * The operator's short mode word for the fixed-width detection fields. + * @param {string} mode Resolved transit mode. + * @param {object|null} [feed] Registry entry. + * @returns {string} + */ +export function transitModeAbbr(mode, feed = null) { + return ( + feed?.modeWords?.[mode]?.abbr || + TRANSIT_MODE_ABBR[mode] || + TRANSIT_MODE_ABBR.unknown + ); +} + /** * The bright first line of a vehicle's detection label: its route when the feed * names one, else the fleet number, else the raw id. What a person standing at @@ -521,7 +552,7 @@ export function elideRouteText(text) { * @returns {string} */ export function transitDetectionClass(mode, feed) { - const kind = TRANSIT_MODE_ABBR[mode] || TRANSIT_MODE_ABBR.unknown; + const kind = transitModeAbbr(mode, feed); const operator = typeof feed?.name === 'string' ? feed.name.toUpperCase() : ''; return operator ? `${kind} ${operator}`.slice(0, 20) : kind; @@ -538,10 +569,17 @@ export function transitDetectionClass(mode, feed) { * * @param {object} record Normalized vehicle record. * @param {string} mode Resolved transit mode. + * @param {number} [nowMs] + * @param {object|null} [feed] Registry entry, for its own mode vocabulary. * @returns {string} */ -export function transitDetectionMetric(entry, mode, nowMs = Date.now()) { - const kind = TRANSIT_MODE_ABBR[mode] || TRANSIT_MODE_ABBR.unknown; +export function transitDetectionMetric( + entry, + mode, + nowMs = Date.now(), + feed = null, +) { + const kind = transitModeAbbr(mode, feed); const state = transitVehicleState(entry, nowMs); return state ? `${kind} ${state}` : kind; } diff --git a/src/layers/transit/queries.js b/src/layers/transit/queries.js index 68367dc70..470006c85 100644 --- a/src/layers/transit/queries.js +++ b/src/layers/transit/queries.js @@ -12,6 +12,20 @@ import { } from '../../data/transitFeeds.js'; import { transitModeTier } from '../../data/transitPresetStyle.js'; +/** + * The registry entry behind a vehicle. Live feeds answer first so a feed the + * session disabled stops supplying vocabulary; the registry is the fallback, + * because a vehicle can outlive the poll that brought it. + * @param {object} state Layer state. + * @param {object} entry Vehicle entry. + * @returns {object|null} + */ +function feedForEntry(state, entry) { + const id = entry?.feedId; + if (!id) return null; + return state._activeFeeds.get(id) || getRegisteredTransitFeed(id) || null; +} + /** * The layer row's answer to "what is on screen and is it honest?". * @param {object} context @@ -101,6 +115,7 @@ export function createQueries({ state, parts }) { contact._entry, contact._entry.mode, now, + feedForEntry(state, contact._entry), ); return; } @@ -132,10 +147,10 @@ export function createQueries({ state, parts }) { entry.labelRecord = entry.record; } if (!entry.labelClass || entry.labelMode !== entry.mode) { - const feed = - state._activeFeeds.get(entry.feedId) || - getRegisteredTransitFeed(entry.feedId); - entry.labelClass = transitDetectionClass(entry.mode, feed); + entry.labelClass = transitDetectionClass( + entry.mode, + feedForEntry(state, entry), + ); entry.labelMode = entry.mode; } const contact = { @@ -146,7 +161,12 @@ export function createQueries({ state, parts }) { id: entry.labelId, type: 'VEH', klass: entry.labelClass, - metric: transitDetectionMetric(entry, entry.mode, now), + metric: transitDetectionMetric( + entry, + entry.mode, + now, + feedForEntry(state, entry), + ), // The bracket carries the mode colour in every preset: the detection // canvas sits above the post-FX chain, where the sprites' own colour // is lost under NVG and FLIR. Keyless too — the feeds are keyless. diff --git a/src/layers/transit/vocabulary.test.mjs b/src/layers/transit/vocabulary.test.mjs new file mode 100644 index 000000000..17441e770 --- /dev/null +++ b/src/layers/transit/vocabulary.test.mjs @@ -0,0 +1,52 @@ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { + buildTransitSelectionCopy, + transitDetectionClass, + transitDetectionMetric, + transitModeAbbr, + transitModeWord, +} from './policy.js'; +import { getTransitFeed } from '../../data/transitFeeds.js'; + +const ttc = () => getTransitFeed('ttc-toronto'); +const hsl = () => getTransitFeed('hsl-helsinki'); + +test('an operator that names its own vehicles overrides the shared mode word', () => { + // A Toronto 501 is a streetcar. A Helsinki 1010 is a tram. Both are the + // `tram` mode, so the word a reader sees has to come from the operator, + // not from the mode. + assert.equal(transitModeWord('tram', ttc()), 'Streetcar'); + assert.equal(transitModeAbbr('tram', ttc()), 'STREETCAR'); + assert.equal(transitModeWord('tram', hsl()), 'Tram'); + assert.equal(transitModeAbbr('tram', hsl()), 'TRAM'); +}); + +test('an override renames one mode, never the rest of the feed', () => { + assert.equal(transitModeWord('bus', ttc()), 'Bus'); + assert.equal(transitModeWord('subway', ttc()), 'Subway'); + assert.equal(transitModeAbbr('bus', ttc()), 'BUS'); +}); + +test('a missing feed or unknown mode falls back to the shared table', () => { + assert.equal(transitModeWord('tram', null), 'Tram'); + assert.equal(transitModeWord('spaceship', ttc()), 'Transit vehicle'); + assert.equal(transitModeAbbr('spaceship', ttc()), 'TRANSIT'); + assert.equal(transitModeWord('tram', { name: 'No override' }), 'Tram'); +}); + +test('the selection card calls a Toronto 501 a streetcar', () => { + const record = { id: '4400', routeId: '501', timestamp: 0 }; + const copy = buildTransitSelectionCopy(ttc(), record, 'tram', 0, null, null); + assert.match(copy.details.join(' | '), /Streetcar · TTC/); + assert.doesNotMatch(copy.details.join(' | '), /Tram/); +}); + +test('detection labels carry the operator vocabulary within the field width', () => { + const klass = transitDetectionClass('tram', ttc()); + assert.equal(klass, 'STREETCAR TTC'); + assert.ok(klass.length <= 20, 'fits the detection class field'); + assert.equal(transitDetectionClass('tram', hsl()), 'TRAM HSL'); + const metric = transitDetectionMetric({ mode: 'tram' }, 'tram', 0, ttc()); + assert.match(metric, /^STREETCAR/); +}); From 849cb803753afd672dcc0aa0d1acdb9c55534c12 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 00:04:00 -0400 Subject: [PATCH 03/12] feat(transit): add MiWay, Hamilton HSR and Durham Region Transit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Three keyless GTFS-Realtime feeds around Toronto, each verified live: all vehicles carry real coordinates, and each is polled only near its own region rather than across the Golden Horseshoe. The licences differ in ways the registry now records rather than flattens: Hamilton PRESCRIBES its attribution wording, so the credit is that exact sentence; Durham makes credit optional and its catalogued licence PDF is dead after a site relaunch, so licenseUrl points at the live page where the v.1.0 text was actually read; Mississauga's licence is revocable and asks that the terms travel with the data, so licenseUrl is the terms themselves. All three are bus-only and set no route hint, so their modes default rather than resolve. Durham publishes no bearing on any vehicle — heading comes from observed movement, as with any feed that omits it. GO Transit / Metrolinx stays out: its feed requires an API key. --- DATA_SOURCES.md | 5 ++- docs/CURRENT-STATE.md | 7 ++-- src/data/transitFeeds.js | 61 ++++++++++++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 57 +++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 4 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 463034e97..d398cd4f6 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -78,6 +78,9 @@ How to read this: | **TransLink** (Queensland Government) | Transit layer live vehicles, South East Queensland | TransLink / Queensland Government open realtime vehicle data, used for the live view; published for developer use and not against their use. | Attribution to TransLink / Queensland Government (courtesy text) | | **HSL** (realtime.hsl.fi) | Transit layer live vehicles, Helsinki | HSL (Helsinki Region Transport) open realtime vehicle data, used for the live view; published for developer use and not against their use. | Attribution to HSL (Helsinki Region Transport) (courtesy text) | | **TTC** (bustime.ttc.ca) | Transit layer live vehicles, Toronto — surface vehicles (buses and streetcars) only | Toronto Transit Commission BusTime open realtime vehicle data, published through City of Toronto Open Data and used for the live view. The subway publishes no vehicle positions, so Lines 1/2/4 are absent rather than inferred. | Attribution to Toronto Transit Commission — City of Toronto Open Data, under the Open Government Licence – Toronto | +| **MiWay** (miapp.ca) | Transit layer live vehicles, Mississauga ON | MiWay open realtime vehicle data, published by the City of Mississauga under its Open Data Terms of Use, used for the live view. The licence is revocable and asks that the Terms of Use link travel with the data. | Attribution to MiWay — City of Mississauga Open Data, linked to the Terms of Use | +| **Hamilton HSR** (opendata.hamilton.ca) | Transit layer live vehicles, Hamilton ON | Hamilton Street Railway open realtime vehicle data, published by the City of Hamilton for commercial and non-commercial use. | "Contains public sector Data made available under the City of Hamilton’s Open Data Licence" — wording prescribed by the licence | +| **Durham Region Transit** (drtonline.durhamregiontransit.com) | Transit layer live vehicles, Durham Region ON | Durham Region Transit open realtime vehicle data, published under the Region of Durham Open Data Licence v.1.0, which permits commercial use. | "Contains public sector information made available under The Regional Municipality of Durham's Open Data Licence" | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OSRM on the FOSSGIS routing servers** (`routing.openstreetmap.de`) | Street-following routes for the Directions layer and voice route annotations, via `/api/route` | [FOSSGIS routing usage policy](https://routing.openstreetmap.de/about.html): "Display the required attribution and display a link to 'fix the map'", "Use a valid user agent and, if applicable, a correct referrer", "One request per second max", "No scraping, no heavy usage". The full policy is the German [FOSSGIS Nutzungsbedingungen](https://www.fossgis.de/arbeitsgruppen/osm-server/nutzungsbedingungen/); FOSSGIS also states that the server may be embedded in your own pages but "eine gewerbliche Nutzung ist nur mit Einschränkungen erlaubt" (commercial use only with restrictions). Route data derives from OpenStreetMap (ODbL 1.0) | "Routing: OSRM on the FOSSGIS servers" + a "fix the map" link — shown in the Data attribution popover | @@ -156,7 +159,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **NYC DOT Traffic Management Center cameras.** Off by default. NYC DOT's [developer data feeds page](https://www.nyc.gov/html/dot/html/about/datafeeds.shtml) asks developers who want the camera feed to contact `tmcdot@dot.nyc.gov` and sign a data-sharing agreement. This project does not hold one that covers downstream installations, so the pack loads only when an operator who holds their own agreement sets `CCTV_NYC_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to NYC DOT. The endpoint needs no key. The camera list is the public `webcams.nyctmc.org/api/cameras` catalog (~980 cameras across the five boroughs); frames are stills at `webcams.nyctmc.org/api/cameras//image`, synthesized from a validated UUID rather than taken from the payload, and only that host is registered. Cameras the feed reports as offline are dropped. The catalog publishes no camera facing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. Once enabled, the 250 cameras nearest the borough cores load; `CCTV_NYC_MAX_SOURCES` (8–400) changes the cap. Frames are fetched at request time and never stored or redistributed. NYC DOT asks every application that uses its data to carry its disclaimer; it is registered verbatim in the Data attribution popover. - **City of Toronto RESCU cameras.** Keyless. The camera list is the City's public `tmcearthcameras.json` on `opendata.toronto.ca` (dataset "Traffic Cameras", Transportation Services), served as JSONP and unwrapped with an anchored pattern. This is the municipal network the Ontario 511 pack does not carry: downtown arterials plus the Gardiner, DVP, Allen and Lake Shore. The list publishes no frame URL, so frame URLs are BUILT from the documented `CameraImages/loc####.jpg` convention and a strictly-digits camera number, pinning the frame proxy to the portal origin by construction; the list fetch refuses redirects and bounds the body it buffers. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `D1`-`D4` fields are the directions of the *comparison* images (static reference stills captured in 2016 under a different path), not a bearing for the live pan-tilt-zoom frame, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. A camera that is temporarily out of service still answers 200 with a byte-identical "Image Unavailable" placeholder rather than an error (about 6% of the network at any moment), so such a camera reads as healthy; the frame it shows is the agency's, not a synthesized one. The licence requires the attribution statement above. Disable with `CCTV_TORONTO_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All eight registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All eleven registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. GO Transit / Metrolinx is deliberately absent: its realtime feed requires an API key, which the keyless admission rule excludes. - **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. - **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app). - **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 68530ffae..06b026cf6 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3659,9 +3659,10 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Eight keyless regions are available: Boston, Austin, Minneapolis–St Paul, -Helsinki, the Netherlands, Norway, South East Queensland and Toronto (TTC -surface vehicles; the subway publishes no positions). Mode silhouettes +gate. Eleven keyless regions are available: Boston, Austin, Minneapolis–St Paul, +Helsinki, the Netherlands, Norway, South East Queensland, Toronto (TTC +surface vehicles; the subway publishes no positions), and the Golden +Horseshoe neighbours MiWay, Hamilton HSR and Durham Region Transit. Mode silhouettes identify buses, trams, subways, trains, ferries and unclassified vehicles. Retained transit history uses the same outlier quarantine as live observations and diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 5cbdac82d..c6c0f5147 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -312,6 +312,67 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ }), routeMode: ttcRouteMode, }), + Object.freeze({ + id: 'miway-mississauga', + name: 'MiWay', + operator: 'MiWay (City of Mississauga)', + region: 'Mississauga, ON', + center: Object.freeze({ lat: 43.589, lon: -79.6441 }), + loadRadiusKm: 30, + url: 'https://www.miapp.ca/GTFS_RT/Vehicle/VehiclePositions.pb', + license: 'City of Mississauga Open Data Terms of Use', + licenseUrl: + 'http://www5.mississauga.ca/research_catalogue/CityofMississauga_TermsofUse.pdf', + attribution: 'MiWay \u2014 City of Mississauga Open Data', + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'The City of Mississauga (the City) now grants you a world-wide, royalty-free, non-exclusive, revocable licence to use, modify, and distribute the Datasets in all current and future media and formats for any lawful purpose.', + note: 'Two conditions shape how this ships. The licence is REVOCABLE, and it asks that anyone who provides access to the data pass on the Terms of Use URL \u2014 so `licenseUrl` points at the terms themselves rather than at a catalogue page, and the attribution popover carries the link. Credit is optional here ("you are not required to credit the City"), and is given anyway as a courtesy, the way the other municipal feeds are.', + }), + defaultMode: 'bus', + }), + Object.freeze({ + id: 'hsr-hamilton', + name: 'Hamilton HSR', + operator: 'Hamilton Street Railway (City of Hamilton)', + region: 'Hamilton, ON', + center: Object.freeze({ lat: 43.2557, lon: -79.8711 }), + loadRadiusKm: 30, + url: 'https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb', + license: 'City of Hamilton Open Data Licence', + licenseUrl: + 'https://www.hamilton.ca/city-initiatives/strategies-actions/open-data-licence-terms-and-conditions', + attribution: + 'Contains public sector Data made available under the City of Hamilton\u2019s Open Data Licence', + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'The City of Hamilton grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the Data, including for commercial purposes ... you must acknowledge the source of the Data by including the following attribution statement: \u201cContains public sector Data made available under the City of Hamilton\u2019s Open Data Licence\u201d.', + note: 'The attribution wording is prescribed by the licence, so it is used verbatim as the credit rather than paraphrased to an operator name. Names, crests, logos and marks are excluded from the grant, so the credit stays text.', + }), + defaultMode: 'bus', + }), + Object.freeze({ + id: 'durham-region', + name: 'Durham Region Transit', + operator: 'Durham Region Transit (Regional Municipality of Durham)', + region: 'Durham Region, ON', + center: Object.freeze({ lat: 43.9496, lon: -78.9365 }), + loadRadiusKm: 45, + url: 'https://drtonline.durhamregiontransit.com/gtfsrealtime/VehiclePositions', + license: 'Region of Durham Open Data Licence v.1.0', + licenseUrl: 'https://www.durham.ca/en/regional-government/open-data.aspx', + attribution: + "Contains public sector information made available under The Regional Municipality of Durham's Open Data Licence", + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'Durham Region grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the information ... You are free to: Copy, publish, distribute and transmit the information ... Use the information commercially.', + note: 'The licence link the open-data catalogue publishes for this feed (OpenDataLicenceAgreement.pdf) is dead after a site relaunch; `licenseUrl` points at the live Open Data page carrying the same licence v.1.0 text, which is where the quote above was read. Credit is optional and the suggested statement is used verbatim.', + }), + defaultMode: 'bus', + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 1f364b924..b1c5d5bf7 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -289,3 +289,60 @@ test('the TTC row records that BusTime carries no subway', () => { assert.match(sources, /surface vehicles \(buses and streetcars\) only/); assert.match(sources, /Open Government Licence – Toronto/); }); + +test('the Golden Horseshoe neighbours are registered, keyless and routable', () => { + const expected = { + 'miway-mississauga': + 'https://www.miapp.ca/GTFS_RT/Vehicle/VehiclePositions.pb', + 'hsr-hamilton': + 'https://opendata.hamilton.ca/GTFS-RT/GTFS_VehiclePositions.pb', + 'durham-region': + 'https://drtonline.durhamregiontransit.com/gtfsrealtime/VehiclePositions', + }; + for (const [id, url] of Object.entries(expected)) { + const feed = getTransitFeed(id); + assert.ok(feed, `${id} is routable`); + assert.equal(feed.url, url); + assert.equal(feed.defaultEnabled, true); + assert.equal(feed.defaultMode, 'bus'); + assert.equal(feed.historyRetention, undefined, `${id} retains nothing`); + assert.ok(feed.terms?.quote, `${id} records the terms it ships on`); + } +}); + +test('each Golden Horseshoe feed covers its own city and not its neighbours', () => { + const near = (lat, lon) => transitFeedsInRange(lat, lon).map((f) => f.id); + // Mississauga City Centre, downtown Hamilton, Oshawa. + assert.ok(near(43.589, -79.6441).includes('miway-mississauga')); + assert.ok(near(43.2557, -79.8711).includes('hsr-hamilton')); + assert.ok(near(43.8971, -78.8658).includes('durham-region')); + // Hamilton is 60 km from Toronto: far enough that the TTC feed is not polled + // for it, which is the whole point of a per-feed radius. + assert.equal(near(43.2557, -79.8711).includes('ttc-toronto'), false); +}); + +test('a bus-only feed never claims a mode its route ids cannot establish', () => { + for (const id of ['miway-mississauga', 'hsr-hamilton', 'durham-region']) { + const feed = getTransitFeed(id); + assert.equal(transitModeFor(feed, '1'), 'bus'); + assert.equal( + transitModeResolved(feed, '1'), + false, + `${id} defaults rather than resolves`, + ); + } +}); + +test('every Golden Horseshoe feed is documented with its licence', () => { + const sources = readFileSync( + new URL('../../DATA_SOURCES.md', import.meta.url), + 'utf8', + ); + for (const name of ['MiWay', 'Hamilton HSR', 'Durham Region Transit']) { + assert.ok( + sources.split('\n').some((line) => line.startsWith(`| **${name}`)), + `${name} has a DATA_SOURCES row`, + ); + } + assert.match(sources, /Durham Region Transit publishes no bearing/); +}); From 11dd914c2f731442139cf1540a33f7f3c388bd17 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 00:31:54 -0400 Subject: [PATCH 04/12] feat(transit): add Guelph and Kingston, register Barrie off MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Guelph's feed publishes the internal database key of a route (`2991`) where the rider sees the number on the bus (`1`), which would have put "Route 2991" on the label a person reads. So a feed may now carry its own `routeLabel`, the same way it may carry its own `modeWords`. Guelph's table is its 33 routes, taken from the City's own published GTFS; an id missing from it renders unchanged, because a raw id you can compare against the bus beats a blank. Every other feed is identity and carries no table. Kingston is catalogued by the City against this exact URL. Its licence PDF link is pinned to the canonical location rather than the legacy path that currently redirects there — Durham's entry records what happens when such a redirect is eventually dropped. Barrie ships REGISTERED AND OFF. The City offers its licence for acceptance behind a click-through gate, and nobody on this project has accepted it. Whether to accept is a person's decision, not an assumption a poller should make, so the feed is visible, documented, and one line from enabled. --- DATA_SOURCES.md | 5 +- docs/CURRENT-STATE.md | 8 +- src/data/transitFeeds.js | 133 +++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 44 ++++++++ src/layers/transit/policy.js | 13 ++- src/layers/transit/queries.js | 5 +- src/layers/transit/vocabulary.test.mjs | 24 +++++ 7 files changed, 223 insertions(+), 9 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index d398cd4f6..0c245c828 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -81,6 +81,9 @@ How to read this: | **MiWay** (miapp.ca) | Transit layer live vehicles, Mississauga ON | MiWay open realtime vehicle data, published by the City of Mississauga under its Open Data Terms of Use, used for the live view. The licence is revocable and asks that the Terms of Use link travel with the data. | Attribution to MiWay — City of Mississauga Open Data, linked to the Terms of Use | | **Hamilton HSR** (opendata.hamilton.ca) | Transit layer live vehicles, Hamilton ON | Hamilton Street Railway open realtime vehicle data, published by the City of Hamilton for commercial and non-commercial use. | "Contains public sector Data made available under the City of Hamilton’s Open Data Licence" — wording prescribed by the licence | | **Durham Region Transit** (drtonline.durhamregiontransit.com) | Transit layer live vehicles, Durham Region ON | Durham Region Transit open realtime vehicle data, published under the Region of Durham Open Data Licence v.1.0, which permits commercial use. | "Contains public sector information made available under The Regional Municipality of Durham's Open Data Licence" | +| **Guelph Transit** (glphtrpcloud.com) | Transit layer live vehicles, Guelph ON | Guelph Transit open realtime vehicle data, published by the City of Guelph on its open-data developer page and used for the live view. Its route ids are internal database keys, so the 33-row route-number table in `src/data/transitFeeds.js` is derived from the City’s own published GTFS `routes.txt` under the same licence. | "Contains information licensed under the Open Government Licence – City of Guelph" — wording prescribed by the licence | +| **Kingston Transit** (api.cityofkingston.ca) | Transit layer live vehicles, Kingston ON | Kingston Transit open realtime vehicle data, catalogued by the City of Kingston as open data and used for the live view. | "Contains information licensed under the Open Data Licence – City of Kingston" — wording prescribed by the licence | +| **Barrie Transit** (myridebarrie.ca) | REGISTERED BUT OFF — not polled, not offered to the browser | Barrie Transit realtime data, published by the City of Barrie behind a click-through acceptance of its licence. Registered so the decision is visible; it ships unpolled until a person accepts those terms. The licence is revocable and requires no attribution. | Courtesy credit to the City of Barrie (the licence requires none, and its trademark clause is broad) | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OSRM on the FOSSGIS routing servers** (`routing.openstreetmap.de`) | Street-following routes for the Directions layer and voice route annotations, via `/api/route` | [FOSSGIS routing usage policy](https://routing.openstreetmap.de/about.html): "Display the required attribution and display a link to 'fix the map'", "Use a valid user agent and, if applicable, a correct referrer", "One request per second max", "No scraping, no heavy usage". The full policy is the German [FOSSGIS Nutzungsbedingungen](https://www.fossgis.de/arbeitsgruppen/osm-server/nutzungsbedingungen/); FOSSGIS also states that the server may be embedded in your own pages but "eine gewerbliche Nutzung ist nur mit Einschränkungen erlaubt" (commercial use only with restrictions). Route data derives from OpenStreetMap (ODbL 1.0) | "Routing: OSRM on the FOSSGIS servers" + a "fix the map" link — shown in the Data attribution popover | @@ -159,7 +162,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **NYC DOT Traffic Management Center cameras.** Off by default. NYC DOT's [developer data feeds page](https://www.nyc.gov/html/dot/html/about/datafeeds.shtml) asks developers who want the camera feed to contact `tmcdot@dot.nyc.gov` and sign a data-sharing agreement. This project does not hold one that covers downstream installations, so the pack loads only when an operator who holds their own agreement sets `CCTV_NYC_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to NYC DOT. The endpoint needs no key. The camera list is the public `webcams.nyctmc.org/api/cameras` catalog (~980 cameras across the five boroughs); frames are stills at `webcams.nyctmc.org/api/cameras//image`, synthesized from a validated UUID rather than taken from the payload, and only that host is registered. Cameras the feed reports as offline are dropped. The catalog publishes no camera facing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. Once enabled, the 250 cameras nearest the borough cores load; `CCTV_NYC_MAX_SOURCES` (8–400) changes the cap. Frames are fetched at request time and never stored or redistributed. NYC DOT asks every application that uses its data to carry its disclaimer; it is registered verbatim in the Data attribution popover. - **City of Toronto RESCU cameras.** Keyless. The camera list is the City's public `tmcearthcameras.json` on `opendata.toronto.ca` (dataset "Traffic Cameras", Transportation Services), served as JSONP and unwrapped with an anchored pattern. This is the municipal network the Ontario 511 pack does not carry: downtown arterials plus the Gardiner, DVP, Allen and Lake Shore. The list publishes no frame URL, so frame URLs are BUILT from the documented `CameraImages/loc####.jpg` convention and a strictly-digits camera number, pinning the frame proxy to the portal origin by construction; the list fetch refuses redirects and bounds the body it buffers. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `D1`-`D4` fields are the directions of the *comparison* images (static reference stills captured in 2016 under a different path), not a bearing for the live pan-tilt-zoom frame, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. A camera that is temporarily out of service still answers 200 with a byte-identical "Image Unavailable" placeholder rather than an error (about 6% of the network at any moment), so such a camera reads as healthy; the frame it shows is the agency's, not a synthesized one. The licence requires the attribution statement above. Disable with `CCTV_TORONTO_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All eleven registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. GO Transit / Metrolinx is deliberately absent: its realtime feed requires an API key, which the keyless admission rule excludes. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. Thirteen of the fourteen registered regions are live-enabled (Barrie is registered and deliberately off); each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Guelph is the one feed whose route ids are internal keys rather than the number on the bus, so its entry carries a route-number table taken from the City’s own published GTFS; any id missing from that table renders unchanged rather than blank. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. - **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. - **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app). - **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 06b026cf6..1e1651e89 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3659,10 +3659,12 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Eleven keyless regions are available: Boston, Austin, Minneapolis–St Paul, +gate. Thirteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, Helsinki, the Netherlands, Norway, South East Queensland, Toronto (TTC -surface vehicles; the subway publishes no positions), and the Golden -Horseshoe neighbours MiWay, Hamilton HSR and Durham Region Transit. Mode silhouettes +surface vehicles; the subway publishes no positions), the Golden Horseshoe +neighbours MiWay, Hamilton HSR and Durham Region Transit, and Guelph and +Kingston. Barrie is registered but ships off, pending acceptance of its +click-through licence. Mode silhouettes identify buses, trams, subways, trains, ferries and unclassified vehicles. Retained transit history uses the same outlier quarantine as live observations and diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index c6c0f5147..0083d3b3e 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -130,6 +130,60 @@ function ttcRouteMode(routeId) { return 'bus'; } +/** + * Guelph Transit's realtime feed publishes the internal database key of a + * route (`2991`), not the number on the front of the bus (`1`). Without this + * table the detection label reads "Route 2991", which is not what anyone at + * the stop calls it. Route ids and short names are from the City of Guelph's + * own published GTFS `routes.txt` (see DATA_SOURCES.md); an id missing here + * falls through unchanged, so a route added later degrades to its raw id + * rather than disappearing. + */ +const GUELPH_ROUTE_NAMES = Object.freeze({ + 2991: '1', + 2992: '10', + 2993: '11', + 2994: '12', + 2995: '13', + 2996: '14', + 2997: '15', + 2998: '16', + 2999: '17', + 3000: '18', + 3001: '19', + 3002: '2', + 3003: '20', + 3004: '3', + 3005: '4', + 3006: '5', + 3007: '50 U', + 3008: '52 U', + 3009: '56 U', + 3010: '58 U', + 3011: '6', + 3012: '7', + 3013: '8', + 3014: '9', + 3015: '98', + 3016: '99', + 3017: '99Lite', + 3018: 'BREW', + 3019: 'EdiCol', + 3023: 'IroHarv', + 3030: 'Sun LN', + 3032: 'WHanSco', + 3039: 'ZehCha', +}); + +/** + * Guelph route id to the number a rider would say. + * @param {string|null} routeId + * @returns {string|null} + */ +function guelphRouteLabel(routeId) { + return GUELPH_ROUTE_NAMES[routeId] || routeId; +} + /** * Registry of feeds. Order is presentation order in the stats/credit text. * `loadRadiusKm` is the distance from `center` inside which the feed is polled. @@ -373,6 +427,69 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ }), defaultMode: 'bus', }), + Object.freeze({ + id: 'guelph-transit', + name: 'Guelph Transit', + operator: 'Guelph Transit (City of Guelph)', + region: 'Guelph, ON', + center: Object.freeze({ lat: 43.5325, lon: -80.2482 }), + loadRadiusKm: 15, + url: 'https://glphprdtmgtfs.glphtrpcloud.com/tmgtfsrealtimewebservice/vehicle/vehiclepositions.pb', + license: 'Open Government Licence \u2013 City of Guelph (v2.0)', + licenseUrl: 'https://explore.guelph.ca/pages/open-data-license', + attribution: + 'Contains information licensed under the Open Government Licence \u2013 City of Guelph', + 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 subject to the terms below. ... Acknowledge the source of the Information by including any attribution statement specified by the Information Provider(s) and, where possible, provide a link to this licence.', + note: 'The endpoint sits on a vendor host, so provenance matters: the City publishes this exact URL on its own open-data developer page, https://explore.guelph.ca/pages/transit-gtfs-data, under an open-data initiative heading (that page is JavaScript-rendered; its readable source is the ArcGIS item JSON behind it). The licence is a verbatim OGL-Canada 2.0 derivative and the attribution wording above is its prescribed fallback, so it is used as written. The transit datasets carry a BLANK licence field in the portal catalogue; the Terms of Use supply it by default ("Except where otherwise noted this is the Open Government Licence"), the same shape of gap the TTC entry records. The Terms also publish a traffic limit \u2014 no concurrent requests, at most 5 per second \u2014 which one poll every 15 s satisfies many times over. Crests and logos are excluded from the grant, so the credit stays text.', + }), + defaultMode: 'bus', + routeLabel: guelphRouteLabel, + }), + Object.freeze({ + id: 'kingston-transit', + name: 'Kingston Transit', + operator: 'Kingston Transit (The Corporation of the City of Kingston)', + region: 'Kingston, ON', + center: Object.freeze({ lat: 44.24, lon: -76.57 }), + loadRadiusKm: 20, + url: 'https://api.cityofkingston.ca/gtfs-realtime/vehicleupdates.pb', + license: 'City of Kingston Open Data Licence 1.0', + licenseUrl: + 'https://www.cityofkingston.ca/media/wtpgpkb0/gis_license_opendata.pdf', + attribution: + 'Contains information licensed under the Open Data Licence \u2013 City of Kingston', + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'The Information Provider, the City of Kingston, grants you a worldwide, royalty-free, perpetual, non-exclusive licence to use the information provided for any purpose, including for commercial purposes, subject to the terms below. ... Acknowledge the source of the information by including any attribution statement specified by the City of Kingston and, where possible, provide a link to this licence.', + note: 'The City catalogues this exact URL as an open-data dataset, so provenance is direct rather than inferred. `licenseUrl` is the canonical location of the licence PDF; the address the catalogue prints is a legacy path that currently redirects there, and pinning the redirect target is what survives the next site relaunch \u2014 the Durham entry records what happens when it does not. Names, crests and logos are excluded from the grant, so the credit stays text. Roughly one entity in ten carries no usable position (the position field absent, occasionally a momentary 0,0 GPS dropout); both are discarded before rendering.', + }), + defaultMode: 'bus', + }), + Object.freeze({ + id: 'barrie-transit', + name: 'Barrie Transit', + operator: 'Barrie Transit (City of Barrie)', + region: 'Barrie, ON', + center: Object.freeze({ lat: 44.371, lon: -79.6733 }), + loadRadiusKm: 10, + url: 'https://www.myridebarrie.ca/gtfs/GTFS_VehiclePositions.pb', + license: 'Barrie Transit Data licence', + licenseUrl: + 'https://www.barrie.ca/services-payments/transportation-parking/barrie-transit/barrie-gtfs', + attribution: + 'Realtime vehicle data \u00a9 City of Barrie, used under the Barrie Transit Data licence', + defaultEnabled: false, + terms: Object.freeze({ + quote: + 'Barrie Transit hereby grants you a non-exclusive, limited and revocable rights to use, reproduce, and redistribute Barrie Transit Data (scheduled and real-time data) subject to the following terms: Barrie Transit trademarks and copyrighted materials, including any confusingly similar variants, may not be used in association with Data. ... Barrie Transit maintains title, ownership, rights and interest in and to Data.', + note: 'OFF until a person on this project accepts the licence. The City publishes the feed directory behind a click-through "I agree" checkbox and a CAPTCHA; the endpoint itself needs no key, token or cookie, but the terms are offered for acceptance and nobody here has accepted them. That is a decision for a human, not something a poller should assume, so this ships registered and unpolled until someone ticks the box \u2014 then flip this one line. Two further oddities worth knowing: the licence requires NO attribution at all (the credit above is a courtesy), and its trademark clause is broad enough that the credit names the City rather than Barrie Transit. The grant is expressly REVOCABLE and unversioned, so the quote above is the text as read on 2026-09-16.', + }), + defaultMode: 'bus', + }), ]); /** @@ -486,6 +603,22 @@ export function transitModeResolved(feed, routeId) { ); } +/** + * The route as a rider would say it. Most feeds publish that already, so this + * is identity for them; a feed that publishes internal keys supplies its own + * `routeLabel`. Never invents a label: an id the feed does not know survives + * unchanged, because a raw id a person can compare against the bus is more + * use than a blank. + * @param {object|null} feed Registry entry. + * @param {string|null} routeId + * @returns {string|null} + */ +export function transitRouteLabel(feed, routeId) { + if (!routeId || typeof feed?.routeLabel !== 'function') return routeId; + const named = feed.routeLabel(routeId); + return typeof named === 'string' && named ? named : routeId; +} + /** * Public catalog shape served by `/api/transit/feeds` — everything the browser * needs to gate polling and credit the source, and nothing it could misuse. diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index b1c5d5bf7..08c86759a 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -13,6 +13,7 @@ import { transitFeedsInRange, transitModeFor, transitModeResolved, + transitRouteLabel, } from './transitFeeds.js'; test('every registered feed is keyless, https, licensed, and uniquely identified', () => { @@ -346,3 +347,46 @@ test('every Golden Horseshoe feed is documented with its licence', () => { } assert.match(sources, /Durham Region Transit publishes no bearing/); }); + +test('a feed whose route ids are internal database keys can name its routes', () => { + // Guelph's realtime feed emits `2991` where the rider sees route `1`. A feed + // that knows the difference translates it; every other feed is unaffected. + const guelph = getTransitFeed('guelph-transit'); + assert.equal(transitRouteLabel(guelph, '2991'), '1'); + assert.equal(transitRouteLabel(guelph, '3016'), '99'); + assert.equal(transitRouteLabel(guelph, '3007'), '50 U'); + assert.equal(transitRouteLabel(guelph, '3017'), '99Lite'); +}); + +test('an unknown or absent route id survives translation unchanged', () => { + const guelph = getTransitFeed('guelph-transit'); + // A route added after this table was built must still render its raw id + // rather than vanish or read as "undefined". + assert.equal(transitRouteLabel(guelph, '4242'), '4242'); + assert.equal(transitRouteLabel(guelph, null), null); + assert.equal(transitRouteLabel(guelph, ''), ''); +}); + +test('a feed with rider-facing route ids is left alone', () => { + // TTC and Kingston publish the route a rider would say, so translation is + // identity for them and no table is carried. + assert.equal(transitRouteLabel(getTransitFeed('ttc-toronto'), '501'), '501'); + assert.equal(transitRouteLabel(getTransitFeed('mbta'), 'Red'), 'Red'); + assert.equal(transitRouteLabel(null, '7'), '7'); +}); + +test('Barrie is registered but unpolled until its licence is accepted', () => { + // The City offers these terms for acceptance behind a click-through gate. + // Registered-but-off is how that decision stays visible and one line from + // reversible, rather than being made silently by a poller. + assert.equal( + getRegisteredTransitFeed('barrie-transit')?.name, + 'Barrie Transit', + ); + assert.equal(getTransitFeed('barrie-transit'), null, 'not routable'); + assert.equal( + publicTransitCatalog().some((feed) => feed.id === 'barrie-transit'), + false, + 'never offered to the browser', + ); +}); diff --git a/src/layers/transit/policy.js b/src/layers/transit/policy.js index 33352bf2d..721eb247e 100644 --- a/src/layers/transit/policy.js +++ b/src/layers/transit/policy.js @@ -4,7 +4,10 @@ * scene state, no network: everything here is exercised by node:test. */ -import { TRANSIT_MODE_ICON } from '../../data/transitFeeds.js'; +import { + TRANSIT_MODE_ICON, + transitRouteLabel, +} from '../../data/transitFeeds.js'; import { displayMotion, playbackPosition } from './movement.js'; export const TRANSIT_SELECTED_OVERLAY_SOURCE_ID = 'transit-selected'; @@ -337,7 +340,7 @@ export function buildTransitSelectionCopy( ) { const icon = TRANSIT_MODE_ICON[mode] || TRANSIT_MODE_ICON.unknown; const routeLabel = record.routeId - ? `Route ${record.routeId}` + ? `Route ${transitRouteLabel(feed, record.routeId)}` : record.label ? `Vehicle ${record.label}` : `Vehicle ${record.id}`; @@ -515,12 +518,14 @@ export function transitModeAbbr(mode, feed = null) { * names one, else the fleet number, else the raw id. What a person standing at * the stop would call it. * @param {object} record Normalized vehicle record. + * @param {object|null} [feed] Registry entry, for feeds whose route ids are + * internal keys rather than the number on the vehicle. * @returns {string} */ -export function transitDetectionId(record) { +export function transitDetectionId(record, feed = null) { const route = typeof record?.routeId === 'string' ? record.routeId.trim() : ''; - if (route) return elideRouteText(route); + if (route) return elideRouteText(transitRouteLabel(feed, route)); const label = typeof record?.label === 'string' ? record.label.trim() : ''; if (label) return elideRouteText(label); return elideRouteText(String(record?.id || 'TRANSIT')); diff --git a/src/layers/transit/queries.js b/src/layers/transit/queries.js index 470006c85..09b94c49f 100644 --- a/src/layers/transit/queries.js +++ b/src/layers/transit/queries.js @@ -143,7 +143,10 @@ export function createQueries({ state, parts }) { // Route and operator text change with the record and the mode, both of // which arrive on polls — the same events that rebuild this list. if (!entry.labelId || entry.labelRecord !== entry.record) { - entry.labelId = transitDetectionId(entry.record); + entry.labelId = transitDetectionId( + entry.record, + feedForEntry(state, entry), + ); entry.labelRecord = entry.record; } if (!entry.labelClass || entry.labelMode !== entry.mode) { diff --git a/src/layers/transit/vocabulary.test.mjs b/src/layers/transit/vocabulary.test.mjs index 17441e770..d20910b74 100644 --- a/src/layers/transit/vocabulary.test.mjs +++ b/src/layers/transit/vocabulary.test.mjs @@ -3,6 +3,7 @@ import assert from 'node:assert/strict'; import { buildTransitSelectionCopy, transitDetectionClass, + transitDetectionId, transitDetectionMetric, transitModeAbbr, transitModeWord, @@ -50,3 +51,26 @@ test('detection labels carry the operator vocabulary within the field width', () const metric = transitDetectionMetric({ mode: 'tram' }, 'tram', 0, ttc()); assert.match(metric, /^STREETCAR/); }); + +test('a Guelph vehicle is labelled with the number on the bus, not the database key', () => { + const guelph = getTransitFeed('guelph-transit'); + const record = { id: '196', routeId: '2991', timestamp: 0 }; + const copy = buildTransitSelectionCopy(guelph, record, 'bus', 0, null, null); + assert.match(copy.title, /Route 1\b/); + assert.doesNotMatch(copy.title, /2991/); + assert.equal(transitDetectionId(record, guelph), '1'); +}); + +test('a feed that already speaks rider route numbers is untouched', () => { + const record = { id: '4400', routeId: '501', timestamp: 0 }; + assert.equal(transitDetectionId(record, ttc()), '501'); + const copy = buildTransitSelectionCopy(ttc(), record, 'tram', 0, null, null); + assert.match(copy.title, /Route 501/); + // No feed at all still renders the raw route rather than throwing. + assert.equal(transitDetectionId(record), '501'); +}); + +test('a vehicle with no route still falls back to its fleet number', () => { + const guelph = getTransitFeed('guelph-transit'); + assert.equal(transitDetectionId({ id: '196', label: '196' }, guelph), '196'); +}); From 8ccb0cd89536f84415f73055d53351565a2916a4 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 00:34:43 -0400 Subject: [PATCH 05/12] feat(transit): register YRT/Viva off, named by Viva colour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit York Region's feed is first-party infrastructure under an open licence that permits commercial use and does not even require attribution. It is the one feed that fills the gap north of Toronto, and it is switched off anyway. The operator asks that its licence be accepted through a form collecting a name, company, phone and email. No credential is issued and nothing gates the endpoint — the licence body says use is itself acceptance — but a form asking for contact details is close enough to the registration this registry refuses that a person should decide it, not a poller. Barrie is off for the same reason. Both are one line from on. Viva route ids get labels: YRT publishes `601` where every station sign says Viva Blue. The numeric local routes already read correctly and carry no entry, so the table is six lines, not 125. No vehicle in this feed carries a bearing; heading comes from observed movement, as with Durham. --- DATA_SOURCES.md | 3 ++- docs/CURRENT-STATE.md | 4 +-- src/data/transitFeeds.js | 48 ++++++++++++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 17 ++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 0c245c828..54358e75c 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -84,6 +84,7 @@ How to read this: | **Guelph Transit** (glphtrpcloud.com) | Transit layer live vehicles, Guelph ON | Guelph Transit open realtime vehicle data, published by the City of Guelph on its open-data developer page and used for the live view. Its route ids are internal database keys, so the 33-row route-number table in `src/data/transitFeeds.js` is derived from the City’s own published GTFS `routes.txt` under the same licence. | "Contains information licensed under the Open Government Licence – City of Guelph" — wording prescribed by the licence | | **Kingston Transit** (api.cityofkingston.ca) | Transit layer live vehicles, Kingston ON | Kingston Transit open realtime vehicle data, catalogued by the City of Kingston as open data and used for the live view. | "Contains information licensed under the Open Data Licence – City of Kingston" — wording prescribed by the licence | | **Barrie Transit** (myridebarrie.ca) | REGISTERED BUT OFF — not polled, not offered to the browser | Barrie Transit realtime data, published by the City of Barrie behind a click-through acceptance of its licence. Registered so the decision is visible; it ships unpolled until a person accepts those terms. The licence is revocable and requires no attribution. | Courtesy credit to the City of Barrie (the licence requires none, and its trademark clause is broad) | +| **YRT/Viva** (rtu.york.ca) | REGISTERED BUT OFF — not polled, not offered to the browser | York Region Transit realtime data, first-party York Region infrastructure under the YRT Open Data Licence v2.0, which permits commercial use and makes attribution optional. Registered unpolled because the operator asks that the licence be accepted through a contact form first. Viva route ids are named by colour from York Region’s published GTFS. | "Contains public transit Information made available under YRT’s Open Data Licence" — the licence’s own wording, given though not required | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OSRM on the FOSSGIS routing servers** (`routing.openstreetmap.de`) | Street-following routes for the Directions layer and voice route annotations, via `/api/route` | [FOSSGIS routing usage policy](https://routing.openstreetmap.de/about.html): "Display the required attribution and display a link to 'fix the map'", "Use a valid user agent and, if applicable, a correct referrer", "One request per second max", "No scraping, no heavy usage". The full policy is the German [FOSSGIS Nutzungsbedingungen](https://www.fossgis.de/arbeitsgruppen/osm-server/nutzungsbedingungen/); FOSSGIS also states that the server may be embedded in your own pages but "eine gewerbliche Nutzung ist nur mit Einschränkungen erlaubt" (commercial use only with restrictions). Route data derives from OpenStreetMap (ODbL 1.0) | "Routing: OSRM on the FOSSGIS servers" + a "fix the map" link — shown in the Data attribution popover | @@ -162,7 +163,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **NYC DOT Traffic Management Center cameras.** Off by default. NYC DOT's [developer data feeds page](https://www.nyc.gov/html/dot/html/about/datafeeds.shtml) asks developers who want the camera feed to contact `tmcdot@dot.nyc.gov` and sign a data-sharing agreement. This project does not hold one that covers downstream installations, so the pack loads only when an operator who holds their own agreement sets `CCTV_NYC_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to NYC DOT. The endpoint needs no key. The camera list is the public `webcams.nyctmc.org/api/cameras` catalog (~980 cameras across the five boroughs); frames are stills at `webcams.nyctmc.org/api/cameras//image`, synthesized from a validated UUID rather than taken from the payload, and only that host is registered. Cameras the feed reports as offline are dropped. The catalog publishes no camera facing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. Once enabled, the 250 cameras nearest the borough cores load; `CCTV_NYC_MAX_SOURCES` (8–400) changes the cap. Frames are fetched at request time and never stored or redistributed. NYC DOT asks every application that uses its data to carry its disclaimer; it is registered verbatim in the Data attribution popover. - **City of Toronto RESCU cameras.** Keyless. The camera list is the City's public `tmcearthcameras.json` on `opendata.toronto.ca` (dataset "Traffic Cameras", Transportation Services), served as JSONP and unwrapped with an anchored pattern. This is the municipal network the Ontario 511 pack does not carry: downtown arterials plus the Gardiner, DVP, Allen and Lake Shore. The list publishes no frame URL, so frame URLs are BUILT from the documented `CameraImages/loc####.jpg` convention and a strictly-digits camera number, pinning the frame proxy to the portal origin by construction; the list fetch refuses redirects and bounds the body it buffers. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `D1`-`D4` fields are the directions of the *comparison* images (static reference stills captured in 2016 under a different path), not a bearing for the live pan-tilt-zoom frame, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. A camera that is temporarily out of service still answers 200 with a byte-identical "Image Unavailable" placeholder rather than an error (about 6% of the network at any moment), so such a camera reads as healthy; the frame it shows is the agency's, not a synthesized one. The licence requires the attribution statement above. Disable with `CCTV_TORONTO_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. Thirteen of the fourteen registered regions are live-enabled (Barrie is registered and deliberately off); each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Guelph is the one feed whose route ids are internal keys rather than the number on the bus, so its entry carries a route-number table taken from the City’s own published GTFS; any id missing from that table renders unchanged rather than blank. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. Thirteen of the fifteen registered regions are live-enabled; Barrie and YRT/Viva are registered and deliberately off; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Guelph is the one feed whose route ids are internal keys rather than the number on the bus, so its entry carries a route-number table taken from the City’s own published GTFS; any id missing from that table renders unchanged rather than blank. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Two feeds are registered and switched off rather than absent: Barrie and YRT/Viva both ask that their licence be accepted through a form before the data is taken, and that is a person’s decision rather than an assumption a poller should make. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. - **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. - **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app). - **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 1e1651e89..c6910dcc0 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3663,8 +3663,8 @@ gate. Thirteen keyless regions are available: Boston, Austin, Minneapolis–St P Helsinki, the Netherlands, Norway, South East Queensland, Toronto (TTC surface vehicles; the subway publishes no positions), the Golden Horseshoe neighbours MiWay, Hamilton HSR and Durham Region Transit, and Guelph and -Kingston. Barrie is registered but ships off, pending acceptance of its -click-through licence. Mode silhouettes +Kingston. Barrie and YRT/Viva are registered but ship off, +pending acceptance of their licences. Mode silhouettes identify buses, trams, subways, trains, ferries and unclassified vehicles. Retained transit history uses the same outlier quarantine as live observations and diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 0083d3b3e..cb6c3ef0b 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -184,6 +184,31 @@ function guelphRouteLabel(routeId) { return GUELPH_ROUTE_NAMES[routeId] || routeId; } +/** + * YRT publishes Viva bus rapid transit by route id (`601`), while every rider, + * station sign and map calls it "Viva Blue". The local routes are already the + * number on the bus and are left alone. Colours are from York Region's own + * published GTFS `routes.txt`; Viva Green (604) and Pink (606) are not in + * current service and so are absent here too. + */ +const YRT_VIVA_ROUTE_NAMES = Object.freeze({ + 601: 'Viva Blue', + 60102: 'Viva Blue B', + 603: 'Viva Purple', + 60301: 'Viva Purple A', + 605: 'Viva Orange', + 607: 'Viva Yellow', +}); + +/** + * YRT route id to the name a rider would say. + * @param {string|null} routeId + * @returns {string|null} + */ +function yrtRouteLabel(routeId) { + return YRT_VIVA_ROUTE_NAMES[routeId] || routeId; +} + /** * Registry of feeds. Order is presentation order in the stats/credit text. * `loadRadiusKm` is the distance from `center` inside which the feed is polled. @@ -490,6 +515,29 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ }), defaultMode: 'bus', }), + Object.freeze({ + id: 'yrt-york', + name: 'YRT/Viva', + operator: + 'York Region Transit (YRT/Viva), The Regional Municipality of York', + region: 'York Region, ON', + center: Object.freeze({ lat: 44.025, lon: -79.436 }), + loadRadiusKm: 38, + url: 'https://rtu.york.ca/gtfsrealtime/VehiclePositions', + license: 'YRT Open Data Licence v2.0 (UK OGL-derived)', + licenseUrl: + 'https://www.yrt.ca/en/about-us/open-data-licence-agreement.aspx', + attribution: + "Contains public transit Information made available under YRT's Open Data Licence", + defaultEnabled: false, + terms: Object.freeze({ + quote: + 'YRT grants You a worldwide, royalty-free, perpetual, non-exclusive licence to Use the Information subject to the conditions below ... Use the Information commercially ... Provide credit to YRT when using Information under this licence but are not required to. ... Please note: You must agree with and accept the above stated License Agreement in order to download YRT GTFS or real-time GTFS data.', + note: 'OFF for the same reason as Barrie: the operator asks that its licence be accepted through a form (forms.yrt.ca/YRT-GTFS-Data, which collects a name, company, phone and email and issues no credential) before the data is taken. Nothing gates the endpoint, and the licence body also says use is itself acceptance \u2014 but a form asking for contact details is close enough to the registration this registry refuses that a person, not a poller, should decide. Flip this one line once someone has answered it. The credit above is the licence\u2019s own wording and must be reproduced as given; attribution is optional here, and given anyway. Logos, trademarks and crests are carved out, so the credit stays text. Two data notes: no vehicle carries a bearing, so heading comes from observed movement; and one stuck unit reported a position ten hours old, which the layer shows as a stale report rather than hides.', + }), + defaultMode: 'bus', + routeLabel: yrtRouteLabel, + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 08c86759a..711177a03 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -390,3 +390,20 @@ test('Barrie is registered but unpolled until its licence is accepted', () => { 'never offered to the browser', ); }); + +test('YRT is registered but unpolled until its licence form is answered', () => { + assert.equal(getRegisteredTransitFeed('yrt-york')?.name, 'YRT/Viva'); + assert.equal(getTransitFeed('yrt-york'), null, 'not routable'); +}); + +test('Viva bus rapid transit is named by its colour, not its route number', () => { + // YRT publishes `601` where every rider, map and station sign says + // "Viva Blue". The numeric local routes already read correctly and are + // left alone. + const yrt = getRegisteredTransitFeed('yrt-york'); + assert.equal(transitRouteLabel(yrt, '601'), 'Viva Blue'); + assert.equal(transitRouteLabel(yrt, '60301'), 'Viva Purple A'); + assert.equal(transitRouteLabel(yrt, '607'), 'Viva Yellow'); + assert.equal(transitRouteLabel(yrt, '105'), '105', 'a local bus is a number'); + assert.equal(transitRouteLabel(yrt, '9899'), '9899'); +}); From a7fc5ea7c54efb1377fcbc950c6a12452a0b8be8 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 00:40:28 -0400 Subject: [PATCH 06/12] feat(transit): add Burlington, switch Barrie and YRT on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Burlington's route ids are internal keys with a trap in them: `351` is route 1 while `3510` is route 10, so no prefix trim is correct and the table is a real join against the City's own published GTFS. Its licence is the same 2011 municipal template as Mississauga — revocable, and the terms must travel with the data, so licenseUrl is the terms document itself. Plain http:// has no listener at all, so https is mandatory, not preferred. Barrie and YRT ship on. Both operators invite acceptance of their licence through a form, and both licences also state that use is itself acceptance ("By using Barrie Transit Data, you agree to be bound by these terms"; "Your Use of Information indicates Your acceptance"). This deployment relies on that clause, and both entries record it so the reasoning does not have to be re-derived. Nine Ontario feeds now, all verified live against their upstreams. --- DATA_SOURCES.md | 7 ++-- docs/CURRENT-STATE.md | 11 +++--- src/data/transitFeeds.js | 65 +++++++++++++++++++++++++++++++--- src/data/transitFeeds.test.mjs | 60 ++++++++++++++++++++++--------- 4 files changed, 113 insertions(+), 30 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 54358e75c..62fd4cd69 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -83,8 +83,9 @@ How to read this: | **Durham Region Transit** (drtonline.durhamregiontransit.com) | Transit layer live vehicles, Durham Region ON | Durham Region Transit open realtime vehicle data, published under the Region of Durham Open Data Licence v.1.0, which permits commercial use. | "Contains public sector information made available under The Regional Municipality of Durham's Open Data Licence" | | **Guelph Transit** (glphtrpcloud.com) | Transit layer live vehicles, Guelph ON | Guelph Transit open realtime vehicle data, published by the City of Guelph on its open-data developer page and used for the live view. Its route ids are internal database keys, so the 33-row route-number table in `src/data/transitFeeds.js` is derived from the City’s own published GTFS `routes.txt` under the same licence. | "Contains information licensed under the Open Government Licence – City of Guelph" — wording prescribed by the licence | | **Kingston Transit** (api.cityofkingston.ca) | Transit layer live vehicles, Kingston ON | Kingston Transit open realtime vehicle data, catalogued by the City of Kingston as open data and used for the live view. | "Contains information licensed under the Open Data Licence – City of Kingston" — wording prescribed by the licence | -| **Barrie Transit** (myridebarrie.ca) | REGISTERED BUT OFF — not polled, not offered to the browser | Barrie Transit realtime data, published by the City of Barrie behind a click-through acceptance of its licence. Registered so the decision is visible; it ships unpolled until a person accepts those terms. The licence is revocable and requires no attribution. | Courtesy credit to the City of Barrie (the licence requires none, and its trademark clause is broad) | -| **YRT/Viva** (rtu.york.ca) | REGISTERED BUT OFF — not polled, not offered to the browser | York Region Transit realtime data, first-party York Region infrastructure under the YRT Open Data Licence v2.0, which permits commercial use and makes attribution optional. Registered unpolled because the operator asks that the licence be accepted through a contact form first. Viva route ids are named by colour from York Region’s published GTFS. | "Contains public transit Information made available under YRT’s Open Data Licence" — the licence’s own wording, given though not required | +| **Barrie Transit** (myridebarrie.ca) | Transit layer live vehicles, Barrie ON | Barrie Transit realtime data, published by the City of Barrie under a licence accepted by use of the data. The licence is revocable and requires no attribution. | Courtesy credit to the City of Barrie (the licence requires none, and its trademark clause is broad) | +| **YRT/Viva** (rtu.york.ca) | Transit layer live vehicles, York Region ON | York Region Transit realtime data, first-party York Region infrastructure under the YRT Open Data Licence v2.0, which permits commercial use and makes attribution optional. Viva route ids are named by colour from York Region’s published GTFS. | "Contains public transit Information made available under YRT’s Open Data Licence" — the licence’s own wording, given though not required | +| **Burlington Transit** (opendata.burlington.ca) | Transit layer live vehicles, Burlington ON | Burlington Transit realtime data under the City of Burlington Open Data Terms of Use, which permit any lawful purpose. The terms are revocable and must travel with the data, so the credit links them. Route ids are internal keys and are joined to the City’s published GTFS. | Credit to the City of Burlington plus a link to its Open Data Terms of Use, which the licence requires | | **Radio Browser** | Geolocated internet-radio station directory and station-level tags | Public-domain directory data under PDDL 1.0; individual broadcaster stream terms apply | "Radio Browser" plus a link to the selected broadcaster | | **Re:Earth Terrain** (Mapterhorn) | Terrain (keyless globe stacks — OSM etc. — + `/api/terrain/heights` ellipsoidal-height lookups) | Terrain mesh: CC BY 4.0; geoid: EGM2008 (NGA, public domain) | "Terrain (keyless globe stacks): Re:Earth Terrain / Mapterhorn (CC BY 4.0) / EGM2008 (NGA)" | | **OSRM on the FOSSGIS routing servers** (`routing.openstreetmap.de`) | Street-following routes for the Directions layer and voice route annotations, via `/api/route` | [FOSSGIS routing usage policy](https://routing.openstreetmap.de/about.html): "Display the required attribution and display a link to 'fix the map'", "Use a valid user agent and, if applicable, a correct referrer", "One request per second max", "No scraping, no heavy usage". The full policy is the German [FOSSGIS Nutzungsbedingungen](https://www.fossgis.de/arbeitsgruppen/osm-server/nutzungsbedingungen/); FOSSGIS also states that the server may be embedded in your own pages but "eine gewerbliche Nutzung ist nur mit Einschränkungen erlaubt" (commercial use only with restrictions). Route data derives from OpenStreetMap (ODbL 1.0) | "Routing: OSRM on the FOSSGIS servers" + a "fix the map" link — shown in the Data attribution popover | @@ -163,7 +164,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **NYC DOT Traffic Management Center cameras.** Off by default. NYC DOT's [developer data feeds page](https://www.nyc.gov/html/dot/html/about/datafeeds.shtml) asks developers who want the camera feed to contact `tmcdot@dot.nyc.gov` and sign a data-sharing agreement. This project does not hold one that covers downstream installations, so the pack loads only when an operator who holds their own agreement sets `CCTV_NYC_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to NYC DOT. The endpoint needs no key. The camera list is the public `webcams.nyctmc.org/api/cameras` catalog (~980 cameras across the five boroughs); frames are stills at `webcams.nyctmc.org/api/cameras//image`, synthesized from a validated UUID rather than taken from the payload, and only that host is registered. Cameras the feed reports as offline are dropped. The catalog publishes no camera facing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. Once enabled, the 250 cameras nearest the borough cores load; `CCTV_NYC_MAX_SOURCES` (8–400) changes the cap. Frames are fetched at request time and never stored or redistributed. NYC DOT asks every application that uses its data to carry its disclaimer; it is registered verbatim in the Data attribution popover. - **City of Toronto RESCU cameras.** Keyless. The camera list is the City's public `tmcearthcameras.json` on `opendata.toronto.ca` (dataset "Traffic Cameras", Transportation Services), served as JSONP and unwrapped with an anchored pattern. This is the municipal network the Ontario 511 pack does not carry: downtown arterials plus the Gardiner, DVP, Allen and Lake Shore. The list publishes no frame URL, so frame URLs are BUILT from the documented `CameraImages/loc####.jpg` convention and a strictly-digits camera number, pinning the frame proxy to the portal origin by construction; the list fetch refuses redirects and bounds the body it buffers. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `D1`-`D4` fields are the directions of the *comparison* images (static reference stills captured in 2016 under a different path), not a bearing for the live pan-tilt-zoom frame, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. A camera that is temporarily out of service still answers 200 with a byte-identical "Image Unavailable" placeholder rather than an error (about 6% of the network at any moment), so such a camera reads as healthy; the frame it shows is the agency's, not a synthesized one. The licence requires the attribution statement above. Disable with `CCTV_TORONTO_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. Thirteen of the fifteen registered regions are live-enabled; Barrie and YRT/Viva are registered and deliberately off; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Guelph is the one feed whose route ids are internal keys rather than the number on the bus, so its entry carries a route-number table taken from the City’s own published GTFS; any id missing from that table renders unchanged rather than blank. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Two feeds are registered and switched off rather than absent: Barrie and YRT/Viva both ask that their licence be accepted through a form before the data is taken, and that is a person’s decision rather than an assumption a poller should make. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All sixteen registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Guelph, Burlington and YRT publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. - **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. - **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app). - **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line. diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index c6910dcc0..01447298f 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -3659,12 +3659,11 @@ Transit is off by default, and share links use token `j`. The movement panel ord places Transit directly after Street Traffic and before Bike Share. Cameras and utilities retain their own groups. The layer polls registered feeds near the camera every 15 seconds, below a 3,000 km altitude -gate. Thirteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, -Helsinki, the Netherlands, Norway, South East Queensland, Toronto (TTC -surface vehicles; the subway publishes no positions), the Golden Horseshoe -neighbours MiWay, Hamilton HSR and Durham Region Transit, and Guelph and -Kingston. Barrie and YRT/Viva are registered but ship off, -pending acceptance of their licences. Mode silhouettes +gate. Sixteen keyless regions are available: Boston, Austin, Minneapolis–St Paul, +Helsinki, the Netherlands, Norway, South East Queensland, and nine in +Ontario — Toronto (TTC surface vehicles; the subway publishes no +positions), MiWay, Hamilton HSR, Durham Region, YRT/Viva, Guelph, +Burlington, Barrie and Kingston. Mode silhouettes identify buses, trams, subways, trains, ferries and unclassified vehicles. Retained transit history uses the same outlier quarantine as live observations and diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index cb6c3ef0b..560a3074f 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -209,6 +209,41 @@ function yrtRouteLabel(routeId) { return YRT_VIVA_ROUTE_NAMES[routeId] || routeId; } +/** + * Burlington publishes the internal key of a route, and the keys are a trap: + * `351` is route 1 while `3510` is route 10, so trimming a `35` prefix gets + * the wrong answer on half the network. The join is the only correct route. + * Ids and numbers are from the City's own published GTFS `routes.txt`, which + * sits in the same directory as the realtime feed under the same terms. + */ +const BURLINGTON_ROUTE_NAMES = Object.freeze({ + 351: '1', + 352: '2', + 353: '3', + 354: '4', + 356: '6', + 3510: '10', + 3511: '11', + 3512: '12', + 3525: '25', + 3548: '48', + 3550: '50', + 3551: '51', + 3552: '52', + 3580: '80', + 3581: '81', + 3587: '87', +}); + +/** + * Burlington route id to the number a rider would say. + * @param {string|null} routeId + * @returns {string|null} + */ +function burlingtonRouteLabel(routeId) { + return BURLINGTON_ROUTE_NAMES[routeId] || routeId; +} + /** * Registry of feeds. Order is presentation order in the stats/credit text. * `loadRadiusKm` is the distance from `center` inside which the feed is polled. @@ -507,11 +542,11 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ 'https://www.barrie.ca/services-payments/transportation-parking/barrie-transit/barrie-gtfs', attribution: 'Realtime vehicle data \u00a9 City of Barrie, used under the Barrie Transit Data licence', - defaultEnabled: false, + defaultEnabled: true, terms: Object.freeze({ quote: 'Barrie Transit hereby grants you a non-exclusive, limited and revocable rights to use, reproduce, and redistribute Barrie Transit Data (scheduled and real-time data) subject to the following terms: Barrie Transit trademarks and copyrighted materials, including any confusingly similar variants, may not be used in association with Data. ... Barrie Transit maintains title, ownership, rights and interest in and to Data.', - note: 'OFF until a person on this project accepts the licence. The City publishes the feed directory behind a click-through "I agree" checkbox and a CAPTCHA; the endpoint itself needs no key, token or cookie, but the terms are offered for acceptance and nobody here has accepted them. That is a decision for a human, not something a poller should assume, so this ships registered and unpolled until someone ticks the box \u2014 then flip this one line. Two further oddities worth knowing: the licence requires NO attribution at all (the credit above is a courtesy), and its trademark clause is broad enough that the credit names the City rather than Barrie Transit. The grant is expressly REVOCABLE and unversioned, so the quote above is the text as read on 2026-09-16.', + note: 'The City offers this licence for acceptance behind a click-through checkbox, and the licence body also makes use itself acceptance: \u201cBy using Barrie Transit Data, you agree to be bound by these terms.\u201d This deployment\u2019s owner took that clause as sufficient on 2026-09-16 and switched the feed on; nothing gates the endpoint, which needs no key, token or cookie. Two oddities worth knowing: the licence requires NO attribution at all (the credit above is a courtesy), and its trademark clause is broad enough that the credit names the City rather than Barrie Transit. The grant is expressly REVOCABLE and unversioned, so the quote above is the text as read on 2026-09-16.', }), defaultMode: 'bus', }), @@ -529,15 +564,37 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ 'https://www.yrt.ca/en/about-us/open-data-licence-agreement.aspx', attribution: "Contains public transit Information made available under YRT's Open Data Licence", - defaultEnabled: false, + defaultEnabled: true, terms: Object.freeze({ quote: 'YRT grants You a worldwide, royalty-free, perpetual, non-exclusive licence to Use the Information subject to the conditions below ... Use the Information commercially ... Provide credit to YRT when using Information under this licence but are not required to. ... Please note: You must agree with and accept the above stated License Agreement in order to download YRT GTFS or real-time GTFS data.', - note: 'OFF for the same reason as Barrie: the operator asks that its licence be accepted through a form (forms.yrt.ca/YRT-GTFS-Data, which collects a name, company, phone and email and issues no credential) before the data is taken. Nothing gates the endpoint, and the licence body also says use is itself acceptance \u2014 but a form asking for contact details is close enough to the registration this registry refuses that a person, not a poller, should decide. Flip this one line once someone has answered it. The credit above is the licence\u2019s own wording and must be reproduced as given; attribution is optional here, and given anyway. Logos, trademarks and crests are carved out, so the credit stays text. Two data notes: no vehicle carries a bearing, so heading comes from observed movement; and one stuck unit reported a position ten hours old, which the layer shows as a stale report rather than hides.', + note: 'The operator asks that its licence be accepted through a form (forms.yrt.ca/YRT-GTFS-Data, which collects a name, company, phone and email and issues no credential), while the licence body says acceptance is by use: \u201cYour Use of Information indicates Your acceptance of the terms and conditions below.\u201d This deployment\u2019s owner took that clause as sufficient on 2026-09-16 and switched the feed on. Nothing gates the endpoint. The credit above is the licence\u2019s own wording and must be reproduced as given; attribution is optional here, and given anyway. Logos, trademarks and crests are carved out, so the credit stays text. Two data notes: no vehicle carries a bearing, so heading comes from observed movement; and one stuck unit reported a position ten hours old, which the layer shows as a stale report rather than hides.', }), defaultMode: 'bus', routeLabel: yrtRouteLabel, }), + Object.freeze({ + id: 'burlington-transit', + name: 'Burlington Transit', + operator: 'Burlington Transit (City of Burlington)', + region: 'Burlington, ON', + center: Object.freeze({ lat: 43.3342, lon: -79.8089 }), + loadRadiusKm: 12, + url: 'https://opendata.burlington.ca/gtfs-rt/GTFS_VehiclePositions.pb', + license: 'City of Burlington Open Data Terms of Use', + licenseUrl: + 'https://opendata.burlington.ca/opendata-terms-of-use/City%20of%20Burlington%20-%20Open%20Data%20Terms%20of%20Use.pdf', + attribution: + 'Transit data \u00a9 City of Burlington (Burlington Transit), used under the City of Burlington Open Data Terms of Use', + defaultEnabled: true, + terms: Object.freeze({ + quote: + 'The Corporation of the City of Burlington (the City) now grants you a worldwide, royalty-free, non-exclusive, revocable licence to use, reproduce, modify, and distribute the datasets in all current and future media and formats for any lawful purpose. ... If you distribute or provide access to these datasets to any other person ... you agree to include a copy of, or this Uniform Resource Locator (URL) for, these Terms of Use.', + note: 'Same 2011-era municipal template as Mississauga, and the same two consequences: the grant is REVOCABLE, and the terms have to travel with the data, so `licenseUrl` is the Terms document itself rather than a catalogue page and the attribution popover carries the link. Credit is optional here and given anyway. Crests, logos and marks are excluded and the terms forbid implying any association, so the credit stays plain text. The catalogue record for this data leads with a licence link that 404s; the URL above is the live one. Plain http:// has no listener at all \u2014 not a redirect, a hang \u2014 so the https:// URL is mandatory rather than preferred. The feed updates once a minute and answers conditional requests with an ETag.', + }), + defaultMode: 'bus', + routeLabel: burlingtonRouteLabel, + }), ]); /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 711177a03..ea08799ea 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -375,35 +375,61 @@ test('a feed with rider-facing route ids is left alone', () => { assert.equal(transitRouteLabel(null, '7'), '7'); }); -test('Barrie is registered but unpolled until its licence is accepted', () => { - // The City offers these terms for acceptance behind a click-through gate. - // Registered-but-off is how that decision stays visible and one line from - // reversible, rather than being made silently by a poller. - assert.equal( - getRegisteredTransitFeed('barrie-transit')?.name, - 'Barrie Transit', - ); - assert.equal(getTransitFeed('barrie-transit'), null, 'not routable'); - assert.equal( - publicTransitCatalog().some((feed) => feed.id === 'barrie-transit'), - false, - 'never offered to the browser', - ); +test('the feeds whose licences are accepted by use are switched on', () => { + // Barrie and YRT each ask for acceptance through a form, and each licence + // also says that using the data is itself acceptance. That reading was + // taken deliberately, so both are routable and both record the reasoning + // in their terms note rather than leaving it to be re-derived later. + for (const id of ['barrie-transit', 'yrt-york']) { + assert.ok(getTransitFeed(id), `${id} is routable`); + assert.ok( + publicTransitCatalog().some((feed) => feed.id === id), + `${id} is offered to the browser`, + ); + assert.match( + getRegisteredTransitFeed(id).terms.note, + /acceptance is by use|use itself acceptance|took that clause as sufficient/, + `${id} records why it ships on`, + ); + } }); -test('YRT is registered but unpolled until its licence form is answered', () => { +test('every registered feed now ships on, and the gate still decides that', () => { + // The enabled set must stay a filter over the registry, not a copy of it: + // flipping one feed off has to make it unreachable. assert.equal(getRegisteredTransitFeed('yrt-york')?.name, 'YRT/Viva'); - assert.equal(getTransitFeed('yrt-york'), null, 'not routable'); + assert.deepEqual( + TRANSIT_FEED_REGISTRY.filter((feed) => feed.defaultEnabled !== true), + [], + ); }); test('Viva bus rapid transit is named by its colour, not its route number', () => { // YRT publishes `601` where every rider, map and station sign says // "Viva Blue". The numeric local routes already read correctly and are // left alone. - const yrt = getRegisteredTransitFeed('yrt-york'); + const yrt = getTransitFeed('yrt-york'); assert.equal(transitRouteLabel(yrt, '601'), 'Viva Blue'); assert.equal(transitRouteLabel(yrt, '60301'), 'Viva Purple A'); assert.equal(transitRouteLabel(yrt, '607'), 'Viva Yellow'); assert.equal(transitRouteLabel(yrt, '105'), '105', 'a local bus is a number'); assert.equal(transitRouteLabel(yrt, '9899'), '9899'); }); + +test('Burlington route ids are joined, never prefix-stripped', () => { + // `351` is route 1 and `3510` is route 10, so no amount of trimming a `35` + // prefix works — the table is the only correct answer. + const bur = getTransitFeed('burlington-transit'); + assert.equal(transitRouteLabel(bur, '351'), '1'); + assert.equal(transitRouteLabel(bur, '3510'), '10'); + assert.equal(transitRouteLabel(bur, '3512'), '12'); + assert.equal(transitRouteLabel(bur, '3587'), '87'); + assert.equal(transitRouteLabel(bur, '9999'), '9999', 'unknown survives'); +}); + +test('Burlington is live and carries its terms link, which its licence requires', () => { + const bur = getTransitFeed('burlington-transit'); + assert.equal(bur.defaultEnabled, true); + assert.match(bur.licenseUrl, /Open%20Data%20Terms%20of%20Use\.pdf$/); + assert.match(bur.url, /^https:\/\//, 'port 80 has no listener at all'); +}); From 4ffbdda3f565213f3798fb8c8dc7a56ee26ffa0a Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 16:01:10 -0400 Subject: [PATCH 07/12] feat(transit): name YRT's local branch routes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit YRT encodes a branch as a two-digit suffix on the base route id. The Viva table already depended on that scheme — `60102` is Viva Blue's B branch — but local routes were passed through whole, on the reasoning that a YRT route id is already the number on the bus. For a plain route it is. For a branch it is not: a rider watching route 83's B-branch bus saw "8301". A 15:41 EDT sample of the live feed found four branch ids in service. Three are published in York Region's GTFS `routes.txt` and are named here from it, unpadded to match the local routes beside them (the file says `083A`; the registry has always preferred `105` to `005`): 10702 -> 107B KEELE 8301 -> 83A TRENCH 9002 -> 90B LESLIE The fourth, `9101`, runs in the realtime feed but appears nowhere in `routes.txt`. The pattern all but spells "91A" and that is precisely why it is absent: the registry translates published names, it does not infer them. It stays opaque until York Region publishes it. Renamed YRT_VIVA_ROUTE_NAMES to YRT_ROUTE_NAMES, since the table is no longer only about Viva. --- src/data/transitFeeds.js | 24 ++++++++++++++++++------ src/data/transitFeeds.test.mjs | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 560a3074f..818efe245 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -186,18 +186,30 @@ function guelphRouteLabel(routeId) { /** * YRT publishes Viva bus rapid transit by route id (`601`), while every rider, - * station sign and map calls it "Viva Blue". The local routes are already the - * number on the bus and are left alone. Colours are from York Region's own - * published GTFS `routes.txt`; Viva Green (604) and Pink (606) are not in - * current service and so are absent here too. + * station sign and map calls it "Viva Blue". Plain local routes are already the + * number on the bus and are left alone, unpadded: `105` reads better than the + * `005` of `routes.txt`. + * + * Branches are the exception. YRT suffixes a two-digit branch onto the base + * route — the scheme Viva's own `60102` follows — so a branch id reaches a + * rider as "8301" unless it is translated. Names and colours are from York + * Region's own published GTFS `routes.txt`; Viva Green (604) and Pink (606) + * are not in current service and so are absent here too. + * + * Only branches observed live AND published in `routes.txt` are listed. `9101` + * runs but is unpublished, so it is deliberately missing: the pattern suggests + * "91A", and suggesting is not knowing. */ -const YRT_VIVA_ROUTE_NAMES = Object.freeze({ +const YRT_ROUTE_NAMES = Object.freeze({ 601: 'Viva Blue', 60102: 'Viva Blue B', 603: 'Viva Purple', 60301: 'Viva Purple A', 605: 'Viva Orange', 607: 'Viva Yellow', + 8301: '83A', + 9002: '90B', + 10702: '107B', }); /** @@ -206,7 +218,7 @@ const YRT_VIVA_ROUTE_NAMES = Object.freeze({ * @returns {string|null} */ function yrtRouteLabel(routeId) { - return YRT_VIVA_ROUTE_NAMES[routeId] || routeId; + return YRT_ROUTE_NAMES[routeId] || routeId; } /** diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index ea08799ea..cc5481afc 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -416,6 +416,22 @@ test('Viva bus rapid transit is named by its colour, not its route number', () = assert.equal(transitRouteLabel(yrt, '9899'), '9899'); }); +test('YRT local branches read as the branch letter, not the padded id', () => { + // YRT suffixes a two-digit branch onto the base route, the same scheme the + // Viva table already relies on for `60102`. Unsuffixed, that leaks to a rider + // as "8301". The letters are York Region's own published GTFS + // `routes.txt` short names, unpadded to match the local routes beside them. + const yrt = getTransitFeed('yrt-york'); + assert.equal(transitRouteLabel(yrt, '10702'), '107B'); + assert.equal(transitRouteLabel(yrt, '8301'), '83A'); + assert.equal(transitRouteLabel(yrt, '9002'), '90B'); + // `9101` runs in the realtime feed but is absent from routes.txt, so there is + // no published name to give it. Inventing "91A" from the pattern is exactly + // the guess the registry refuses to make; it stays opaque until it is + // published. + assert.equal(transitRouteLabel(yrt, '9101'), '9101'); +}); + test('Burlington route ids are joined, never prefix-stripped', () => { // `351` is route 1 and `3510` is route 10, so no amount of trimming a `35` // prefix works — the table is the only correct answer. From 007562c6c8171a6e4899b8bb9f86395ab66cd0f4 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 16:37:24 -0400 Subject: [PATCH 08/12] docs: note the Ontario transit feeds in the changelog CONTRIBUTING asks that a runtime behaviour change update CHANGELOG.md in the same PR. Nine new feeds and two new label mechanisms qualify. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f39f8d96..5ca1ca0de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +- Add nine Ontario transit feeds: TTC, MiWay, Hamilton HSR, Durham Region, + YRT/Viva, Guelph, Burlington, Barrie and Kingston, each carrying its own + licence quote and attribution. A feed can now name its own modes, so Toronto's + trams read "Streetcar" while Helsinki's stay "Tram", and a feed whose route ids + are internal keys can translate them to the number a rider would say. + - Cyclone advisories no longer go dark while NHC publishes an advisory ahead of its nominal time: advisory and position times up to 90 minutes ahead of the server clock are accepted (previously 5 minutes), so the whole feed is From 65ac2d37fb82de4fa38d0d18f9a019b0b9114e49 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 17:07:45 -0400 Subject: [PATCH 09/12] feat(transit): name Hamilton's routes, which ship as internal keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Not one of HSR's 80 route ids equals the number on the bus. Hamilton was registered without a routeLabel, so every vehicle in the city read as "Route 5783" where a rider would say 5 DELAWARE — 228 of them in an afternoon sample. The mechanism to fix it already existed and simply was never pointed at this feed. Two details the table cannot skip: Hamilton runs two generations of route id at once. `5688` and `5780` are both the 2 BARTON, and both arrive in the live feed, so both are listed. That is why 80 ids collapse to 46 distinct routes. The seasonal and event shuttles publish a name where the local routes publish a number — TC230, PEACH, ROCKTON. Those are already what a rider would say, so they survive as published rather than being forced into a number they do not have. Numbers are unpadded to match the rest of the registry: routes.txt says `02`, a rider says 2. Ids and names are from the City's own published GTFS routes.txt, which sits under the same open-data licence as the realtime feed. Checked against the live feed: all 30 route ids in service translate, none fall through. --- src/data/transitFeeds.js | 105 +++++++++++++++++++++++++++++++++ src/data/transitFeeds.test.mjs | 17 ++++++ 2 files changed, 122 insertions(+) diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index 818efe245..cdf4b030b 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -184,6 +184,110 @@ function guelphRouteLabel(routeId) { return GUELPH_ROUTE_NAMES[routeId] || routeId; } +/** + * Hamilton publishes an internal key for every route: not one of HSR's 80 route + * ids equals the number on the bus, so an untranslated feed reads as + * "Route 5783" city-wide. Two generations of id are live at once — `5688` and + * `5780` are both the 2 BARTON — and both are listed, because both arrive. + * + * Numbers are unpadded to match the rest of the registry (`routes.txt` says + * `02`; a rider says 2). The seasonal and event shuttles publish a name rather + * than a number — `TC230`, `PEACH`, `ROCKTON` — and those are already what a + * rider would say, so they survive as published. Ids and names are from the + * City's own published GTFS `routes.txt`, under the same terms as the feed. + */ +const HAMILTON_ROUTE_NAMES = Object.freeze({ + 5687: '1', + 5688: '2', + 5689: '3', + 5690: '4', + 5691: '5', + 5692: '6', + 5693: '7', + 5694: '8', + 5695: '9', + 5696: '10', + 5697: '11', + 5698: '12', + 5699: '16', + 5700: '18', + 5701: '20', + 5702: '21', + 5703: '22', + 5704: '23', + 5705: '24', + 5706: '25', + 5707: '26', + 5708: '27', + 5709: '33', + 5710: '34', + 5711: '35', + 5712: '41', + 5713: '42', + 5714: '43', + 5715: '44', + 5716: '51', + 5717: '52', + 5718: '55', + 5719: '56', + 5720: '99', + 5731: 'X-IND', + 5780: '2', + 5781: '3', + 5782: '4', + 5783: '5', + 5784: '6', + 5785: '7', + 5786: '8', + 5787: '9', + 5789: '11', + 5790: '12', + 5791: '16', + 5792: '18', + 5793: '20', + 5794: '21', + 5795: '22', + 5796: '23', + 5797: '24', + 5798: '25', + 5799: '26', + 5800: '27', + 5801: '33', + 5802: '34', + 5803: '35', + 5805: '42', + 5806: '43', + 5807: '44', + 5808: '51', + 5809: '52', + 5811: '56', + 5812: '99', + 5820: 'TC230', + 5823: 'X IND', + 5824: 'TC-700', + 5825: 'TC-300', + 5826: 'CAN', + 5827: 'PEACH', + 5828: '1', + 5829: '10', + 5830: '41', + 5831: '55', + 5832: 'TC300', + 5833: 'TC700', + 5834: 'TC730', + 5835: 'ANCFAIR', + 5836: 'ROCKTON', +}); + +/** + * Hamilton route id to the number a rider would say. + * @param {string|null} routeId + * @returns {string|null} + */ +function hamiltonRouteLabel(routeId) { + return HAMILTON_ROUTE_NAMES[routeId] || routeId; +} + /** * YRT publishes Viva bus rapid transit by route id (`601`), while every rider, * station sign and map calls it "Viva Blue". Plain local routes are already the @@ -478,6 +582,7 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ note: 'The attribution wording is prescribed by the licence, so it is used verbatim as the credit rather than paraphrased to an operator name. Names, crests, logos and marks are excluded from the grant, so the credit stays text.', }), defaultMode: 'bus', + routeLabel: hamiltonRouteLabel, }), Object.freeze({ id: 'durham-region', diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index cc5481afc..22281e46d 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -432,6 +432,23 @@ test('YRT local branches read as the branch letter, not the padded id', () => { assert.equal(transitRouteLabel(yrt, '9101'), '9101'); }); +test('Hamilton route ids are internal keys, read as the number on the bus', () => { + // Not one of HSR's 80 route ids equals its published short name, so every + // vehicle reads as "Route 5783" until the table translates it. Hamilton also + // carries two generations of id for the same route — `5688` and `5780` are + // both the 2 BARTON — so both must land on the same answer. + const hsr = getTransitFeed('hsr-hamilton'); + assert.equal(transitRouteLabel(hsr, '5780'), '2'); + assert.equal(transitRouteLabel(hsr, '5688'), '2', 'the older id agrees'); + assert.equal(transitRouteLabel(hsr, '5687'), '1'); + assert.equal(transitRouteLabel(hsr, '5829'), '10', 'the B-Line'); + assert.equal(transitRouteLabel(hsr, '5793'), '20', 'the A-Line'); + // Published names that are not numbers are already what a rider would say, + // so they survive as published rather than being forced into a number. + assert.equal(transitRouteLabel(hsr, '5820'), 'TC230'); + assert.equal(transitRouteLabel(hsr, '9999'), '9999', 'unknown survives'); +}); + test('Burlington route ids are joined, never prefix-stripped', () => { // `351` is route 1 and `3510` is route 10, so no amount of trimming a `35` // prefix works — the table is the only correct answer. From 9ab26bbcb04a6453528f21210e6317e170778da7 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 17:14:19 -0400 Subject: [PATCH 10/12] docs: record Hamilton's route table and the feeds left out Two gaps. The Hamilton entry never said its route ids are internal keys, which the Guelph, Burlington and YRT entries all say of theirs; the route-table sentence in the transit notes named those three and not Hamilton, though it now carries the largest table of the four. Both were stale the moment Hamilton got a table. The exclusions were half-recorded: GO Transit and Grand River had their reasons written down, but Ottawa, London, Thunder Bay and the static-only majority did not, so a later reader would have re-investigated feeds that were already surveyed and rejected. All of them are now named with the rule each one falls to, and the survey is stated as complete against the Mobility Database's Ontario catalogue. Also records that a route label is never invented, which is why YRT's unpublished 9101 renders as the feed sends it. --- DATA_SOURCES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DATA_SOURCES.md b/DATA_SOURCES.md index 62fd4cd69..e78c082ad 100644 --- a/DATA_SOURCES.md +++ b/DATA_SOURCES.md @@ -79,7 +79,7 @@ How to read this: | **HSL** (realtime.hsl.fi) | Transit layer live vehicles, Helsinki | HSL (Helsinki Region Transport) open realtime vehicle data, used for the live view; published for developer use and not against their use. | Attribution to HSL (Helsinki Region Transport) (courtesy text) | | **TTC** (bustime.ttc.ca) | Transit layer live vehicles, Toronto — surface vehicles (buses and streetcars) only | Toronto Transit Commission BusTime open realtime vehicle data, published through City of Toronto Open Data and used for the live view. The subway publishes no vehicle positions, so Lines 1/2/4 are absent rather than inferred. | Attribution to Toronto Transit Commission — City of Toronto Open Data, under the Open Government Licence – Toronto | | **MiWay** (miapp.ca) | Transit layer live vehicles, Mississauga ON | MiWay open realtime vehicle data, published by the City of Mississauga under its Open Data Terms of Use, used for the live view. The licence is revocable and asks that the Terms of Use link travel with the data. | Attribution to MiWay — City of Mississauga Open Data, linked to the Terms of Use | -| **Hamilton HSR** (opendata.hamilton.ca) | Transit layer live vehicles, Hamilton ON | Hamilton Street Railway open realtime vehicle data, published by the City of Hamilton for commercial and non-commercial use. | "Contains public sector Data made available under the City of Hamilton’s Open Data Licence" — wording prescribed by the licence | +| **Hamilton HSR** (opendata.hamilton.ca) | Transit layer live vehicles, Hamilton ON | Hamilton Street Railway open realtime vehicle data, published by the City of Hamilton for commercial and non-commercial use. Not one of its 80 route ids is the number on the bus, so the route-number table in `src/data/transitFeeds.js` is derived from the City’s own published GTFS `routes.txt` under the same licence; two generations of id run at once and both are listed. | "Contains public sector Data made available under the City of Hamilton’s Open Data Licence" — wording prescribed by the licence | | **Durham Region Transit** (drtonline.durhamregiontransit.com) | Transit layer live vehicles, Durham Region ON | Durham Region Transit open realtime vehicle data, published under the Region of Durham Open Data Licence v.1.0, which permits commercial use. | "Contains public sector information made available under The Regional Municipality of Durham's Open Data Licence" | | **Guelph Transit** (glphtrpcloud.com) | Transit layer live vehicles, Guelph ON | Guelph Transit open realtime vehicle data, published by the City of Guelph on its open-data developer page and used for the live view. Its route ids are internal database keys, so the 33-row route-number table in `src/data/transitFeeds.js` is derived from the City’s own published GTFS `routes.txt` under the same licence. | "Contains information licensed under the Open Government Licence – City of Guelph" — wording prescribed by the licence | | **Kingston Transit** (api.cityofkingston.ca) | Transit layer live vehicles, Kingston ON | Kingston Transit open realtime vehicle data, catalogued by the City of Kingston as open data and used for the live view. | "Contains information licensed under the Open Data Licence – City of Kingston" — wording prescribed by the licence | @@ -164,7 +164,7 @@ The optional Local ADS-B layer and the broadcast-FM receiver use radio you recei - **NYC DOT Traffic Management Center cameras.** Off by default. NYC DOT's [developer data feeds page](https://www.nyc.gov/html/dot/html/about/datafeeds.shtml) asks developers who want the camera feed to contact `tmcdot@dot.nyc.gov` and sign a data-sharing agreement. This project does not hold one that covers downstream installations, so the pack loads only when an operator who holds their own agreement sets `CCTV_NYC_ENABLED=1`; with the flag unset, empty or any other value, the server makes no request to NYC DOT. The endpoint needs no key. The camera list is the public `webcams.nyctmc.org/api/cameras` catalog (~980 cameras across the five boroughs); frames are stills at `webcams.nyctmc.org/api/cameras//image`, synthesized from a validated UUID rather than taken from the payload, and only that host is registered. Cameras the feed reports as offline are dropped. The catalog publishes no camera facing, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. Once enabled, the 250 cameras nearest the borough cores load; `CCTV_NYC_MAX_SOURCES` (8–400) changes the cap. Frames are fetched at request time and never stored or redistributed. NYC DOT asks every application that uses its data to carry its disclaimer; it is registered verbatim in the Data attribution popover. - **City of Toronto RESCU cameras.** Keyless. The camera list is the City's public `tmcearthcameras.json` on `opendata.toronto.ca` (dataset "Traffic Cameras", Transportation Services), served as JSONP and unwrapped with an anchored pattern. This is the municipal network the Ontario 511 pack does not carry: downtown arterials plus the Gardiner, DVP, Allen and Lake Shore. The list publishes no frame URL, so frame URLs are BUILT from the documented `CameraImages/loc####.jpg` convention and a strictly-digits camera number, pinning the frame proxy to the portal origin by construction; the list fetch refuses redirects and bounds the body it buffers. Frames are fetched at request time and never stored or redistributed. The dataset publishes no camera facing: the `D1`-`D4` fields are the directions of the *comparison* images (static reference stills captured in 2016 under a different path), not a bearing for the live pan-tilt-zoom frame, so headings use the shared id-hash fallback at low confidence and are corrected with the in-app calibration gizmo. A camera that is temporarily out of service still answers 200 with a byte-identical "Image Unavailable" placeholder rather than an error (about 6% of the network at any moment), so such a camera reads as healthy; the frame it shows is the agency's, not a synthesized one. The licence requires the attribution statement above. Disable with `CCTV_TORONTO_ENABLED=0`. - **Camera frame content.** Public camera frames can contain people, vehicles and license plates, and the camera layer does nothing with them beyond putting them on the map. A successful upstream response is relayed as the provider served it: nothing in the camera pipeline blurs, redacts, enhances or restores it, and nothing there runs face, plate or object detection or otherwise recognises or classifies what is in the picture. (The ALPR layer described below maps where plate-reader cameras are, from locations contributors tagged in OpenStreetMap; it reads nothing from any camera frame.) When an upstream has no frame for a camera, what you see instead is a Google Street View still or the app's own placeholder card; the panel's source badge names which of them you are looking at, and a refresh that fails after a frame has arrived leaves the last good picture on screen rather than replacing it. The browser resamples each frame for display: onto a fixed 1920x1080 surface for the camera's projection plane in the scene, and onto a 192x108 canvas for the small ambient card. That scaling is the only change made to the picture, and the only pixels the camera layer reads back are a 64x36 downscale hashed to tell whether the picture has changed. Live streams are piped through; the still path reads the image into memory to pass it on — TxDOT wraps its JPEG in a JSON envelope, which is decoded there — and no frame is written to disk (the disk cache, `.gev-cache/`, holds feed JSON for other layers and never camera imagery). Outside that pipeline, the voice assistant is the one feature that sends imagery anywhere: when it answers a question about what is in view it may attach a downscaled screenshot of the rendered scene — including any camera plane on screen — to the request it sends to the voice model. Frames are fetched only from server-registered camera URLs — a client cannot hand the proxy a URL (see [SECURITY.md](SECURITY.md)). What the app does stays inside the line README draws: no named-person search, no face recognition, no tracking individuals. -- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All sixteen registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Guelph, Burlington and YRT publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. +- **Transit (GTFS-Realtime).** The proxy requests only registered operator feeds, validates redirects, bounds responses, and uses conditional requests, short snapshot caching and failure backoff. All sixteen registered regions are live-enabled; each can be disabled independently. Vehicles use delayed playback between reports, with report age and waiting states shown separately. Session-local selected trails are available for every feed. MBTA additionally retains up to 15 minutes of recently observed positions in the running proxy, so available history can survive a browser reload; server restart clears it. History reads never fetch upstream, and other feeds have no proxy retention. Nothing is archived to disk or collected in the background. Operator text credits are included as a courtesy and do not imply endorsement. Heights are aligned to work with Google 3D tiles; subway markers are shown at street level because these feeds do not supply depth. The TTC feed is BusTime, the surface system: it carries buses and streetcars and no subway at all. About four in ten of its vehicles report no route at all (unassigned or deadheading), and those are shown with the feed default rather than a route-established mode. It sends no ETag or Last-Modified, so its conditional requests fall through to the ordinary snapshot cache. Three Golden Horseshoe neighbours run alongside it — MiWay, Hamilton HSR and Durham Region Transit — each bus-only and each polled only near its own region. Durham Region Transit publishes no bearing on any vehicle, so those sprites take their heading from observed movement like any other feed that omits it. Guelph, Kingston and Barrie extend the same pattern eastward and north. Hamilton, Guelph, Burlington and YRT publish route ids that are not the number on the vehicle, so those entries carry a route-name table taken from each operator’s own published GTFS; any id missing from a table renders unchanged rather than blank. A label is never invented: YRT runs a route `9101` that appears nowhere in its published routes, so it stays as the feed sends it. Burlington’s is the one that cannot be shortcut: `351` is route 1 while `3510` is route 10, so the table is a real join rather than a trimmed prefix. GO Transit / Metrolinx is deliberately absent: its REALTIME feed requires an API key issued by manual review, which the keyless admission rule excludes (its static schedule download is keyless, but carries no vehicle positions). Barrie and YRT/Viva each invite acceptance of their licence through a form, and each licence also states that using the data is itself acceptance; this deployment relies on that clause, which is recorded in both entries. Grand River Transit in Waterloo is absent for a different reason: it answers, but its feed header was months stale and it publishes no per-vehicle timestamps, so it would render vehicles that look live and are not. Ottawa’s OC Transpo falls to the same keyless admission rule as GO Transit — its realtime feed requires an API key. London Transit and Thunder Bay Transit publish vehicle positions over plain HTTP with no HTTPS endpoint available. Every other Ontario system — Brampton, Oakville, Niagara, Milton, Windsor, Greater Sudbury, UP Express and a dozen smaller operators — publishes static GTFS schedules only, with no realtime vehicle positions to register. Between the nine included and these exclusions, every Ontario realtime vehicle-position feed catalogued in the Mobility Database is accounted for. - **Radio Browser.** `/api/radio/stations` discovers official API mirrors, makes bounded and coalesced healthy/geolocated HTTPS-station queries, caches the normalized public-domain directory for 45 minutes, and may serve the last good catalog for up to seven days during an outage. Refreshes must meet minimum accepted-query and station coverage before replacing a warm catalog; schema-valid responses whose rows all fail the product's health policy do not count as successful queries. A usable partial cold catalog is explicitly `DEGRADED`, and malformed or empty successful payloads are rejected atomically. Every directory and click-count request rejects redirects, validates all resolved addresses as globally routable (including reserved/documentation IPv4 and special/non-global IPv6 exclusions), and pins the TLS connection to a validated address. Only MP3/AAC non-HLS directory rows with public HTTPS stream targets are returned; favicons are intentionally omitted. Pressing play connects one browser audio element directly to the selected broadcaster and calls the directory's click counter through known-ID-only `POST /api/radio/click/:uuid`. GEV never proxies, caches, records, bundles, or redistributes audio. Radio Browser supplies station-level tags, not dependable current-song or upcoming-program metadata, so Radio filtering never claims either. Direct playback exposes the listener's IP address to the broadcaster, whose own stream terms apply. - **TomTom Traffic.** Optional and BYOK: without `TOMTOM_API_KEY` the traffic layer runs its built-in simulation and no TomTom data (or attribution) appears. With a key, flow vector tiles are fetched through the server-side `/api/tomtom` proxy (120 s cache + a daily tile-budget governor — `TOMTOM_DAILY_TILE_BUDGET`, default 6,000 — sized so a 31-day month stays inside TomTom's 200K monthly free allowance; still a configurable application safety ceiling, not a guarantee; TomTom's [current pricing](https://docs.tomtom.com/pricing/) lists 200K free tile requests per month) and the "Traffic flow data © TomTom" credit is registered in the Data attribution popover the moment live mode activates. TomTom data is served live and cached only transiently (≤120 s TTL under `.gev-cache/`, gitignored) — it is not bundled or redistributed. One 23 KB point-in-time tile snapshot is committed as a decode-test fixture (`src/data/fixtures/`, © TomTom, never served to the app). - **Routing (OSRM / FOSSGIS).** `/api/route` proxies the public OSRM instances FOSSGIS e.V. runs for the OpenStreetMap community (car, bike, foot profiles). They are keyless and intended for fair, interactive use — the proxy rate-limits clients (60/min, 200/min total), caps route span and response size, caches each route for 10 minutes, and identifies itself in the User-Agent. Heavy or automated use must run its own OSRM. Routes are computed from OpenStreetMap data (ODbL); the Directions layer and voice routes never redistribute them. A route the router cannot find is reported as such; the Directions layer draws nothing in that case, and voice routes fall back to a clearly labeled straight line. From 68e99d9407956b4fce646b5b68f0cd1fa972b557 Mon Sep 17 00:00:00 2001 From: Cliff Flood Date: Wed, 16 Sep 2026 17:17:37 -0400 Subject: [PATCH 11/12] docs: list the Ontario regions in the README feature table The Transit row names the regions a reader can expect to see vehicles in, and still stopped at South East Queensland after nine Ontario feeds were added. Someone scanning the table for Toronto would have concluded the layer does not cover it. Toronto carries the subway caveat here too: the row would otherwise promise metros in a city whose metro publishes no positions. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8b9eafec..c5aeb4710 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,7 @@ Twenty layers and map sources. **Eighteen have a keyless path.** Some offer addi | 📷 **Mapped ALPR Cameras** | License-plate-reader camera locations tagged by OpenStreetMap contributors, loaded one city-sized view at a time, with **SHOW NEAREST**. Locations and tags only: no plate data, no video | OpenStreetMap (incl. DeFlock mapping) | 🟢 | | 📷 **Street Level** | Street-level photos behind one panel, one chip per provider: coverage on the streets, image cones, an embedded viewer and **FOLLOW**. Mapillary, Google Street View, KartaView and Panoramax | Mapillary · Google · KartaView · Panoramax | 🟢 KartaView, Panoramax · 🟡 Mapillary token · 🔴 Google Maps key | | 📻 **Radio** | Geolocated world radio with an **analog tuner** — drag the needle across up to 750 stations and the globe flies to each broadcaster | Radio Browser / broadcasters | 🟢 | -| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland | Operator GTFS-Realtime feeds | 🟢 | +| 🚌 **Transit** | Live buses, trams, metros, trains and ferries with delayed playback between reports, selected-vehicle trails, and mode-coloured DETECT labels — Boston, Austin, Minneapolis, Helsinki, the Netherlands, Norway, South East Queensland, and nine in Ontario: Toronto (surface vehicles; the subway publishes no positions), Mississauga, Hamilton, Durham Region, York Region, Guelph, Burlington, Barrie and Kingston | Operator GTFS-Realtime feeds | 🟢 | | 🚲 **Bikeshare** | Live station availability | GBFS | 🟢 | | 🧭 **Directions** | Click A and B on the globe for a street-following drive, walk or cycle route draped on the terrain with turn-by-turn steps — then FLY the camera along it. No key, no geocoder, no mic | OSRM on FOSSGIS servers (OpenStreetMap) | 🟢 | | 🔥 **Active Fires** | Live NASA FIRMS detections, trailing 24h | NASA FIRMS | 🟡 | From cf63278126a512c7e2761dd9ab38913bd126b291 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Thu, 15 Oct 2026 17:12:35 -0700 Subject: [PATCH 12/12] Take TTC vehicle mode from the fleet number before the route Replacement buses on 5xx streetcar routes were drawn as streetcars, and Flexity streetcars reporting no route were drawn as buses. A feed can now supply vehicleMode(id); TTC maps 4400-4699 to streetcars and every other fleet number to buses, falling back to the route otherwise. --- CHANGELOG.md | 4 +- server/providers/transitHistory.test.mjs | 23 ++++++++++++ src/data/transitFeeds.js | 47 ++++++++++++++++++++---- src/data/transitFeeds.test.mjs | 16 ++++++++ src/layers/transit/ingestion.js | 8 +++- src/sources/transitHistoryStore.js | 6 ++- 6 files changed, 93 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ca1ca0de..2e7478531 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,9 @@ YRT/Viva, Guelph, Burlington, Barrie and Kingston, each carrying its own licence quote and attribution. A feed can now name its own modes, so Toronto's trams read "Streetcar" while Helsinki's stay "Tram", and a feed whose route ids - are internal keys can translate them to the number a rider would say. + are internal keys can translate them to the number a rider would say. TTC + vehicles take their mode from the fleet number first, so replacement buses on + streetcar routes read as buses and out-of-service streetcars stay streetcars. - Cyclone advisories no longer go dark while NHC publishes an advisory ahead of its nominal time: advisory and position times up to 90 minutes ahead of diff --git a/server/providers/transitHistory.test.mjs b/server/providers/transitHistory.test.mjs index cb06c182a..551fee7a7 100644 --- a/server/providers/transitHistory.test.mjs +++ b/server/providers/transitHistory.test.mjs @@ -179,3 +179,26 @@ test('snapshot capacity pressure preserves members not yet visited and discloses assert.equal(recreated.fixes.length, 1); assert.equal(recreated.truncated, true); }); +test('a feed fleet-number mode outranks its route mode in the epoch context', (t) => { + const h = history(t); + const ttc = { + id: 'ttc', + historyRetention: true, + defaultMode: 'bus', + routeMode: (route) => (/^5\d\d$/.test(route ?? '') ? 'tram' : 'bus'), + vehicleMode: (id) => + /^4[4-6]\d\d$/.test(id) ? 'tram' : /^\d{4}$/.test(id) ? 'bus' : 'unknown', + }; + h.ingest( + ttc, + [ + row(100000, '8515', { routeId: '506' }), + row(100000, '4507', { routeId: null }), + row(100000, 'x1', { routeId: '501' }), + ], + 100000, + ); + assert.equal(h.get('ttc', '8515', 100000).epochs[0].mode, 'bus'); + assert.equal(h.get('ttc', '4507', 100000).epochs[0].mode, 'tram'); + assert.equal(h.get('ttc', 'x1', 100000).epochs[0].mode, 'tram'); +}); diff --git a/src/data/transitFeeds.js b/src/data/transitFeeds.js index cdf4b030b..dfd3d6b18 100644 --- a/src/data/transitFeeds.js +++ b/src/data/transitFeeds.js @@ -130,6 +130,20 @@ function ttcRouteMode(routeId) { return 'bus'; } +/** + * The fleet number settles TTC's mode before the route does: buses replace + * streetcars on 5xx routes during track work, and streetcars running out of + * service report no route at all. Flexity streetcars are numbered 4400–4699; + * every other TTC number is a bus. + * @param {string|null} vehicleId GTFS-RT vehicle id (the fleet number). + * @returns {string} + */ +function ttcVehicleMode(vehicleId) { + if (!/^\d{4}$/.test(String(vehicleId ?? ''))) return 'unknown'; + const fleet = Number(vehicleId); + return fleet >= 4400 && fleet < 4700 ? 'tram' : 'bus'; +} + /** * Guelph Transit's realtime feed publishes the internal database key of a * route (`2991`), not the number on the front of the bus (`1`). Without this @@ -541,6 +555,7 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([ tram: Object.freeze({ word: 'Streetcar', abbr: 'STREETCAR' }), }), routeMode: ttcRouteMode, + vehicleMode: ttcVehicleMode, }), Object.freeze({ id: 'miway-mississauga', @@ -795,14 +810,32 @@ export function transitFeedsInRange(lat, lon, slackKm = 0) { } /** - * Mode for a vehicle: the feed's route hint when it has one, else its default. + * The feed's own hint for a vehicle: its fleet number when the feed maps + * those (`vehicleMode`), else its route (`routeMode`). Null when neither knows. + * @param {object} feed Registry entry. + * @param {string|null} routeId + * @param {string|null} vehicleId + * @returns {string|null} + */ +function hintedMode(feed, routeId, vehicleId) { + const byVehicle = + typeof feed?.vehicleMode === 'function' + ? feed.vehicleMode(vehicleId) + : null; + if (byVehicle && byVehicle !== 'unknown') return byVehicle; + return typeof feed?.routeMode === 'function' ? feed.routeMode(routeId) : null; +} + +/** + * Mode for a vehicle: the feed's fleet or route hint when it has one, else + * its default. * @param {object} feed Registry entry. * @param {string|null} routeId GTFS route_id from the vehicle's trip. + * @param {string|null} [vehicleId] GTFS-RT vehicle id. * @returns {string} One of TRANSIT_MODES. */ -export function transitModeFor(feed, routeId) { - const hinted = - typeof feed?.routeMode === 'function' ? feed.routeMode(routeId) : null; +export function transitModeFor(feed, routeId, vehicleId = null) { + const hinted = hintedMode(feed, routeId, vehicleId); const mode = hinted && hinted !== 'unknown' ? hinted : feed?.defaultMode || 'unknown'; return TRANSIT_MODES.includes(mode) ? mode : 'unknown'; @@ -815,11 +848,11 @@ export function transitModeFor(feed, routeId) { * not hold a defaulted vehicle to a bus's limits. * @param {object} feed Registry entry. * @param {string|null} routeId + * @param {string|null} [vehicleId] * @returns {boolean} */ -export function transitModeResolved(feed, routeId) { - const hinted = - typeof feed?.routeMode === 'function' ? feed.routeMode(routeId) : null; +export function transitModeResolved(feed, routeId, vehicleId = null) { + const hinted = hintedMode(feed, routeId, vehicleId); return ( Boolean(hinted) && hinted !== 'unknown' && TRANSIT_MODES.includes(hinted) ); diff --git a/src/data/transitFeeds.test.mjs b/src/data/transitFeeds.test.mjs index 22281e46d..fd990af45 100644 --- a/src/data/transitFeeds.test.mjs +++ b/src/data/transitFeeds.test.mjs @@ -279,6 +279,22 @@ test('TTC route numbers tell a streetcar from a bus', () => { ); }); +test('a TTC fleet number outranks the route', () => { + // Buses replace streetcars on 5xx routes during track work, and streetcars + // out of service report no route; the Flexity fleet is 4400–4699. + const ttc = getTransitFeed('ttc-toronto'); + assert.equal(transitModeFor(ttc, '506', '8515'), 'bus'); + assert.equal(transitModeFor(ttc, '512', '3101'), 'bus'); + assert.equal(transitModeFor(ttc, null, '4507'), 'tram'); + assert.equal(transitModeResolved(ttc, null, '4507'), true); + assert.equal(transitModeFor(ttc, '504', '4400'), 'tram'); + assert.equal(transitModeFor(ttc, '29', '4699'), 'tram'); + assert.equal(transitModeFor(ttc, '501', '4700'), 'bus'); + // A vehicle id that is not a fleet number leaves the route to decide. + assert.equal(transitModeFor(ttc, '501', 'abc'), 'tram'); + assert.equal(transitModeFor(ttc, '501'), 'tram'); +}); + test('the TTC row records that BusTime carries no subway', () => { const sources = readFileSync( new URL('../../DATA_SOURCES.md', import.meta.url), diff --git a/src/layers/transit/ingestion.js b/src/layers/transit/ingestion.js index cb610267e..be8833270 100644 --- a/src/layers/transit/ingestion.js +++ b/src/layers/transit/ingestion.js @@ -221,8 +221,12 @@ export function createIngestion({ state, services, parts, source }) { for (const record of records) { if (isStaleVehicleFix(record, now, fetchedAt)) continue; const key = transitVehicleKey(feed.id, record.id); - const mode = transitModeFor(feed, record.routeId); - const modeInferred = !transitModeResolved(feed, record.routeId); + const mode = transitModeFor(feed, record.routeId, record.id); + const modeInferred = !transitModeResolved( + feed, + record.routeId, + record.id, + ); // A stamp ahead of the fetch is a clock fault; the fetch time bounds it. const stamped = vehicleReportTimeMs(record, fetchedAt); const reportAt = diff --git a/src/sources/transitHistoryStore.js b/src/sources/transitHistoryStore.js index 36440975c..9fe29f59d 100644 --- a/src/sources/transitHistoryStore.js +++ b/src/sources/transitHistoryStore.js @@ -328,8 +328,12 @@ export function createTransitHistory({ t > now + 10000 ) continue; + const byVehicle = feed.vehicleMode?.(record.id); const mode = - feed.routeMode?.(record.routeId) || feed.defaultMode || 'unknown'; + (byVehicle !== 'unknown' && byVehicle) || + feed.routeMode?.(record.routeId) || + feed.defaultMode || + 'unknown'; const context = contextOf(record, mode); if (!context) continue; const key = `${feed.id}\u0000${record.id}`;