feat(transit): add Rio de Janeiro buses and BRT (SMTR GTFS-RT, CC BY 4.0)

Register Rio's two keyless GTFS-Realtime VehiclePositions feeds from the
city transport secretariat (SMTR): municipal buses (SPPO) and the
Mobi-Rio BRT, the Transit layer's first Latin American region.

Both feeds publish Position.speed in km/h instead of m/s. A new optional
registry field, speedUnit: 'kmh', makes buildTransitSnapshot convert it
once, so every speedMps consumer stays correct and other feeds are
untouched.

Document the source in DATA_SOURCES.md and update the region lists in
README.md and docs/CURRENT-STATE.md.

Refs #1480

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Itallo BrandãoandClaude Opus 5.5 committed 2026-10-29 16:11:10 -03:00
1 parent f13c60c477
commit a4c7b20ca8
7 files changed
+147 -6

No files matched your search

+26
View File
@@ -137,6 +137,7 @@ function encodeFeed({
const position = new PbfWriter();
position.writeFloatField(1, entity.lat);
position.writeFloatField(2, entity.lon);
if (entity.speed != null) position.writeFloatField(5, entity.speed);
vehicle.writeBytesField(2, position.finish());
if (entity.timestamp) vehicle.writeVarintField(5, entity.timestamp);
const descriptor = new PbfWriter();
@@ -284,6 +285,31 @@ test('the snapshot builder fills timestamps from the header it decoded', () => {
assert.equal(snapshot.feedTimestamp, 1_700_000_000);
});
test('a feed that publishes km/h has its speeds converted to m/s, and only that feed', () => {
// Rio's SMTR feeds put km/h in Position.speed; read as m/s, a 36 km/h bus
// would be reported at 130 km/h.
const bytes = encodeFeed({
entities: [
{ id: 'moving', lat: -22.9, lon: -43.2, speed: 36 },
{ id: 'still', lat: -22.9, lon: -43.2, speed: 0 },
{ id: 'silent', lat: -22.9, lon: -43.2 },
],
});
const rio = buildTransitSnapshot(getTransitFeed('smtr-rio-onibus'), bytes, 1);
const speeds = Object.fromEntries(
rio.vehicles.map((vehicle) => [vehicle.id, vehicle.speedMps]),
);
assert.ok(Math.abs(speeds.moving - 10) < 1e-6, '36 km/h is 10 m/s');
assert.equal(speeds.still, 0);
assert.equal(speeds.silent, null, 'an absent speed stays absent');
const mbta = buildTransitSnapshot(getTransitFeed('mbta'), bytes, 1);
assert.equal(
mbta.vehicles.find((vehicle) => vehicle.id === 'moving').speedMps,
36,
'a spec-conforming feed is left alone',
);
});
test('conditional-request validators and gzip ride along with feed identification', () => {
const entur = getTransitFeed('entur-norway');
const plain = transitUpstreamHeaders(entur);