diff --git a/p/bvg/index.js b/p/bvg/index.js index 3f00e408..afd1fc12 100644 --- a/p/bvg/index.js +++ b/p/bvg/index.js @@ -6,6 +6,8 @@ const parseLineName = require('vbb-parse-line') const getStations = require('vbb-stations') const {parseHook} = require('../../lib/profile-hooks') +const parseAndAddLocationDHID = require('../vbb/parse-loc-dhid') + const { parseLine: _parseLine, parseLocation: _parseLocation, @@ -65,6 +67,8 @@ const parseLocation = ({parsed}, l) => { if (s) Object.assign(parsed.location, s.location) } } + + parseAndAddLocationDHID(parsed, l) return parsed } diff --git a/p/vbb/index.js b/p/vbb/index.js index bacf8a3b..d7073ddb 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -7,6 +7,7 @@ const parseTicket = require('vbb-parse-ticket') const getStations = require('vbb-stations') const {parseHook} = require('../../lib/profile-hooks') +const parseAndAddLocationDHID = require('./parse-loc-dhid') const _parseLine = require('../../parse/line') const _parseLocation = require('../../parse/location') const _parseJourney = require('../../parse/journey') @@ -38,6 +39,8 @@ const parseLocation = ({parsed}, l) => { if (s) Object.assign(parsed.location, s.location) } } + + parseAndAddLocationDHID(parsed, l) return parsed } diff --git a/p/vbb/parse-loc-dhid.js b/p/vbb/parse-loc-dhid.js new file mode 100644 index 00000000..1e706238 --- /dev/null +++ b/p/vbb/parse-loc-dhid.js @@ -0,0 +1,18 @@ +'use strict' + +const dhidPrefix = 'A×' + +const parseAndAddLocationDHID = (loc, l) => { + if (!Array.isArray(l.gidL)) return; + + const dhidGid = l.gidL.find(gid => gid.slice(0, dhidPrefix.length) === dhidPrefix) + if (!dhidGid) return; + const dhid = dhidGid.slice(dhidPrefix.length) + + // It seems that the DHID of the parent station is being used, not of the stop. + // if (!loc.ids) loc.ids = {} + // loc.ids.dhid = dhid + loc.stationDHID = dhid +} + +module.exports = parseAndAddLocationDHID diff --git a/test/fixtures/bvg-arrivals.js b/test/fixtures/bvg-arrivals.js index aaf5fe50..22c22507 100644 --- a/test/fixtures/bvg-arrivals.js +++ b/test/fixtures/bvg-arrivals.js @@ -3,6 +3,7 @@ const sLandsbergerAllee = { type: 'stop', id: '900000110004', + stationDHID: 'de:11000:900110004', name: 'S Landsberger Allee', location: { type: 'location', diff --git a/test/fixtures/vbb-departures.js b/test/fixtures/vbb-departures.js index 2196ce30..854fd193 100644 --- a/test/fixtures/vbb-departures.js +++ b/test/fixtures/vbb-departures.js @@ -6,6 +6,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -200,6 +201,7 @@ module.exports = [ destination: { type: "stop", id: "900000310004", + stationDHID: 'de:12067:900310004', name: "S Erkner", location: { type: "location", @@ -278,6 +280,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -521,6 +524,7 @@ module.exports = [ destination: { type: "stop", id: "900000005207", + stationDHID: 'de:11000:900005207', name: "Philharmonie Süd", location: { type: "location", @@ -549,6 +553,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -793,6 +798,7 @@ module.exports = [ destination: { type: "stop", id: "900000079221", + stationDHID: 'de:11000:900079221', name: "S+U Hermannstr.", location: { type: "location", @@ -821,6 +827,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -1065,6 +1072,7 @@ module.exports = [ destination: { type: 'stop', id: '900000096197', + stationDHID: 'de:11000:900096197', name: 'S+U Wittenau [U8]', location: { type: 'location', @@ -1093,6 +1101,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -1337,6 +1346,7 @@ module.exports = [ destination: { type: 'stop', id: '900000024102', + stationDHID: 'de:11000:900024102', name: 'S Westkreuz', location: { type: 'location', @@ -1365,6 +1375,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -1609,6 +1620,7 @@ module.exports = [ destination: { type: 'stop', id: '900000170004', + stationDHID: 'de:11000:900170004', name: 'S Ahrensfelde', location: { type: 'location', @@ -1637,6 +1649,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -1881,6 +1894,7 @@ module.exports = [ destination: { type: 'stop', id: '900000230999', + stationDHID: 'de:12054:900230999', name: 'S Potsdam Hauptbahnhof', location: { type: 'location', @@ -1909,6 +1923,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -2153,6 +2168,7 @@ module.exports = [ destination: { type: 'stop', id: '900000320004', + stationDHID: 'de:12064:900320004', name: 'S Strausberg', location: { type: 'location', @@ -2181,6 +2197,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -2425,6 +2442,7 @@ module.exports = [ destination: { type: 'stop', id: '900000079221', + stationDHID: 'de:11000:900079221', name: 'S+U Hermannstr.', location: { type: 'location', @@ -2453,6 +2471,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -2697,6 +2716,7 @@ module.exports = [ destination: { type: 'stop', id: '900000085104', + stationDHID: 'de:11000:900085104', name: 'U Paracelsus-Bad', location: { type: 'location', @@ -2725,6 +2745,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -2968,6 +2989,7 @@ module.exports = [ destination: { type: 'stop', id: '900000120004', + stationDHID: 'de:11000:900120004', name: 'S+U Warschauer Str.', location: { type: 'location', @@ -2996,6 +3018,7 @@ module.exports = [ stop: { type: 'stop', id: '900000100004', + stationDHID: 'de:11000:900100004', name: 'S+U Jannowitzbrücke', location: { type: 'location', @@ -3240,6 +3263,7 @@ module.exports = [ destination: { type: 'stop', id: '900000029101', + stationDHID: 'de:11000:900029101', name: 'S Spandau', location: { type: 'location',