mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 10:24:02 +00:00
Merge pull request #634 from cliph/feat/transit-ontario
Add nine Ontario transit feeds, with per-feed mode and route naming
This commit is contained in:
12 files changed
+955
-28
No files matched your search
@@ -1,5 +1,13 @@
|
||||
# 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. 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.
|
||||
|
||||
- CCTV cameras with identified hardware show the model's datasheet specs. When a
|
||||
source names a camera model found in the vendored CCTV Camera Database records
|
||||
(CC0), the HUD meta line adds its resolution, night vision and PTZ capability.
|
||||
|
||||
+10
-1
@@ -78,6 +78,15 @@ 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 |
|
||||
| **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. 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 |
|
||||
| **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 |
|
||||
@@ -156,7 +165,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 `[email protected]` 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/<uuid>/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 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.
|
||||
|
||||
@@ -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 | 🟡 |
|
||||
|
||||
@@ -3681,8 +3681,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. Seven keyless regions are available: Boston, Austin, Minneapolis–St Paul,
|
||||
Helsinki, the Netherlands, Norway and South East Queensland. 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
|
||||
|
||||
@@ -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');
|
||||
});
|
||||
+498
-7
@@ -115,6 +115,265 @@ 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';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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_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',
|
||||
});
|
||||
|
||||
/**
|
||||
* YRT route id to the name a rider would say.
|
||||
* @param {string|null} routeId
|
||||
* @returns {string|null}
|
||||
*/
|
||||
function yrtRouteLabel(routeId) {
|
||||
return YRT_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.
|
||||
@@ -270,6 +529,204 @@ 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',
|
||||
// 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,
|
||||
vehicleMode: ttcVehicleMode,
|
||||
}),
|
||||
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',
|
||||
routeLabel: hamiltonRouteLabel,
|
||||
}),
|
||||
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',
|
||||
}),
|
||||
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: 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: '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',
|
||||
}),
|
||||
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: 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: '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,
|
||||
}),
|
||||
]);
|
||||
|
||||
/**
|
||||
@@ -353,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';
|
||||
@@ -373,16 +848,32 @@ 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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
transitFeedsInRange,
|
||||
transitModeFor,
|
||||
transitModeResolved,
|
||||
transitRouteLabel,
|
||||
} from './transitFeeds.js';
|
||||
|
||||
test('every registered feed is keyless, https, licensed, and uniquely identified', () => {
|
||||
@@ -239,3 +240,245 @@ 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('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),
|
||||
'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/);
|
||||
});
|
||||
|
||||
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/);
|
||||
});
|
||||
|
||||
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('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('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.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 = 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('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('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.
|
||||
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');
|
||||
});
|
||||
@@ -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 =
|
||||
|
||||
@@ -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}`;
|
||||
@@ -345,7 +348,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,17 +482,50 @@ 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
|
||||
* 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'));
|
||||
@@ -521,7 +557,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 +574,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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -128,14 +143,17 @@ 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) {
|
||||
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 +164,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.
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import {
|
||||
buildTransitSelectionCopy,
|
||||
transitDetectionClass,
|
||||
transitDetectionId,
|
||||
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/);
|
||||
});
|
||||
|
||||
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');
|
||||
});
|
||||
@@ -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}`;
|
||||
|
||||
Reference in new issue
Block a user