mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
VBB-related bugfixes and changes 🐛
This commit is contained in:
parent
541505e720
commit
e762f30f05
7 changed files with 30 additions and 13 deletions
|
@ -34,6 +34,7 @@ const defaultProfile = {
|
||||||
parseDeparture,
|
parseDeparture,
|
||||||
parseJourney,
|
parseJourney,
|
||||||
parseLine,
|
parseLine,
|
||||||
|
parseStationName: id,
|
||||||
parseLocation,
|
parseLocation,
|
||||||
parseMovement,
|
parseMovement,
|
||||||
parseNearby,
|
parseNearby,
|
||||||
|
|
|
@ -26,7 +26,7 @@ const parseLine = (profile, l) => {
|
||||||
const data = modes.bitmasks[parseInt(res.class)]
|
const data = modes.bitmasks[parseInt(res.class)]
|
||||||
if (data) {
|
if (data) {
|
||||||
res.mode = data.mode
|
res.mode = data.mode
|
||||||
res.product = data.product
|
res.product = data.type
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,9 +35,13 @@ const parseLine = (profile, l) => {
|
||||||
|
|
||||||
const parseLocation = (profile, l) => {
|
const parseLocation = (profile, l) => {
|
||||||
const res = _parseLocation(profile, l)
|
const res = _parseLocation(profile, l)
|
||||||
|
|
||||||
|
// todo: shorten has been made for stations, not any type of location
|
||||||
|
res.name = shorten(res.name)
|
||||||
|
|
||||||
if (res.type === 'station') {
|
if (res.type === 'station') {
|
||||||
res.id = to12Digit(res.id)
|
res.id = to12Digit(res.id)
|
||||||
res.name = shorten(res.name)
|
// todo: https://github.com/derhuerst/vbb-hafas/blob/1c64bfe42422e2648b21016d233c808460250308/lib/parse.js#L67-L75
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -72,6 +76,7 @@ const vbbProfile = {
|
||||||
endpoint: 'https://fahrinfo.vbb.de/bin/mgate.exe',
|
endpoint: 'https://fahrinfo.vbb.de/bin/mgate.exe',
|
||||||
transformReqBody,
|
transformReqBody,
|
||||||
|
|
||||||
|
parseStationName: shorten,
|
||||||
parseLocation,
|
parseLocation,
|
||||||
parseLine,
|
parseLine,
|
||||||
parseProducts: modes.parseBitmask,
|
parseProducts: modes.parseBitmask,
|
||||||
|
|
|
@ -108,7 +108,6 @@ m.bitmasks[16] = m.ferry
|
||||||
m.bitmasks[32] = m.express
|
m.bitmasks[32] = m.express
|
||||||
m.bitmasks[64] = m.regional
|
m.bitmasks[64] = m.regional
|
||||||
|
|
||||||
|
|
||||||
m.categories = [
|
m.categories = [
|
||||||
m.suburban,
|
m.suburban,
|
||||||
m.subway,
|
m.subway,
|
||||||
|
|
|
@ -51,7 +51,7 @@ const createParseJourney = (profile, stations, lines, remarks) => {
|
||||||
} else if (pt.type === 'JNY') {
|
} else if (pt.type === 'JNY') {
|
||||||
res.id = pt.jny.jid
|
res.id = pt.jny.jid
|
||||||
res.line = lines[parseInt(pt.jny.prodX)] || null
|
res.line = lines[parseInt(pt.jny.prodX)] || null
|
||||||
res.direction = pt.jny.dirTxt // todo: parse this
|
res.direction = profile.parseStationName(pt.jny.dirTxt)
|
||||||
|
|
||||||
if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS
|
if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS
|
||||||
if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS
|
if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
// todo: what is p.oprX?
|
// todo: what is p.oprX?
|
||||||
const parseLine = (profile, p) => {
|
const parseLine = (profile, p) => {
|
||||||
if (!p) return null // todo: handle this upstream
|
if (!p) return null // todo: handle this upstream
|
||||||
const res = {type: 'line', name: p.line || p.name}
|
const res = {
|
||||||
|
type: 'line',
|
||||||
|
name: p.line || p.name,
|
||||||
|
public: true
|
||||||
|
}
|
||||||
|
|
||||||
if (p.cls) res.class = p.cls
|
if (p.cls) res.class = p.cls
|
||||||
if (p.prodCtx) {
|
if (p.prodCtx) {
|
||||||
|
|
|
@ -43,6 +43,7 @@ const assertValidLine = (t, l) => {
|
||||||
if (!isValidMode(l.mode)) console.error(l)
|
if (!isValidMode(l.mode)) console.error(l)
|
||||||
t.ok(isValidMode(l.mode), 'invalid mode ' + l.mode)
|
t.ok(isValidMode(l.mode), 'invalid mode ' + l.mode)
|
||||||
t.equal(typeof l.product, 'string')
|
t.equal(typeof l.product, 'string')
|
||||||
|
t.equal(l.public, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
const isValidDateTime = (w) => {
|
const isValidDateTime = (w) => {
|
||||||
|
@ -72,6 +73,10 @@ const isValidWhen = (w) => {
|
||||||
return isRoughlyEqual(10 * hour, +when, ts)
|
return isRoughlyEqual(10 * hour, +when, ts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const assertValidWhen = (t, w) => {
|
||||||
|
t.ok(isValidWhen(w), 'invalid when')
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
assertValidStation,
|
assertValidStation,
|
||||||
assertValidPoi,
|
assertValidPoi,
|
||||||
|
@ -81,5 +86,5 @@ module.exports = {
|
||||||
assertValidLine,
|
assertValidLine,
|
||||||
isValidDateTime,
|
isValidDateTime,
|
||||||
assertValidStopover,
|
assertValidStopover,
|
||||||
when, isValidWhen
|
when, isValidWhen, assertValidWhen
|
||||||
}
|
}
|
||||||
|
|
17
test/vbb.js
17
test/vbb.js
|
@ -15,7 +15,7 @@ const {
|
||||||
assertValidAddress,
|
assertValidAddress,
|
||||||
assertValidLocation,
|
assertValidLocation,
|
||||||
assertValidLine,
|
assertValidLine,
|
||||||
assertValidPassed,
|
assertValidStopover,
|
||||||
hour, when,
|
hour, when,
|
||||||
assertValidWhen
|
assertValidWhen
|
||||||
} = require('./util')
|
} = require('./util')
|
||||||
|
@ -68,7 +68,7 @@ test('journeys – station to station', async (t) => {
|
||||||
t.ok(part.direction.indexOf('(Berlin)') === -1)
|
t.ok(part.direction.indexOf('(Berlin)') === -1)
|
||||||
|
|
||||||
t.ok(Array.isArray(part.passed))
|
t.ok(Array.isArray(part.passed))
|
||||||
for (let passed of part.passed) assertValidPassed(t, passed)
|
for (let passed of part.passed) assertValidStopover(t, passed)
|
||||||
}
|
}
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
@ -93,9 +93,9 @@ test('journeys – only subway', async (t) => {
|
||||||
for (let journey of journeys) {
|
for (let journey of journeys) {
|
||||||
for (let part of journey.parts) {
|
for (let part of journey.parts) {
|
||||||
if (part.line) {
|
if (part.line) {
|
||||||
|
assertValidLine(t, part.line)
|
||||||
t.equal(part.line.mode, 'train')
|
t.equal(part.line.mode, 'train')
|
||||||
t.equal(part.line.product, 'subway')
|
t.equal(part.line.product, 'subway')
|
||||||
t.equal(part.line.public, true)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,8 @@ test('journeys – fails with no product', async (t) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
test('journey part details', async (t) => {
|
// todo
|
||||||
|
test.skip('journey part details', async (t) => {
|
||||||
const journeys = await client.journeys(spichernstr, amrumerStr, {
|
const journeys = await client.journeys(spichernstr, amrumerStr, {
|
||||||
results: 1, when
|
results: 1, when
|
||||||
})
|
})
|
||||||
|
@ -141,7 +142,7 @@ test('journey part details', async (t) => {
|
||||||
t.ok(part.direction)
|
t.ok(part.direction)
|
||||||
|
|
||||||
t.ok(Array.isArray(part.passed))
|
t.ok(Array.isArray(part.passed))
|
||||||
for (let passed of part.passed) assertValidPassed(t, passed)
|
for (let passed of part.passed) assertValidStopover(t, passed)
|
||||||
|
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
@ -200,7 +201,7 @@ test('journeys – station to POI', async (t) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test.only('departures', async (t) => {
|
test('departures', async (t) => {
|
||||||
const deps = await client.departures(spichernstr, {duration: 5, when})
|
const deps = await client.departures(spichernstr, {duration: 5, when})
|
||||||
|
|
||||||
t.ok(Array.isArray(deps))
|
t.ok(Array.isArray(deps))
|
||||||
|
@ -220,7 +221,8 @@ test.only('departures', async (t) => {
|
||||||
t.end()
|
t.end()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('departures at 7-digit station', async (t) => {
|
// todo
|
||||||
|
test.skip('departures at 7-digit station', async (t) => {
|
||||||
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
|
const eisenach = '8010097' // see derhuerst/vbb-hafas#22
|
||||||
await client.departures(eisenach, {when})
|
await client.departures(eisenach, {when})
|
||||||
t.pass('did not fail')
|
t.pass('did not fail')
|
||||||
|
@ -268,6 +270,7 @@ test('locations', async (t) => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// todo
|
||||||
test.skip('radar', async (t) => {
|
test.skip('radar', async (t) => {
|
||||||
const vehicles = await client.radar(52.52411, 13.41002, 52.51942, 13.41709, {
|
const vehicles = await client.radar(52.52411, 13.41002, 52.51942, 13.41709, {
|
||||||
duration: 5 * 60, when
|
duration: 5 * 60, when
|
||||||
|
|
Loading…
Add table
Reference in a new issue