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,
|
metro: false,
|
||||||
express: false,
|
express: false,
|
||||||
night: false,
|
night: false,
|
||||||
productCode: 0
|
productCode: 0,
|
||||||
|
operator: {
|
||||||
|
type: 'operator',
|
||||||
|
id: 's-bahn-berlin-gmbh',
|
||||||
|
name: 'S-Bahn Berlin GmbH'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
direction: 'S Spandau'
|
direction: 'S Spandau'
|
||||||
}, {
|
}, {
|
||||||
|
@ -110,7 +115,8 @@ The response may look like this:
|
||||||
metro: false,
|
metro: false,
|
||||||
express: false,
|
express: false,
|
||||||
night: false,
|
night: false,
|
||||||
productCode: 0
|
productCode: 0,
|
||||||
|
operator: { /* … */ }
|
||||||
},
|
},
|
||||||
direction: 'S Westkreuz'
|
direction: 'S Westkreuz'
|
||||||
}, {
|
}, {
|
||||||
|
@ -149,7 +155,8 @@ The response may look like this:
|
||||||
metro: false,
|
metro: false,
|
||||||
express: false,
|
express: false,
|
||||||
night: false,
|
night: false,
|
||||||
productCode: 1
|
productCode: 1,
|
||||||
|
operator: { /* … */ }
|
||||||
},
|
},
|
||||||
direction: 'U Rudow'
|
direction: 'U Rudow'
|
||||||
} ]
|
} ]
|
||||||
|
|
|
@ -105,7 +105,12 @@ The response looked like this:
|
||||||
metro: false,
|
metro: false,
|
||||||
express: false,
|
express: false,
|
||||||
night: false,
|
night: false,
|
||||||
productCode: 0
|
productCode: 0,
|
||||||
|
operator: {
|
||||||
|
type: 'operator',
|
||||||
|
id: 's-bahn-berlin-gmbh',
|
||||||
|
name: 'S-Bahn Berlin GmbH'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
direction: 'S Spandau',
|
direction: 'S Spandau',
|
||||||
passed: [ /* … */ ]
|
passed: [ /* … */ ]
|
||||||
|
|
|
@ -143,7 +143,12 @@ The response may look like this:
|
||||||
metro: false,
|
metro: false,
|
||||||
express: false,
|
express: false,
|
||||||
night: false,
|
night: false,
|
||||||
productCode: 0
|
productCode: 0,
|
||||||
|
operator: {
|
||||||
|
type: 'operator',
|
||||||
|
id: 's-bahn-berlin-gmbh',
|
||||||
|
name: 'S-Bahn Berlin GmbH'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
direction: 'S Potsdam Hauptbahnhof',
|
direction: 'S Potsdam Hauptbahnhof',
|
||||||
passed: [ {
|
passed: [ {
|
||||||
|
|
|
@ -51,7 +51,12 @@ The response may look like this:
|
||||||
nr: 9,
|
nr: 9,
|
||||||
metro: false,
|
metro: false,
|
||||||
express: 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',
|
direction: 'S Flughafen Berlin-Schönefeld',
|
||||||
trip: 31463,
|
trip: 31463,
|
||||||
|
@ -118,7 +123,12 @@ The response may look like this:
|
||||||
nr: 2,
|
nr: 2,
|
||||||
metro: true,
|
metro: true,
|
||||||
express: false,
|
express: false,
|
||||||
night: false
|
night: false,
|
||||||
|
operator: {
|
||||||
|
type: 'operator',
|
||||||
|
id: 'berliner-verkehrsbetriebe',
|
||||||
|
name: 'Berliner Verkehrsbetriebe'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
direction: 'Heinersdorf',
|
direction: 'Heinersdorf',
|
||||||
trip: 26321,
|
trip: 26321,
|
||||||
|
|
|
@ -45,15 +45,16 @@ const request = (profile, data) => {
|
||||||
if (Array.isArray(c.locL)) {
|
if (Array.isArray(c.locL)) {
|
||||||
d.locations = c.locL.map(loc => profile.parseLocation(profile, loc))
|
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)) {
|
if (Array.isArray(c.remL)) {
|
||||||
d.remarks = c.remL.map(rem => profile.parseRemark(profile, rem))
|
d.remarks = c.remL.map(rem => profile.parseRemark(profile, rem))
|
||||||
}
|
}
|
||||||
if (Array.isArray(c.opL)) {
|
if (Array.isArray(c.opL)) {
|
||||||
d.operators = c.opL.map(op => profile.parseOperator(profile, op))
|
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
|
return d
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
const crypto = require('crypto')
|
const crypto = require('crypto')
|
||||||
|
|
||||||
const _parseLine = require('../../parse/line')
|
const _createParseLine = require('../../parse/line')
|
||||||
const _createParseJourney = require('../../parse/journey')
|
const _createParseJourney = require('../../parse/journey')
|
||||||
const _formatStation = require('../../format/station')
|
const _formatStation = require('../../format/station')
|
||||||
const createParseBitmask = require('../../parse/products-bitmask')
|
const createParseBitmask = require('../../parse/products-bitmask')
|
||||||
|
@ -52,19 +52,24 @@ const transformJourneysQuery = (query, opt) => {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseLine = (profile, l) => {
|
const createParseLine = (profile, operators) => {
|
||||||
const res = _parseLine(profile, l)
|
const parseLine = _createParseLine(profile, operators)
|
||||||
|
|
||||||
res.mode = res.product = null
|
const parseLineWithMode = (l) => {
|
||||||
if ('class' in res) {
|
const res = parseLine(l)
|
||||||
const data = modes.bitmasks[parseInt(res.class)]
|
|
||||||
if (data) {
|
res.mode = res.product = null
|
||||||
res.mode = data.mode
|
if ('class' in res) {
|
||||||
res.product = data.product
|
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) => {
|
const createParseJourney = (profile, stations, lines, remarks) => {
|
||||||
|
@ -144,7 +149,7 @@ const dbProfile = {
|
||||||
products: modes.allProducts,
|
products: modes.allProducts,
|
||||||
|
|
||||||
// todo: parseLocation
|
// todo: parseLocation
|
||||||
parseLine,
|
parseLine: createParseLine,
|
||||||
parseProducts: createParseBitmask(modes.bitmasks),
|
parseProducts: createParseBitmask(modes.bitmasks),
|
||||||
parseJourney: createParseJourney,
|
parseJourney: createParseJourney,
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ const parseLineName = require('vbb-parse-line')
|
||||||
const parseTicket = require('vbb-parse-ticket')
|
const parseTicket = require('vbb-parse-ticket')
|
||||||
const getStations = require('vbb-stations')
|
const getStations = require('vbb-stations')
|
||||||
|
|
||||||
const _parseLine = require('../../parse/line')
|
const _createParseLine = require('../../parse/line')
|
||||||
const _parseLocation = require('../../parse/location')
|
const _parseLocation = require('../../parse/location')
|
||||||
const _createParseJourney = require('../../parse/journey')
|
const _createParseJourney = require('../../parse/journey')
|
||||||
const _createParseStopover = require('../../parse/stopover')
|
const _createParseStopover = require('../../parse/stopover')
|
||||||
|
@ -28,26 +28,31 @@ const transformReqBody = (body) => {
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseLine = (profile, l) => {
|
const createParseLine = (profile, operators) => {
|
||||||
const res = _parseLine(profile, l)
|
const parseLine = _createParseLine(profile, operators)
|
||||||
|
|
||||||
res.mode = res.product = null
|
const parseLineWithMode = (l) => {
|
||||||
if ('class' in res) {
|
const res = parseLine(l)
|
||||||
const data = modes.bitmasks[parseInt(res.class)]
|
|
||||||
if (data) {
|
res.mode = res.product = null
|
||||||
res.mode = data.mode
|
if ('class' in res) {
|
||||||
res.product = data.product
|
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
|
||||||
}
|
}
|
||||||
|
return parseLineWithMode
|
||||||
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 parseLocation = (profile, l) => {
|
const parseLocation = (profile, l) => {
|
||||||
|
@ -169,7 +174,7 @@ const vbbProfile = {
|
||||||
|
|
||||||
parseStationName: shorten,
|
parseStationName: shorten,
|
||||||
parseLocation,
|
parseLocation,
|
||||||
parseLine,
|
parseLine: createParseLine,
|
||||||
parseProducts: createParseBitmask(modes.bitmasks),
|
parseProducts: createParseBitmask(modes.bitmasks),
|
||||||
parseJourney: createParseJourney,
|
parseJourney: createParseJourney,
|
||||||
parseDeparture: createParseDeparture,
|
parseDeparture: createParseDeparture,
|
||||||
|
|
|
@ -3,31 +3,37 @@
|
||||||
const slugg = require('slugg')
|
const slugg = require('slugg')
|
||||||
|
|
||||||
// todo: are p.number and p.line ever different?
|
// todo: are p.number and p.line ever different?
|
||||||
// todo: operator from p.oprX?
|
const createParseLine = (profile, operators) => {
|
||||||
const parseLine = (profile, p) => {
|
const parseLine = (p) => {
|
||||||
if (!p) return null // todo: handle this upstream
|
if (!p) return null // todo: handle this upstream
|
||||||
const res = {
|
const res = {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
id: null,
|
id: null,
|
||||||
name: p.line || p.name,
|
name: p.line || p.name,
|
||||||
public: true
|
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
|
||||||
}
|
}
|
||||||
|
return parseLine
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = parseLine
|
module.exports = createParseLine
|
||||||
|
|
Loading…
Add table
Reference in a new issue