BVG: support BerlKönig, docs 📝

This commit is contained in:
Jannis R 2018-10-28 16:37:19 +01:00
parent baff692b70
commit a40006f5ca
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 70 additions and 1 deletions

View file

@ -8,6 +8,7 @@ const getStations = require('vbb-stations')
const _createParseLine = require('../../parse/line') const _createParseLine = require('../../parse/line')
const _parseLocation = require('../../parse/location') const _parseLocation = require('../../parse/location')
const _createParseDeparture = require('../../parse/departure') const _createParseDeparture = require('../../parse/departure')
const _createParseJourneyLeg = require('../../parse/journey-leg')
const _formatStation = require('../../format/station') const _formatStation = require('../../format/station')
const products = require('./products') const products = require('./products')
@ -74,6 +75,38 @@ const createParseDeparture = (profile, opt, data) => {
return parseDepartureRenameRingbahn 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 validIBNR = /^\d+$/
const formatStation = (id) => { const formatStation = (id) => {
if ('string' !== typeof id) throw new Error('station ID must be a string.') if ('string' !== typeof id) throw new Error('station ID must be a string.')
@ -87,6 +120,18 @@ const formatStation = (id) => {
return _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 // todo: adapt/extend `vbb-parse-ticket` to support the BVG markup
const bvgProfile = { const bvgProfile = {
@ -95,6 +140,7 @@ const bvgProfile = {
endpoint: 'https://bvg-apps.hafas.de/bin/mgate.exe', endpoint: 'https://bvg-apps.hafas.de/bin/mgate.exe',
transformReqBody, transformReqBody,
transformJourneysQuery: requestJourneysWithBerlkoenig,
products, products,
@ -102,6 +148,7 @@ const bvgProfile = {
parseLocation, parseLocation,
parseLine: createParseLine, parseLine: createParseLine,
parseDeparture: createParseDeparture, parseDeparture: createParseDeparture,
parseJourneyLeg: createParseJourneyLeg,
formatStation, formatStation,

View file

@ -16,6 +16,28 @@ const client = createClient(bvgProfile, 'my-awesome-program')
## Customisations ## Customisations
- parses *BVG*-specific products (such as *X-Bus*) - 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 - 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?") - parses line names to give more information (e.g. "Is it an express bus?")
- renames *Ringbahn* line names to contain `⟳` and `⟲` - 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'
}
}
```

View file

@ -36,7 +36,7 @@ const parseHint = (profile, h, icons) => {
tripId: h.jid tripId: h.jid
} }
} }
if (h.type === 'A') { if (h.type === 'A' || h.type === 'I') {
return { return {
type: 'hint', type: 'hint',
code: h.code || null, code: h.code || null,