mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parent
951c26c45a
commit
d7eca5b4d1
8 changed files with 110 additions and 66 deletions
|
@ -88,7 +88,12 @@ The response may look like this:
|
|||
metro: false,
|
||||
express: false,
|
||||
night: false,
|
||||
productCode: 0
|
||||
productCode: 0,
|
||||
operator: {
|
||||
type: 'operator',
|
||||
id: 's-bahn-berlin-gmbh',
|
||||
name: 'S-Bahn Berlin GmbH'
|
||||
}
|
||||
},
|
||||
direction: 'S Spandau'
|
||||
}, {
|
||||
|
@ -110,7 +115,8 @@ The response may look like this:
|
|||
metro: false,
|
||||
express: false,
|
||||
night: false,
|
||||
productCode: 0
|
||||
productCode: 0,
|
||||
operator: { /* … */ }
|
||||
},
|
||||
direction: 'S Westkreuz'
|
||||
}, {
|
||||
|
@ -149,7 +155,8 @@ The response may look like this:
|
|||
metro: false,
|
||||
express: false,
|
||||
night: false,
|
||||
productCode: 1
|
||||
productCode: 1,
|
||||
operator: { /* … */ }
|
||||
},
|
||||
direction: 'U Rudow'
|
||||
} ]
|
||||
|
|
|
@ -105,7 +105,12 @@ The response looked like this:
|
|||
metro: false,
|
||||
express: false,
|
||||
night: false,
|
||||
productCode: 0
|
||||
productCode: 0,
|
||||
operator: {
|
||||
type: 'operator',
|
||||
id: 's-bahn-berlin-gmbh',
|
||||
name: 'S-Bahn Berlin GmbH'
|
||||
}
|
||||
},
|
||||
direction: 'S Spandau',
|
||||
passed: [ /* … */ ]
|
||||
|
|
|
@ -143,7 +143,12 @@ The response may look like this:
|
|||
metro: false,
|
||||
express: false,
|
||||
night: false,
|
||||
productCode: 0
|
||||
productCode: 0,
|
||||
operator: {
|
||||
type: 'operator',
|
||||
id: 's-bahn-berlin-gmbh',
|
||||
name: 'S-Bahn Berlin GmbH'
|
||||
}
|
||||
},
|
||||
direction: 'S Potsdam Hauptbahnhof',
|
||||
passed: [ {
|
||||
|
|
|
@ -51,7 +51,12 @@ The response may look like this:
|
|||
nr: 9,
|
||||
metro: false,
|
||||
express: false,
|
||||
night: false
|
||||
night: false,
|
||||
operator: {
|
||||
type: 'operator',
|
||||
id: 's-bahn-berlin-gmbh',
|
||||
name: 'S-Bahn Berlin GmbH'
|
||||
}
|
||||
},
|
||||
direction: 'S Flughafen Berlin-Schönefeld',
|
||||
trip: 31463,
|
||||
|
@ -118,7 +123,12 @@ The response may look like this:
|
|||
nr: 2,
|
||||
metro: true,
|
||||
express: false,
|
||||
night: false
|
||||
night: false,
|
||||
operator: {
|
||||
type: 'operator',
|
||||
id: 'berliner-verkehrsbetriebe',
|
||||
name: 'Berliner Verkehrsbetriebe'
|
||||
}
|
||||
},
|
||||
direction: 'Heinersdorf',
|
||||
trip: 26321,
|
||||
|
|
|
@ -45,15 +45,16 @@ const request = (profile, data) => {
|
|||
if (Array.isArray(c.locL)) {
|
||||
d.locations = c.locL.map(loc => profile.parseLocation(profile, loc))
|
||||
}
|
||||
if (Array.isArray(c.prodL)) {
|
||||
d.lines = c.prodL.map(line => profile.parseLine(profile, line))
|
||||
}
|
||||
if (Array.isArray(c.remL)) {
|
||||
d.remarks = c.remL.map(rem => profile.parseRemark(profile, rem))
|
||||
}
|
||||
if (Array.isArray(c.opL)) {
|
||||
d.operators = c.opL.map(op => profile.parseOperator(profile, op))
|
||||
}
|
||||
if (Array.isArray(c.prodL)) {
|
||||
const parse = profile.parseLine(profile, d.operators)
|
||||
d.lines = c.prodL.map(parse)
|
||||
}
|
||||
return d
|
||||
})
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const crypto = require('crypto')
|
||||
|
||||
const _parseLine = require('../../parse/line')
|
||||
const _createParseLine = require('../../parse/line')
|
||||
const _createParseJourney = require('../../parse/journey')
|
||||
const _formatStation = require('../../format/station')
|
||||
const createParseBitmask = require('../../parse/products-bitmask')
|
||||
|
@ -52,19 +52,24 @@ const transformJourneysQuery = (query, opt) => {
|
|||
return query
|
||||
}
|
||||
|
||||
const parseLine = (profile, l) => {
|
||||
const res = _parseLine(profile, l)
|
||||
const createParseLine = (profile, operators) => {
|
||||
const parseLine = _createParseLine(profile, operators)
|
||||
|
||||
res.mode = res.product = null
|
||||
if ('class' in res) {
|
||||
const data = modes.bitmasks[parseInt(res.class)]
|
||||
if (data) {
|
||||
res.mode = data.mode
|
||||
res.product = data.product
|
||||
const parseLineWithMode = (l) => {
|
||||
const res = parseLine(l)
|
||||
|
||||
res.mode = res.product = null
|
||||
if ('class' in res) {
|
||||
const data = modes.bitmasks[parseInt(res.class)]
|
||||
if (data) {
|
||||
res.mode = data.mode
|
||||
res.product = data.product
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
return res
|
||||
}
|
||||
return parseLineWithMode
|
||||
}
|
||||
|
||||
const createParseJourney = (profile, stations, lines, remarks) => {
|
||||
|
@ -144,7 +149,7 @@ const dbProfile = {
|
|||
products: modes.allProducts,
|
||||
|
||||
// todo: parseLocation
|
||||
parseLine,
|
||||
parseLine: createParseLine,
|
||||
parseProducts: createParseBitmask(modes.bitmasks),
|
||||
parseJourney: createParseJourney,
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ const parseLineName = require('vbb-parse-line')
|
|||
const parseTicket = require('vbb-parse-ticket')
|
||||
const getStations = require('vbb-stations')
|
||||
|
||||
const _parseLine = require('../../parse/line')
|
||||
const _createParseLine = require('../../parse/line')
|
||||
const _parseLocation = require('../../parse/location')
|
||||
const _createParseJourney = require('../../parse/journey')
|
||||
const _createParseStopover = require('../../parse/stopover')
|
||||
|
@ -28,26 +28,31 @@ const transformReqBody = (body) => {
|
|||
return body
|
||||
}
|
||||
|
||||
const parseLine = (profile, l) => {
|
||||
const res = _parseLine(profile, l)
|
||||
const createParseLine = (profile, operators) => {
|
||||
const parseLine = _createParseLine(profile, operators)
|
||||
|
||||
res.mode = res.product = null
|
||||
if ('class' in res) {
|
||||
const data = modes.bitmasks[parseInt(res.class)]
|
||||
if (data) {
|
||||
res.mode = data.mode
|
||||
res.product = data.product
|
||||
const parseLineWithMode = (l) => {
|
||||
const res = parseLine(l)
|
||||
|
||||
res.mode = res.product = null
|
||||
if ('class' in res) {
|
||||
const data = modes.bitmasks[parseInt(res.class)]
|
||||
if (data) {
|
||||
res.mode = data.mode
|
||||
res.product = data.product
|
||||
}
|
||||
}
|
||||
|
||||
const details = parseLineName(l.name)
|
||||
res.symbol = details.symbol
|
||||
res.nr = details.nr
|
||||
res.metro = details.metro
|
||||
res.express = details.express
|
||||
res.night = details.night
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
const details = parseLineName(l.name)
|
||||
res.symbol = details.symbol
|
||||
res.nr = details.nr
|
||||
res.metro = details.metro
|
||||
res.express = details.express
|
||||
res.night = details.night
|
||||
|
||||
return res
|
||||
return parseLineWithMode
|
||||
}
|
||||
|
||||
const parseLocation = (profile, l) => {
|
||||
|
@ -169,7 +174,7 @@ const vbbProfile = {
|
|||
|
||||
parseStationName: shorten,
|
||||
parseLocation,
|
||||
parseLine,
|
||||
parseLine: createParseLine,
|
||||
parseProducts: createParseBitmask(modes.bitmasks),
|
||||
parseJourney: createParseJourney,
|
||||
parseDeparture: createParseDeparture,
|
||||
|
|
|
@ -3,31 +3,37 @@
|
|||
const slugg = require('slugg')
|
||||
|
||||
// todo: are p.number and p.line ever different?
|
||||
// todo: operator from p.oprX?
|
||||
const parseLine = (profile, p) => {
|
||||
if (!p) return null // todo: handle this upstream
|
||||
const res = {
|
||||
type: 'line',
|
||||
id: null,
|
||||
name: p.line || p.name,
|
||||
public: true
|
||||
const createParseLine = (profile, operators) => {
|
||||
const parseLine = (p) => {
|
||||
if (!p) return null // todo: handle this upstream
|
||||
const res = {
|
||||
type: 'line',
|
||||
id: null,
|
||||
name: p.line || p.name,
|
||||
public: true
|
||||
}
|
||||
|
||||
// We don't get a proper line id from the API, so we use the trip nr here.
|
||||
// todo: find a better way
|
||||
if (p.prodCtx && p.prodCtx.num) res.id = p.prodCtx.num
|
||||
// This is terrible, but FPTF demands an ID. Let's pray for VBB to expose an ID.
|
||||
else if (p.line) res.id = slugg(p.line.trim())
|
||||
else if (p.name) res.id = slugg(p.name.trim())
|
||||
|
||||
if (p.cls) res.class = p.cls
|
||||
if (p.prodCtx && p.prodCtx.catCode !== undefined) {
|
||||
res.productCode = +p.prodCtx.catCode
|
||||
}
|
||||
|
||||
// todo: parse mode, remove from profiles
|
||||
|
||||
if ('number' === typeof p.oprX) {
|
||||
res.operator = operators[p.oprX] || null
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// We don't get a proper line id from the API, so we use the trip nr here.
|
||||
// todo: find a better way
|
||||
if (p.prodCtx && p.prodCtx.num) res.id = p.prodCtx.num
|
||||
// This is terrible, but FPTF demands an ID. Let's pray for VBB to expose an ID.
|
||||
else if (p.line) res.id = slugg(p.line.trim())
|
||||
else if (p.name) res.id = slugg(p.name.trim())
|
||||
|
||||
if (p.cls) res.class = p.cls
|
||||
if (p.prodCtx && p.prodCtx.catCode !== undefined) {
|
||||
res.productCode = +p.prodCtx.catCode
|
||||
}
|
||||
|
||||
// todo: parse mode, remove from profiles
|
||||
|
||||
return res
|
||||
return parseLine
|
||||
}
|
||||
|
||||
module.exports = parseLine
|
||||
module.exports = createParseLine
|
||||
|
|
Loading…
Add table
Reference in a new issue