From a40006f5ca0aba5cc5d05b05d73a469c28896464 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Sun, 28 Oct 2018 16:37:19 +0100 Subject: [PATCH] =?UTF-8?q?BVG:=20support=20BerlK=C3=B6nig,=20docs=20:memo?= =?UTF-8?q?:?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p/bvg/index.js | 47 +++++++++++++++++++++++++++++++++++++++++++++++ p/bvg/readme.md | 22 ++++++++++++++++++++++ parse/hint.js | 2 +- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/p/bvg/index.js b/p/bvg/index.js index 445194b5..f18e027c 100644 --- a/p/bvg/index.js +++ b/p/bvg/index.js @@ -8,6 +8,7 @@ const getStations = require('vbb-stations') const _createParseLine = require('../../parse/line') const _parseLocation = require('../../parse/location') const _createParseDeparture = require('../../parse/departure') +const _createParseJourneyLeg = require('../../parse/journey-leg') const _formatStation = require('../../format/station') const products = require('./products') @@ -74,6 +75,38 @@ const createParseDeparture = (profile, opt, data) => { return parseDepartureRenameRingbahn } +const createParseJourneyLeg = (profile, opt, data) => { + const _parseJourneyLeg = _createParseJourneyLeg(profile, opt, data) + const parseJourneyLeg = (journey, leg, parseStopovers = true) => { + if (leg.type === 'KISS') { + const icon = data.icons[leg.icoX] + if (icon && icon.type === 'prod_berl') { + const res = _parseJourneyLeg(journey, {...leg, type: 'WALK'}, parseStopovers) + delete res.walking + + const mcp = leg.dep.mcp || {} + const mcpData = mcp.mcpData || {} + // todo: mcp.lid + // todo: mcpData.occupancy, mcpData.type + // todo: journey.trfRes.bkgData + res.line = { + type: 'line', + id: null, // todo + // todo: fahrtNr? + name: mcpData.providerName, + public: true, + mode: 'taxi', + product: 'berlkoenig' + // todo: operator + } + return res + } + } + return _parseJourneyLeg(journey, leg, parseStopovers) + } + return parseJourneyLeg +} + const validIBNR = /^\d+$/ const formatStation = (id) => { if ('string' !== typeof id) throw new Error('station ID must be a string.') @@ -87,6 +120,18 @@ const formatStation = (id) => { return _formatStation(id) } +// use the Berlkönig ride sharing service? +const requestJourneysWithBerlkoenig = (query, opt) => { + if (('numF' in query) && opt.berlkoenig) { + // todo: check if this is still true + throw new Error('The `berlkoenig` and `results` options are mutually exclusive.') + } + query.jnyFltrL.push({type: 'GROUP', mode: 'INC', value: 'OEV'}) + if (opt.berlkoenig) query.jnyFltrL.push({type: 'GROUP', mode: 'INC', value: 'BERLKOENIG'}) + query.gisFltrL = [{meta: 'foot_speed_normal', type: 'M', mode: 'FB'}] + return query +} + // todo: adapt/extend `vbb-parse-ticket` to support the BVG markup const bvgProfile = { @@ -95,6 +140,7 @@ const bvgProfile = { endpoint: 'https://bvg-apps.hafas.de/bin/mgate.exe', transformReqBody, + transformJourneysQuery: requestJourneysWithBerlkoenig, products, @@ -102,6 +148,7 @@ const bvgProfile = { parseLocation, parseLine: createParseLine, parseDeparture: createParseDeparture, + parseJourneyLeg: createParseJourneyLeg, formatStation, diff --git a/p/bvg/readme.md b/p/bvg/readme.md index 0304acb2..a48516eb 100644 --- a/p/bvg/readme.md +++ b/p/bvg/readme.md @@ -16,6 +16,28 @@ const client = createClient(bvgProfile, 'my-awesome-program') ## Customisations - parses *BVG*-specific products (such as *X-Bus*) +- supports [BerlKönig `journey` legs](#berlkoenig) - strips parts from station names that are unnecessary in the Berlin context - parses line names to give more information (e.g. "Is it an express bus?") - renames *Ringbahn* line names to contain `⟳` and `⟲` + +### BerlKönig + +BVG has recently announced [a ride-sharing service called *BerlKönig*](https://www.berlkoenig.de). Pass `berlkoenig: true` into `journeys()` to get special legs: + +```js +{ + mode: 'walking', + departure: // … + arrival: // … + origin: // … + destination: // … + line: { + type: 'line', + name: 'BerlKönig', + public: true, + mode: 'taxi', + product: 'berlkoenig' + } +} +``` diff --git a/parse/hint.js b/parse/hint.js index dadd2b50..07623984 100644 --- a/parse/hint.js +++ b/parse/hint.js @@ -36,7 +36,7 @@ const parseHint = (profile, h, icons) => { tripId: h.jid } } - if (h.type === 'A') { + if (h.type === 'A' || h.type === 'I') { return { type: 'hint', code: h.code || null,