mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-18 17:22:19 +00:00
feat(transit): add Cairns and Adelaide Metro; mode hints for TransLink
- translink-cairns: TransLink CNS vehicle positions (keyless, CC BY 4.0, same open-data page as SEQ). - adelaide-metro: Adelaide Metro GTFS-R vehicle positions (keyless, CC BY 4.0 per the data.sa.gov.au catalogue). Its gateway negotiates on Accept and returns base64 protobuf as JSON for the proxy's default list, so the feed asks for application/x-google-protobuf. - TransLink route ids now resolve rail (station-pair codes), the Gold Coast light rail (L1) and ferries (F*, SMBI); buses, Brisbane Metro and the SHUT rail-replacement bus stay on the bus default. Adelaide trains, trams and the SeaLink ferry resolve from its static route list. Both rule sets checked against the operators' routes.txt. - Credits: "Translink, Department of Transport and Main Roads" and "Adelaide Metro – Department for Infrastructure and Transport, South Australia", each with its CC BY 4.0 link (generated per feed by transitFeedCredit). DATA_SOURCES rows follow the transit row style. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
1 parent
0d1a68160e
commit
015bf25a79
4 files changed
+239
-3
No files matched your search
@@ -376,6 +376,54 @@ function burlingtonRouteLabel(routeId) {
|
||||
return BURLINGTON_ROUTE_NAMES[routeId] || routeId;
|
||||
}
|
||||
|
||||
/**
|
||||
* TransLink (Queensland) route ids are `<route>-<version>`. Rail lines are two
|
||||
* two-letter station codes (`BRBN`, `SHCL`), ferries are `F<n>` plus the
|
||||
* Southern Moreton Bay Islands service `SMBI`, and the Gold Coast light rail
|
||||
* is `L1`. `SHUT` is the rail-replacement bus. Everything else is a bus, left
|
||||
* to the feed default so movement plausibility treats it as a guess.
|
||||
* @param {string|null} routeId
|
||||
* @returns {string}
|
||||
*/
|
||||
function translinkRouteMode(routeId) {
|
||||
if (!routeId) return 'unknown';
|
||||
const route = routeId.replace(/-\d+$/, '');
|
||||
if (/^F\d+$/.test(route) || route === 'SMBI') return 'ferry';
|
||||
if (route === 'L1') return 'tram';
|
||||
if (/^[A-Z]{4}$/.test(route) && route !== 'SHUT') return 'rail';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/** Adelaide Metro train and tram route ids, from its static routes.txt. */
|
||||
const ADELAIDE_RAIL_ROUTES = new Set([
|
||||
'BEL',
|
||||
'FLNDRS',
|
||||
'GAW',
|
||||
'GAWC',
|
||||
'GRNG',
|
||||
'NOAR',
|
||||
'OSBORN',
|
||||
'OUTHA',
|
||||
'PTDOCK',
|
||||
'SALIS',
|
||||
'SEAFRD',
|
||||
]);
|
||||
const ADELAIDE_TRAM_ROUTES = new Set(['BTANIC', 'FESTVL', 'GLNELG']);
|
||||
|
||||
/**
|
||||
* Adelaide Metro route ids are the line codes; all-letter bus routes exist
|
||||
* (`INDSTA`), so trains and trams are listed rather than pattern-matched.
|
||||
* @param {string|null} routeId
|
||||
* @returns {string}
|
||||
*/
|
||||
function adelaideMetroRouteMode(routeId) {
|
||||
if (!routeId) return 'unknown';
|
||||
if (ADELAIDE_RAIL_ROUTES.has(routeId)) return 'rail';
|
||||
if (ADELAIDE_TRAM_ROUTES.has(routeId)) return 'tram';
|
||||
if (routeId === 'SEALNK') return 'ferry';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
/**
|
||||
* Registry of feeds. Order is presentation order in the stats/credit text.
|
||||
* `loadRadiusKm` is the distance from `center` inside which the feed is polled.
|
||||
@@ -522,7 +570,7 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([
|
||||
url: 'https://gtfsrt.api.translink.com.au/api/realtime/seq/VehiclePositions',
|
||||
license: 'CC BY 4.0',
|
||||
licenseUrl: 'https://translink.com.au/about-translink/open-data',
|
||||
attribution: 'TransLink — Queensland Government (CC BY 4.0)',
|
||||
attribution: 'Translink, Department of Transport and Main Roads',
|
||||
defaultEnabled: true,
|
||||
terms: Object.freeze({
|
||||
quote:
|
||||
@@ -530,6 +578,53 @@ export const TRANSIT_FEED_REGISTRY = Object.freeze([
|
||||
note: 'No key, no stated rate limit, no caching rule. Logos and network imagery need separate approval, so the credit is text only.',
|
||||
}),
|
||||
defaultMode: 'bus',
|
||||
routeMode: translinkRouteMode,
|
||||
}),
|
||||
Object.freeze({
|
||||
id: 'translink-cairns',
|
||||
name: 'TransLink',
|
||||
operator: 'TransLink (Queensland Government)',
|
||||
region: 'Cairns, Australia',
|
||||
center: Object.freeze({ lat: -16.9186, lon: 145.7781 }),
|
||||
loadRadiusKm: 60,
|
||||
url: 'https://gtfsrt.api.translink.com.au/api/realtime/CNS/VehiclePositions',
|
||||
license: 'CC BY 4.0',
|
||||
licenseUrl: 'https://translink.com.au/about-translink/open-data',
|
||||
attribution: 'Translink, Department of Transport and Main Roads',
|
||||
defaultEnabled: true,
|
||||
terms: Object.freeze({
|
||||
quote:
|
||||
'Our data is licensed under a Creative Commons Attribution 4.0 International License. Authentication is not required to use the feed.',
|
||||
note: 'The same open-data page lists Cairns (CNS) vehicle positions beside South East Queensland; same terms, text-only credit.',
|
||||
}),
|
||||
defaultMode: 'bus',
|
||||
routeMode: translinkRouteMode,
|
||||
}),
|
||||
Object.freeze({
|
||||
id: 'adelaide-metro',
|
||||
name: 'Adelaide Metro',
|
||||
operator:
|
||||
'Adelaide Metro (Department for Infrastructure and Transport, South Australia)',
|
||||
region: 'Adelaide, Australia',
|
||||
center: Object.freeze({ lat: -34.9285, lon: 138.6007 }),
|
||||
loadRadiusKm: 80,
|
||||
url: 'https://gtfs.adelaidemetro.com.au/v1/realtime/vehicle_positions',
|
||||
// The gateway negotiates on Accept: the proxy's default list gets
|
||||
// application/json carrying base64 protobuf; its own type gets raw bytes.
|
||||
headers: Object.freeze({ Accept: 'application/x-google-protobuf' }),
|
||||
license: 'CC BY 4.0',
|
||||
licenseUrl:
|
||||
'https://data.sa.gov.au/data/dataset/adelaide-metro-real-time-passenger-information',
|
||||
attribution:
|
||||
'Adelaide Metro – Department for Infrastructure and Transport, South Australia',
|
||||
defaultEnabled: true,
|
||||
terms: Object.freeze({
|
||||
quote:
|
||||
'Adelaide Metro provides Real-Time information in SIRI and GTFS-R format',
|
||||
note: 'Quoted from the data.sa.gov.au catalogue entry "Adelaide Metro Real-Time Passenger Information", published by the Department for Infrastructure and Transport under Creative Commons Attribution 4.0. The feed needs no key (its API description declares no security scheme) and is marked BETA, subject to change. adelaidemetro.com.au refuses automated readers (HTTP 403).',
|
||||
}),
|
||||
defaultMode: 'bus',
|
||||
routeMode: adelaideMetroRouteMode,
|
||||
}),
|
||||
Object.freeze({
|
||||
id: 'ttc-toronto',
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { transitFeedCredit } from './dataCredits.js';
|
||||
import { transitUpstreamHeaders } from './transitProxy.js';
|
||||
import {
|
||||
getTransitFeed,
|
||||
publicTransitCatalog,
|
||||
transitFeedsInRange,
|
||||
transitModeFor,
|
||||
transitModeResolved,
|
||||
} from './transitFeeds.js';
|
||||
|
||||
// Route ids below are as published in the live feeds and the operators'
|
||||
// static routes.txt (checked 16 Oct 2026).
|
||||
|
||||
test('Australian feeds are keyless, routable and cover their own city only', () => {
|
||||
const seq = getTransitFeed('translink-seq');
|
||||
const cairns = getTransitFeed('translink-cairns');
|
||||
const adelaide = getTransitFeed('adelaide-metro');
|
||||
assert.equal(
|
||||
cairns.url,
|
||||
'https://gtfsrt.api.translink.com.au/api/realtime/CNS/VehiclePositions',
|
||||
);
|
||||
assert.equal(
|
||||
adelaide.url,
|
||||
'https://gtfs.adelaidemetro.com.au/v1/realtime/vehicle_positions',
|
||||
);
|
||||
for (const feed of [seq, cairns]) {
|
||||
assert.equal(feed.headers, undefined, `${feed.id} needs no extra header`);
|
||||
}
|
||||
for (const feed of [seq, cairns, adelaide]) {
|
||||
assert.equal(feed.license, 'CC BY 4.0');
|
||||
}
|
||||
const ids = (lat, lon) => transitFeedsInRange(lat, lon).map((f) => f.id);
|
||||
assert.deepEqual(ids(-27.4698, 153.0251), ['translink-seq']);
|
||||
assert.deepEqual(ids(-16.9186, 145.7781), ['translink-cairns']);
|
||||
assert.deepEqual(ids(-34.9285, 138.6007), ['adelaide-metro']);
|
||||
assert.deepEqual(ids(-37.8136, 144.9631), [], 'Melbourne has no feed');
|
||||
});
|
||||
|
||||
test('Adelaide is asked for its own protobuf type, or its gateway answers base64 JSON', () => {
|
||||
// Offered the default Accept list (application/x-protobuf, ..., */*), the
|
||||
// Adelaide Metro gateway replies application/json carrying the protobuf as
|
||||
// base64, which the decoder rejects. Its own media type gets raw protobuf.
|
||||
const adelaide = getTransitFeed('adelaide-metro');
|
||||
assert.deepEqual(Object.keys(adelaide.headers), ['Accept']);
|
||||
const headers = transitUpstreamHeaders(adelaide);
|
||||
assert.equal(headers.Accept, 'application/x-google-protobuf');
|
||||
assert.equal(headers['Accept-Encoding'], 'gzip');
|
||||
assert.match(headers['User-Agent'], /gods-eye-view/);
|
||||
});
|
||||
|
||||
test('TransLink route ids resolve rail, light rail and ferries; buses stay a default', () => {
|
||||
const seq = getTransitFeed('translink-seq');
|
||||
const cases = [
|
||||
['BRBN-5187', 'rail'],
|
||||
['SHCL-5187', 'rail'],
|
||||
['RPIP-5201', 'rail'],
|
||||
['L1-5029', 'tram'],
|
||||
['F1-4055', 'ferry'],
|
||||
['F23-4055', 'ferry'],
|
||||
['F50-4430', 'ferry'],
|
||||
['SMBI-3779', 'ferry'],
|
||||
];
|
||||
for (const [routeId, mode] of cases) {
|
||||
assert.equal(transitModeFor(seq, routeId), mode, routeId);
|
||||
assert.equal(transitModeResolved(seq, routeId), true, routeId);
|
||||
}
|
||||
// Buses, Brisbane Metro and the rail-replacement shuttle are buses by the
|
||||
// feed default, so movement plausibility does not treat them as known.
|
||||
for (const routeId of ['600', '250-5169', 'M1-4949', 'SHUT-5213', null]) {
|
||||
assert.equal(transitModeFor(seq, routeId), 'bus', String(routeId));
|
||||
assert.equal(transitModeResolved(seq, routeId), false, String(routeId));
|
||||
}
|
||||
const cairns = getTransitFeed('translink-cairns');
|
||||
assert.equal(transitModeFor(cairns, 'C111-5061'), 'bus');
|
||||
assert.equal(transitModeResolved(cairns, 'C111-5061'), false);
|
||||
});
|
||||
|
||||
test('Adelaide Metro route ids resolve trains, trams and the SeaLink ferry', () => {
|
||||
const adelaide = getTransitFeed('adelaide-metro');
|
||||
const cases = [
|
||||
['BEL', 'rail'],
|
||||
['GAWC', 'rail'],
|
||||
['OUTHA', 'rail'],
|
||||
['SEAFRD', 'rail'],
|
||||
['PTDOCK', 'rail'],
|
||||
['BTANIC', 'tram'],
|
||||
['GLNELG', 'tram'],
|
||||
['FESTVL', 'tram'],
|
||||
['SEALNK', 'ferry'],
|
||||
];
|
||||
for (const [routeId, mode] of cases) {
|
||||
assert.equal(transitModeFor(adelaide, routeId), mode, routeId);
|
||||
assert.equal(transitModeResolved(adelaide, routeId), true, routeId);
|
||||
}
|
||||
// All-letter bus routes exist (INDSTA/INDSTB), so letters alone are not rail.
|
||||
for (const routeId of ['100', 'G10', 'H33C', 'INDSTA', 'T721', null]) {
|
||||
assert.equal(transitModeFor(adelaide, routeId), 'bus', String(routeId));
|
||||
assert.equal(
|
||||
transitModeResolved(adelaide, routeId),
|
||||
false,
|
||||
String(routeId),
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('Australian feeds credit the operator and department as text', () => {
|
||||
const credit = (id) =>
|
||||
transitFeedCredit(publicTransitCatalog().find((feed) => feed.id === id))
|
||||
.html;
|
||||
for (const id of ['translink-seq', 'translink-cairns']) {
|
||||
assert.match(
|
||||
credit(id),
|
||||
/^Transit \(Translink, Department of Transport and Main Roads\): <a href="https:\/\/translink\.com\.au\/about-translink\/open-data"[^>]*>CC BY 4\.0<\/a>$/,
|
||||
);
|
||||
}
|
||||
assert.match(
|
||||
credit('adelaide-metro'),
|
||||
/^Transit \(Adelaide Metro – Department for Infrastructure and Transport, South Australia\): <a href="https:\/\/data\.sa\.gov\.au\/[^"]+"[^>]*>CC BY 4\.0<\/a>$/,
|
||||
);
|
||||
});
|
||||
|
||||
test('DATA_SOURCES documents the Australian feeds in the transit row style', () => {
|
||||
const rows = readFileSync(
|
||||
new URL('../../DATA_SOURCES.md', import.meta.url),
|
||||
'utf8',
|
||||
).split('\n');
|
||||
const translink = rows.find((line) => line.startsWith('| **TransLink**'));
|
||||
assert.match(translink, /South East Queensland and Cairns/);
|
||||
const adelaide = rows.find((line) => line.startsWith('| **Adelaide Metro**'));
|
||||
assert.ok(adelaide, 'Adelaide Metro row exists');
|
||||
for (const row of [translink, adelaide]) {
|
||||
assert.match(row, /open realtime vehicle data/);
|
||||
assert.match(row, /published for developer use and not against their use/);
|
||||
assert.doesNotMatch(row, /licen[cs]e|CC BY|terms/i);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user