VBB: don't convert 7/9 <-> 12 digit IDs 💥

This commit is contained in:
Jannis R 2021-12-29 18:12:33 +01:00
parent df4124e31d
commit 5ecf03f349
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
5 changed files with 46 additions and 74 deletions

View file

@ -1,10 +1,8 @@
'use strict' 'use strict'
const shorten = require('vbb-short-station-name') const shorten = require('vbb-short-station-name')
const {to12Digit, to9Digit} = require('vbb-translate-ids')
const parseLineName = require('vbb-parse-line') const parseLineName = require('vbb-parse-line')
const parseTicket = require('vbb-parse-ticket') const parseTicket = require('vbb-parse-ticket')
const getStations = require('vbb-stations')
const {parseHook} = require('../../lib/profile-hooks') const {parseHook} = require('../../lib/profile-hooks')
const parseAndAddLocationDHID = require('./parse-loc-dhid') const parseAndAddLocationDHID = require('./parse-loc-dhid')
@ -12,7 +10,6 @@ const _parseLine = require('../../parse/line')
const _parseLocation = require('../../parse/location') const _parseLocation = require('../../parse/location')
const _parseJourney = require('../../parse/journey') const _parseJourney = require('../../parse/journey')
const _parseDeparture = require('../../parse/departure') const _parseDeparture = require('../../parse/departure')
const _formatStation = require('../../format/station')
const baseProfile = require('./base.json') const baseProfile = require('./base.json')
const products = require('./products') const products = require('./products')
@ -31,15 +28,6 @@ const parseLineWithMoreDetails = ({parsed}, p) => {
} }
const parseLocation = ({parsed}, l) => { const parseLocation = ({parsed}, l) => {
if ((parsed.type === 'stop' || parsed.type === 'station') && parsed.id[0] === '9') {
parsed.name = shorten(parsed.name)
parsed.id = to12Digit(parsed.id)
if (!parsed.location.latitude || !parsed.location.longitude) {
const [s] = getStations(parsed.id)
if (s) Object.assign(parsed.location, s.location)
}
}
parseAndAddLocationDHID(parsed, l) parseAndAddLocationDHID(parsed, l)
return parsed return parsed
} }
@ -80,18 +68,6 @@ const parseDepartureRenameRingbahn = ({parsed}) => {
return parsed return parsed
} }
const validIBNR = /^\d+$/
const formatStation = (id) => {
if ('string' !== typeof id) throw new TypeError('station ID must be a string.')
if (!validIBNR.test(id)) {
throw new Error('station ID must be a valid IBNR.')
}
// The VBB has some 7-digit stations. We don't convert them to 12 digits,
// because it only recognizes in the 7-digit format. see derhuerst/vbb-hafas#22
if (id.length !== 7) id = to9Digit(id)
return _formatStation(id)
}
const vbbProfile = { const vbbProfile = {
...baseProfile, ...baseProfile,
locale: 'de-DE', locale: 'de-DE',
@ -105,8 +81,6 @@ const vbbProfile = {
parseJourney: parseHook(_parseJourney, parseJourneyWithTickets), parseJourney: parseHook(_parseJourney, parseJourneyWithTickets),
parseDeparture: parseHook(_parseDeparture, parseDepartureRenameRingbahn), parseDeparture: parseHook(_parseDeparture, parseDepartureRenameRingbahn),
formatStation,
journeysWalkingSpeed: true, journeysWalkingSpeed: true,
refreshJourneyUseOutReconL: true, refreshJourneyUseOutReconL: true,
trip: true, trip: true,

View file

@ -63,9 +63,7 @@
"slugg": "^1.2.0", "slugg": "^1.2.0",
"vbb-parse-line": "^1.0.0", "vbb-parse-line": "^1.0.0",
"vbb-parse-ticket": "^0.2.1", "vbb-parse-ticket": "^0.2.1",
"vbb-short-station-name": "^1.0.1", "vbb-short-station-name": "^1.0.1"
"vbb-stations": "^7.1.0",
"vbb-translate-ids": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^7.0.0", "eslint": "^7.0.0",

View file

@ -37,12 +37,12 @@ const validate = createValidate(cfg, {
const client = createClient(vbbProfile, 'public-transport/hafas-client:test') const client = createClient(vbbProfile, 'public-transport/hafas-client:test')
const amrumerStr = '900000009101' const amrumerStr = '900009101'
const spichernstr = '900000042101' const spichernstr = '900042101'
const bismarckstr = '900000024201' const bismarckstr = '900024201'
const westhafen = '900000001201' const westhafen = '900001201'
const wedding = '900000009104' const wedding = '900009104'
const württembergallee = '900000026153' const württembergallee = '900026153'
tap.test('journeys Spichernstr. to Bismarckstr.', async (t) => { tap.test('journeys Spichernstr. to Bismarckstr.', async (t) => {
const res = await client.journeys({ const res = await client.journeys({
@ -123,7 +123,7 @@ tap.test('journeys: walkingSpeed', async (t) => {
latitude: 52.443576, latitude: 52.443576,
longitude: 13.198973 longitude: 13.198973
} }
const wannsee = '900000053301' const wannsee = '900053301'
await testJourneysWalkingSpeed({ await testJourneysWalkingSpeed({
test: t, test: t,
@ -343,8 +343,8 @@ tap.test('arrivals', async (t) => {
}) })
tap.test('nearby', async (t) => { tap.test('nearby', async (t) => {
const berlinerStr = '900000044201' const berlinerStr = '900044201'
const landhausstr = '900000043252' const landhausstr = '900043252'
// Berliner Str./Bundesallee // Berliner Str./Bundesallee
const nearby = await client.nearby({ const nearby = await client.nearby({

View file

@ -5,7 +5,7 @@ module.exports = [
tripId: '1|24934|5|86|12102021', tripId: '1|24934|5|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -201,7 +201,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: "stop", type: "stop",
id: "900000310004", id: "900310004",
stationDHID: 'de:12067:900310004', stationDHID: 'de:12067:900310004',
name: "S Erkner", name: "S Erkner",
location: { location: {
@ -280,7 +280,7 @@ module.exports = [
tripId: '1|12106|15|86|12102021', tripId: '1|12106|15|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -525,7 +525,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: "stop", type: "stop",
id: "900000005207", id: "900005207",
stationDHID: 'de:11000:900005207', stationDHID: 'de:11000:900005207',
name: "Philharmonie Süd", name: "Philharmonie Süd",
location: { location: {
@ -554,7 +554,7 @@ module.exports = [
tripId: '1|23076|26|86|12102021', tripId: '1|23076|26|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -800,7 +800,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: "stop", type: "stop",
id: "900000079221", id: "900079221",
stationDHID: 'de:11000:900079221', stationDHID: 'de:11000:900079221',
name: "S+U Hermannstr.", name: "S+U Hermannstr.",
location: { location: {
@ -829,7 +829,7 @@ module.exports = [
tripId: '1|23117|2|86|12102021', tripId: '1|23117|2|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -1075,7 +1075,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000096197', id: '900096197',
stationDHID: 'de:11000:900096197', stationDHID: 'de:11000:900096197',
name: 'S+U Wittenau [U8]', name: 'S+U Wittenau [U8]',
location: { location: {
@ -1104,7 +1104,7 @@ module.exports = [
tripId: '1|25978|5|86|12102021', tripId: '1|25978|5|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -1350,7 +1350,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000024102', id: '900024102',
stationDHID: 'de:11000:900024102', stationDHID: 'de:11000:900024102',
name: 'S Westkreuz', name: 'S Westkreuz',
location: { location: {
@ -1379,7 +1379,7 @@ module.exports = [
tripId: '1|26593|10|86|12102021', tripId: '1|26593|10|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -1625,7 +1625,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000170004', id: '900170004',
stationDHID: 'de:11000:900170004', stationDHID: 'de:11000:900170004',
name: 'S Ahrensfelde', name: 'S Ahrensfelde',
location: { location: {
@ -1654,7 +1654,7 @@ module.exports = [
tripId: '1|26662|10|86|12102021', tripId: '1|26662|10|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -1900,7 +1900,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000230999', id: '900230999',
stationDHID: 'de:12054:900230999', stationDHID: 'de:12054:900230999',
name: 'S Potsdam Hauptbahnhof', name: 'S Potsdam Hauptbahnhof',
location: { location: {
@ -1929,7 +1929,7 @@ module.exports = [
tripId: '1|26077|2|86|12102021', tripId: '1|26077|2|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -2175,7 +2175,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000320004', id: '900320004',
stationDHID: 'de:12064:900320004', stationDHID: 'de:12064:900320004',
name: 'S Strausberg', name: 'S Strausberg',
location: { location: {
@ -2204,7 +2204,7 @@ module.exports = [
tripId: '1|23049|34|86|12102021', tripId: '1|23049|34|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -2450,7 +2450,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000079221', id: '900079221',
stationDHID: 'de:11000:900079221', stationDHID: 'de:11000:900079221',
name: 'S+U Hermannstr.', name: 'S+U Hermannstr.',
location: { location: {
@ -2479,7 +2479,7 @@ module.exports = [
tripId: '1|23111|31|86|12102021', tripId: '1|23111|31|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -2725,7 +2725,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000085104', id: '900085104',
stationDHID: 'de:11000:900085104', stationDHID: 'de:11000:900085104',
name: 'U Paracelsus-Bad', name: 'U Paracelsus-Bad',
location: { location: {
@ -2754,7 +2754,7 @@ module.exports = [
tripId: '1|12062|15|86|12102021', tripId: '1|12062|15|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -2999,7 +2999,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000120004', id: '900120004',
stationDHID: 'de:11000:900120004', stationDHID: 'de:11000:900120004',
name: 'S+U Warschauer Str.', name: 'S+U Warschauer Str.',
location: { location: {
@ -3028,7 +3028,7 @@ module.exports = [
tripId: '1|27181|9|86|12102021', tripId: '1|27181|9|86|12102021',
stop: { stop: {
type: 'stop', type: 'stop',
id: '900000100004', id: '900100004',
stationDHID: 'de:11000:900100004', stationDHID: 'de:11000:900100004',
name: 'S+U Jannowitzbrücke', name: 'S+U Jannowitzbrücke',
location: { location: {
@ -3274,7 +3274,7 @@ module.exports = [
origin: null, origin: null,
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000029101', id: '900029101',
stationDHID: 'de:11000:900029101', stationDHID: 'de:11000:900029101',
name: 'S Spandau', name: 'S Spandau',
location: { location: {

View file

@ -5,7 +5,7 @@ module.exports = [{
legs: [{ legs: [{
origin: { origin: {
type: 'stop', type: 'stop',
id: '900000042101', id: '900042101',
name: 'U Spichernstr.', name: 'U Spichernstr.',
location: { location: {
type: 'location', type: 'location',
@ -25,7 +25,7 @@ module.exports = [{
}, },
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000001201', id: '900001201',
name: 'S+U Westhafen', name: 'S+U Westhafen',
location: { location: {
type: 'location', type: 'location',
@ -83,7 +83,7 @@ module.exports = [{
}, { }, {
origin: { origin: {
type: 'stop', type: 'stop',
id: '900000001201', id: '900001201',
name: 'S+U Westhafen', name: 'S+U Westhafen',
location: { location: {
type: 'location', type: 'location',
@ -103,7 +103,7 @@ module.exports = [{
}, },
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000007102', id: '900007102',
name: 'S+U Gesundbrunnen', name: 'S+U Gesundbrunnen',
location: { location: {
type: 'location', type: 'location',
@ -161,7 +161,7 @@ module.exports = [{
}, { }, {
origin: { origin: {
type: 'stop', type: 'stop',
id: '900000007102', id: '900007102',
name: 'S+U Gesundbrunnen', name: 'S+U Gesundbrunnen',
location: { location: {
type: 'location', type: 'location',
@ -181,7 +181,7 @@ module.exports = [{
}, },
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000350127', id: '900350127',
name: 'Eberswalde, Hbf', name: 'Eberswalde, Hbf',
location: { location: {
type: 'location', type: 'location',
@ -305,7 +305,7 @@ module.exports = [{
legs: [{ legs: [{
origin: { origin: {
type: 'stop', type: 'stop',
id: '900000042101', id: '900042101',
name: 'U Spichernstr.', name: 'U Spichernstr.',
location: { location: {
type: 'location', type: 'location',
@ -325,7 +325,7 @@ module.exports = [{
}, },
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000001201', id: '900001201',
name: 'S+U Westhafen', name: 'S+U Westhafen',
location: { location: {
type: 'location', type: 'location',
@ -383,7 +383,7 @@ module.exports = [{
}, { }, {
origin: { origin: {
type: 'stop', type: 'stop',
id: '900000001201', id: '900001201',
name: 'S+U Westhafen', name: 'S+U Westhafen',
location: { location: {
type: 'location', type: 'location',
@ -403,7 +403,7 @@ module.exports = [{
}, },
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000007102', id: '900007102',
name: 'S+U Gesundbrunnen', name: 'S+U Gesundbrunnen',
location: { location: {
type: 'location', type: 'location',
@ -462,7 +462,7 @@ module.exports = [{
}, { }, {
origin: { origin: {
type: 'stop', type: 'stop',
id: '900000007102', id: '900007102',
name: 'S+U Gesundbrunnen', name: 'S+U Gesundbrunnen',
location: { location: {
type: 'location', type: 'location',
@ -482,7 +482,7 @@ module.exports = [{
}, },
destination: { destination: {
type: 'stop', type: 'stop',
id: '900000350127', id: '900350127',
name: 'Eberswalde, Hbf', name: 'Eberswalde, Hbf',
location: { location: {
type: 'location', type: 'location',