mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
VBB: don't convert 7/9 <-> 12 digit IDs 💥✅
This commit is contained in:
parent
df4124e31d
commit
5ecf03f349
5 changed files with 46 additions and 74 deletions
|
@ -1,10 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
const shorten = require('vbb-short-station-name')
|
||||
const {to12Digit, to9Digit} = require('vbb-translate-ids')
|
||||
const parseLineName = require('vbb-parse-line')
|
||||
const parseTicket = require('vbb-parse-ticket')
|
||||
const getStations = require('vbb-stations')
|
||||
const {parseHook} = require('../../lib/profile-hooks')
|
||||
|
||||
const parseAndAddLocationDHID = require('./parse-loc-dhid')
|
||||
|
@ -12,7 +10,6 @@ const _parseLine = require('../../parse/line')
|
|||
const _parseLocation = require('../../parse/location')
|
||||
const _parseJourney = require('../../parse/journey')
|
||||
const _parseDeparture = require('../../parse/departure')
|
||||
const _formatStation = require('../../format/station')
|
||||
|
||||
const baseProfile = require('./base.json')
|
||||
const products = require('./products')
|
||||
|
@ -31,15 +28,6 @@ const parseLineWithMoreDetails = ({parsed}, p) => {
|
|||
}
|
||||
|
||||
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)
|
||||
return parsed
|
||||
}
|
||||
|
@ -80,18 +68,6 @@ const parseDepartureRenameRingbahn = ({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 = {
|
||||
...baseProfile,
|
||||
locale: 'de-DE',
|
||||
|
@ -105,8 +81,6 @@ const vbbProfile = {
|
|||
parseJourney: parseHook(_parseJourney, parseJourneyWithTickets),
|
||||
parseDeparture: parseHook(_parseDeparture, parseDepartureRenameRingbahn),
|
||||
|
||||
formatStation,
|
||||
|
||||
journeysWalkingSpeed: true,
|
||||
refreshJourneyUseOutReconL: true,
|
||||
trip: true,
|
||||
|
|
|
@ -63,9 +63,7 @@
|
|||
"slugg": "^1.2.0",
|
||||
"vbb-parse-line": "^1.0.0",
|
||||
"vbb-parse-ticket": "^0.2.1",
|
||||
"vbb-short-station-name": "^1.0.1",
|
||||
"vbb-stations": "^7.1.0",
|
||||
"vbb-translate-ids": "^4.0.0"
|
||||
"vbb-short-station-name": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.0.0",
|
||||
|
|
|
@ -37,12 +37,12 @@ const validate = createValidate(cfg, {
|
|||
|
||||
const client = createClient(vbbProfile, 'public-transport/hafas-client:test')
|
||||
|
||||
const amrumerStr = '900000009101'
|
||||
const spichernstr = '900000042101'
|
||||
const bismarckstr = '900000024201'
|
||||
const westhafen = '900000001201'
|
||||
const wedding = '900000009104'
|
||||
const württembergallee = '900000026153'
|
||||
const amrumerStr = '900009101'
|
||||
const spichernstr = '900042101'
|
||||
const bismarckstr = '900024201'
|
||||
const westhafen = '900001201'
|
||||
const wedding = '900009104'
|
||||
const württembergallee = '900026153'
|
||||
|
||||
tap.test('journeys – Spichernstr. to Bismarckstr.', async (t) => {
|
||||
const res = await client.journeys({
|
||||
|
@ -123,7 +123,7 @@ tap.test('journeys: walkingSpeed', async (t) => {
|
|||
latitude: 52.443576,
|
||||
longitude: 13.198973
|
||||
}
|
||||
const wannsee = '900000053301'
|
||||
const wannsee = '900053301'
|
||||
|
||||
await testJourneysWalkingSpeed({
|
||||
test: t,
|
||||
|
@ -343,8 +343,8 @@ tap.test('arrivals', async (t) => {
|
|||
})
|
||||
|
||||
tap.test('nearby', async (t) => {
|
||||
const berlinerStr = '900000044201'
|
||||
const landhausstr = '900000043252'
|
||||
const berlinerStr = '900044201'
|
||||
const landhausstr = '900043252'
|
||||
|
||||
// Berliner Str./Bundesallee
|
||||
const nearby = await client.nearby({
|
||||
|
|
48
test/fixtures/vbb-departures.js
vendored
48
test/fixtures/vbb-departures.js
vendored
|
@ -5,7 +5,7 @@ module.exports = [
|
|||
tripId: '1|24934|5|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -201,7 +201,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: "stop",
|
||||
id: "900000310004",
|
||||
id: "900310004",
|
||||
stationDHID: 'de:12067:900310004',
|
||||
name: "S Erkner",
|
||||
location: {
|
||||
|
@ -280,7 +280,7 @@ module.exports = [
|
|||
tripId: '1|12106|15|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -525,7 +525,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: "stop",
|
||||
id: "900000005207",
|
||||
id: "900005207",
|
||||
stationDHID: 'de:11000:900005207',
|
||||
name: "Philharmonie Süd",
|
||||
location: {
|
||||
|
@ -554,7 +554,7 @@ module.exports = [
|
|||
tripId: '1|23076|26|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -800,7 +800,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: "stop",
|
||||
id: "900000079221",
|
||||
id: "900079221",
|
||||
stationDHID: 'de:11000:900079221',
|
||||
name: "S+U Hermannstr.",
|
||||
location: {
|
||||
|
@ -829,7 +829,7 @@ module.exports = [
|
|||
tripId: '1|23117|2|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -1075,7 +1075,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000096197',
|
||||
id: '900096197',
|
||||
stationDHID: 'de:11000:900096197',
|
||||
name: 'S+U Wittenau [U8]',
|
||||
location: {
|
||||
|
@ -1104,7 +1104,7 @@ module.exports = [
|
|||
tripId: '1|25978|5|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -1350,7 +1350,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000024102',
|
||||
id: '900024102',
|
||||
stationDHID: 'de:11000:900024102',
|
||||
name: 'S Westkreuz',
|
||||
location: {
|
||||
|
@ -1379,7 +1379,7 @@ module.exports = [
|
|||
tripId: '1|26593|10|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -1625,7 +1625,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000170004',
|
||||
id: '900170004',
|
||||
stationDHID: 'de:11000:900170004',
|
||||
name: 'S Ahrensfelde',
|
||||
location: {
|
||||
|
@ -1654,7 +1654,7 @@ module.exports = [
|
|||
tripId: '1|26662|10|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -1900,7 +1900,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000230999',
|
||||
id: '900230999',
|
||||
stationDHID: 'de:12054:900230999',
|
||||
name: 'S Potsdam Hauptbahnhof',
|
||||
location: {
|
||||
|
@ -1929,7 +1929,7 @@ module.exports = [
|
|||
tripId: '1|26077|2|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -2175,7 +2175,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000320004',
|
||||
id: '900320004',
|
||||
stationDHID: 'de:12064:900320004',
|
||||
name: 'S Strausberg',
|
||||
location: {
|
||||
|
@ -2204,7 +2204,7 @@ module.exports = [
|
|||
tripId: '1|23049|34|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -2450,7 +2450,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000079221',
|
||||
id: '900079221',
|
||||
stationDHID: 'de:11000:900079221',
|
||||
name: 'S+U Hermannstr.',
|
||||
location: {
|
||||
|
@ -2479,7 +2479,7 @@ module.exports = [
|
|||
tripId: '1|23111|31|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -2725,7 +2725,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000085104',
|
||||
id: '900085104',
|
||||
stationDHID: 'de:11000:900085104',
|
||||
name: 'U Paracelsus-Bad',
|
||||
location: {
|
||||
|
@ -2754,7 +2754,7 @@ module.exports = [
|
|||
tripId: '1|12062|15|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -2999,7 +2999,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000120004',
|
||||
id: '900120004',
|
||||
stationDHID: 'de:11000:900120004',
|
||||
name: 'S+U Warschauer Str.',
|
||||
location: {
|
||||
|
@ -3028,7 +3028,7 @@ module.exports = [
|
|||
tripId: '1|27181|9|86|12102021',
|
||||
stop: {
|
||||
type: 'stop',
|
||||
id: '900000100004',
|
||||
id: '900100004',
|
||||
stationDHID: 'de:11000:900100004',
|
||||
name: 'S+U Jannowitzbrücke',
|
||||
location: {
|
||||
|
@ -3274,7 +3274,7 @@ module.exports = [
|
|||
origin: null,
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000029101',
|
||||
id: '900029101',
|
||||
stationDHID: 'de:11000:900029101',
|
||||
name: 'S Spandau',
|
||||
location: {
|
||||
|
|
24
test/fixtures/vbb-journeys.js
vendored
24
test/fixtures/vbb-journeys.js
vendored
|
@ -5,7 +5,7 @@ module.exports = [{
|
|||
legs: [{
|
||||
origin: {
|
||||
type: 'stop',
|
||||
id: '900000042101',
|
||||
id: '900042101',
|
||||
name: 'U Spichernstr.',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -25,7 +25,7 @@ module.exports = [{
|
|||
},
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000001201',
|
||||
id: '900001201',
|
||||
name: 'S+U Westhafen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -83,7 +83,7 @@ module.exports = [{
|
|||
}, {
|
||||
origin: {
|
||||
type: 'stop',
|
||||
id: '900000001201',
|
||||
id: '900001201',
|
||||
name: 'S+U Westhafen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -103,7 +103,7 @@ module.exports = [{
|
|||
},
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000007102',
|
||||
id: '900007102',
|
||||
name: 'S+U Gesundbrunnen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -161,7 +161,7 @@ module.exports = [{
|
|||
}, {
|
||||
origin: {
|
||||
type: 'stop',
|
||||
id: '900000007102',
|
||||
id: '900007102',
|
||||
name: 'S+U Gesundbrunnen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -181,7 +181,7 @@ module.exports = [{
|
|||
},
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000350127',
|
||||
id: '900350127',
|
||||
name: 'Eberswalde, Hbf',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -305,7 +305,7 @@ module.exports = [{
|
|||
legs: [{
|
||||
origin: {
|
||||
type: 'stop',
|
||||
id: '900000042101',
|
||||
id: '900042101',
|
||||
name: 'U Spichernstr.',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -325,7 +325,7 @@ module.exports = [{
|
|||
},
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000001201',
|
||||
id: '900001201',
|
||||
name: 'S+U Westhafen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -383,7 +383,7 @@ module.exports = [{
|
|||
}, {
|
||||
origin: {
|
||||
type: 'stop',
|
||||
id: '900000001201',
|
||||
id: '900001201',
|
||||
name: 'S+U Westhafen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -403,7 +403,7 @@ module.exports = [{
|
|||
},
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000007102',
|
||||
id: '900007102',
|
||||
name: 'S+U Gesundbrunnen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -462,7 +462,7 @@ module.exports = [{
|
|||
}, {
|
||||
origin: {
|
||||
type: 'stop',
|
||||
id: '900000007102',
|
||||
id: '900007102',
|
||||
name: 'S+U Gesundbrunnen',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -482,7 +482,7 @@ module.exports = [{
|
|||
},
|
||||
destination: {
|
||||
type: 'stop',
|
||||
id: '900000350127',
|
||||
id: '900350127',
|
||||
name: 'Eberswalde, Hbf',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
|
Loading…
Add table
Reference in a new issue