feat(transit): let a feed name its own modes, and call TTC trams streetcars

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.
This commit is contained in:
Cliff Flood committed 2026-10-15 20:18:15 -04:00
1 parent c5f7fe285b
commit 9fc4a5ac04
4 files changed
+125 -9

No files matched your search

+42 -4
View File
@@ -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;
}