mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
fix products parsing 🐛, minor changes
This commit is contained in:
parent
658d67e3b2
commit
d77c450d11
6 changed files with 55 additions and 37 deletions
|
@ -30,7 +30,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.type
|
res.product = data.product
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,10 +8,7 @@ const m = {
|
||||||
name: 'S-Bahn',
|
name: 'S-Bahn',
|
||||||
mode: 'train',
|
mode: 'train',
|
||||||
short: 'S',
|
short: 'S',
|
||||||
type: 'suburban',
|
product: 'suburban'
|
||||||
color: '#008c4f',
|
|
||||||
unicode: '🚈',
|
|
||||||
ansi: ['green'] // `chalk` color code
|
|
||||||
},
|
},
|
||||||
|
|
||||||
subway: {
|
subway: {
|
||||||
|
@ -20,10 +17,7 @@ const m = {
|
||||||
name: 'U-Bahn',
|
name: 'U-Bahn',
|
||||||
mode: 'train',
|
mode: 'train',
|
||||||
short: 'U',
|
short: 'U',
|
||||||
type: 'subway',
|
product: 'subway'
|
||||||
color: '#0067ac',
|
|
||||||
unicode: '🚇',
|
|
||||||
ansi: ['blue'] // `chalk` color code
|
|
||||||
},
|
},
|
||||||
|
|
||||||
tram: {
|
tram: {
|
||||||
|
@ -32,34 +26,25 @@ const m = {
|
||||||
name: 'Tram',
|
name: 'Tram',
|
||||||
mode: 'train',
|
mode: 'train',
|
||||||
short: 'T',
|
short: 'T',
|
||||||
type: 'tram',
|
product: 'tram'
|
||||||
color: '#e3001b',
|
|
||||||
unicode: '🚋',
|
|
||||||
ansi: ['red'] // `chalk` color code
|
|
||||||
},
|
},
|
||||||
|
|
||||||
bus: {
|
bus: {
|
||||||
category: 3,
|
category: 3,
|
||||||
bitmask: 8,
|
bitmask: 8,
|
||||||
name: 'Bus',
|
name: 'Bus',
|
||||||
mode: 'train',
|
mode: 'bus',
|
||||||
short: 'B',
|
short: 'B',
|
||||||
type: 'bus',
|
product: 'bus'
|
||||||
color: '#922A7D',
|
|
||||||
unicode: '🚌',
|
|
||||||
ansi: ['dim', 'magenta'] // `chalk` color codes
|
|
||||||
},
|
},
|
||||||
|
|
||||||
ferry: {
|
ferry: {
|
||||||
category: 4,
|
category: 4,
|
||||||
bitmask: 16,
|
bitmask: 16,
|
||||||
name: 'Fähre',
|
name: 'Fähre',
|
||||||
mode: 'train',
|
mode: 'ferry',
|
||||||
short: 'F',
|
short: 'F',
|
||||||
type: 'ferry',
|
product: 'ferry'
|
||||||
color: '#099bd6',
|
|
||||||
unicode: '🚢',
|
|
||||||
ansi: ['cyan'] // `chalk` color code
|
|
||||||
},
|
},
|
||||||
|
|
||||||
express: {
|
express: {
|
||||||
|
@ -68,10 +53,7 @@ const m = {
|
||||||
name: 'IC/ICE',
|
name: 'IC/ICE',
|
||||||
mode: 'train',
|
mode: 'train',
|
||||||
short: 'E',
|
short: 'E',
|
||||||
type: 'express',
|
product: 'express'
|
||||||
color: '#f4e613',
|
|
||||||
unicode: '🚄',
|
|
||||||
ansi: ['yellow'] // `chalk` color code
|
|
||||||
},
|
},
|
||||||
|
|
||||||
regional: {
|
regional: {
|
||||||
|
@ -80,10 +62,7 @@ const m = {
|
||||||
name: 'RB/RE',
|
name: 'RB/RE',
|
||||||
mode: 'train',
|
mode: 'train',
|
||||||
short: 'R',
|
short: 'R',
|
||||||
type: 'regional',
|
product: 'regional'
|
||||||
color: '#D9222A',
|
|
||||||
unicode: '🚆',
|
|
||||||
ansi: ['red'] // `chalk` color code
|
|
||||||
},
|
},
|
||||||
|
|
||||||
unknown: {
|
unknown: {
|
||||||
|
@ -92,10 +71,7 @@ const m = {
|
||||||
name: 'unknown',
|
name: 'unknown',
|
||||||
mode: null,
|
mode: null,
|
||||||
short: '?',
|
short: '?',
|
||||||
type: 'unknown',
|
product: 'unknown'
|
||||||
color: '#555555',
|
|
||||||
unicode: '?',
|
|
||||||
ansi: ['gray'] // `chalk` color code
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
// - stdStop.dPlatfS, stdStop.dPlatfR
|
// - stdStop.dPlatfS, stdStop.dPlatfR
|
||||||
// todo: what is d.jny.dirFlg?
|
// todo: what is d.jny.dirFlg?
|
||||||
// todo: d.stbStop.dProgType
|
// todo: d.stbStop.dProgType
|
||||||
|
// todo: d.freq, d.freq.jnyL, see https://github.com/derhuerst/hafas-client/blob/9203ed1481f08baacca41ac5e3c19bf022f01b0b/parse.js#L115
|
||||||
|
|
||||||
const createParseDeparture = (profile, stations, lines, remarks) => {
|
const createParseDeparture = (profile, stations, lines, remarks) => {
|
||||||
const tz = profile.timezone
|
const tz = profile.timezone
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const createParseBitmask = (bitmasks) => {
|
const createParseBitmask = (bitmasks) => {
|
||||||
const createBitmask = (bitmask) => {
|
const parseBitmask = (bitmask) => {
|
||||||
const products = {}
|
const products = {}
|
||||||
let i = 1
|
let i = 1
|
||||||
do {
|
do {
|
||||||
|
@ -10,7 +10,7 @@ const createParseBitmask = (bitmasks) => {
|
||||||
} while (bitmasks[i] && bitmasks[i].product)
|
} while (bitmasks[i] && bitmasks[i].product)
|
||||||
return products
|
return products
|
||||||
}
|
}
|
||||||
return createBitmask
|
return parseBitmask
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = createParseBitmask
|
module.exports = createParseBitmask
|
||||||
|
|
21
test/db.js
21
test/db.js
|
@ -19,6 +19,20 @@ const {
|
||||||
when, isValidWhen
|
when, isValidWhen
|
||||||
} = require('./util.js')
|
} = require('./util.js')
|
||||||
|
|
||||||
|
const assertValidStationProducts = (t, p) => {
|
||||||
|
t.ok(p)
|
||||||
|
t.equal(typeof p.nationalExp, 'boolean')
|
||||||
|
t.equal(typeof p.national, 'boolean')
|
||||||
|
t.equal(typeof p.regionalExp, 'boolean')
|
||||||
|
t.equal(typeof p.regional, 'boolean')
|
||||||
|
t.equal(typeof p.suburban, 'boolean')
|
||||||
|
t.equal(typeof p.bus, 'boolean')
|
||||||
|
t.equal(typeof p.ferry, 'boolean')
|
||||||
|
t.equal(typeof p.subway, 'boolean')
|
||||||
|
t.equal(typeof p.tram, 'boolean')
|
||||||
|
t.equal(typeof p.taxi, 'boolean')
|
||||||
|
}
|
||||||
|
|
||||||
const findStation = (id) => new Promise((yay, nay) => {
|
const findStation = (id) => new Promise((yay, nay) => {
|
||||||
const stations = getStations()
|
const stations = getStations()
|
||||||
stations
|
stations
|
||||||
|
@ -71,6 +85,7 @@ test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) {
|
||||||
t.ok(journeys.length > 0, 'no journeys')
|
t.ok(journeys.length > 0, 'no journeys')
|
||||||
for (let journey of journeys) {
|
for (let journey of journeys) {
|
||||||
assertValidStation(t, journey.origin)
|
assertValidStation(t, journey.origin)
|
||||||
|
assertValidStationProducts(t, journey.origin.products)
|
||||||
if (!(yield findStation(journey.origin.id))) {
|
if (!(yield findStation(journey.origin.id))) {
|
||||||
console.error('unknown station', journey.origin.id, journey.origin.name)
|
console.error('unknown station', journey.origin.id, journey.origin.name)
|
||||||
}
|
}
|
||||||
|
@ -80,6 +95,7 @@ test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) {
|
||||||
t.ok(isValidWhen(journey.departure))
|
t.ok(isValidWhen(journey.departure))
|
||||||
|
|
||||||
assertValidStation(t, journey.destination)
|
assertValidStation(t, journey.destination)
|
||||||
|
assertValidStationProducts(t, journey.origin.products)
|
||||||
if (!(yield findStation(journey.origin.id))) {
|
if (!(yield findStation(journey.origin.id))) {
|
||||||
console.error('unknown station', journey.destination.id, journey.destination.name)
|
console.error('unknown station', journey.destination.id, journey.destination.name)
|
||||||
}
|
}
|
||||||
|
@ -93,6 +109,7 @@ test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) {
|
||||||
const part = journey.parts[0]
|
const part = journey.parts[0]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, part.origin)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
if (!(yield findStation(part.origin.id))) {
|
if (!(yield findStation(part.origin.id))) {
|
||||||
console.error('unknown station', part.origin.id, part.origin.name)
|
console.error('unknown station', part.origin.id, part.origin.name)
|
||||||
}
|
}
|
||||||
|
@ -100,6 +117,7 @@ test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) {
|
||||||
t.equal(typeof part.departurePlatform, 'string')
|
t.equal(typeof part.departurePlatform, 'string')
|
||||||
|
|
||||||
assertValidStation(t, part.destination)
|
assertValidStation(t, part.destination)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
if (!(yield findStation(part.destination.id))) {
|
if (!(yield findStation(part.destination.id))) {
|
||||||
console.error('unknown station', part.destination.id, part.destination.name)
|
console.error('unknown station', part.destination.id, part.destination.name)
|
||||||
}
|
}
|
||||||
|
@ -127,6 +145,7 @@ test('Berlin Jungfernheide to Torfstraße 17', co.wrap(function* (t) {
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const part = journey.parts[journey.parts.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, part.origin)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
if (!(yield findStation(part.origin.id))) {
|
if (!(yield findStation(part.origin.id))) {
|
||||||
console.error('unknown station', part.origin.id, part.origin.name)
|
console.error('unknown station', part.origin.id, part.origin.name)
|
||||||
}
|
}
|
||||||
|
@ -155,6 +174,7 @@ test('Berlin Jungfernheide to ATZE Musiktheater', co.wrap(function* (t) {
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const part = journey.parts[journey.parts.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, part.origin)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
if (!(yield findStation(part.origin.id))) {
|
if (!(yield findStation(part.origin.id))) {
|
||||||
console.error('unknown station', part.origin.id, part.origin.name)
|
console.error('unknown station', part.origin.id, part.origin.name)
|
||||||
}
|
}
|
||||||
|
@ -179,6 +199,7 @@ test('departures at Berlin Jungfernheide', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(deps))
|
t.ok(Array.isArray(deps))
|
||||||
for (let dep of deps) {
|
for (let dep of deps) {
|
||||||
assertValidStation(t, dep.station)
|
assertValidStation(t, dep.station)
|
||||||
|
assertValidStationProducts(t, dep.station.products)
|
||||||
if (!(yield findStation(dep.station.id))) {
|
if (!(yield findStation(dep.station.id))) {
|
||||||
console.error('unknown station', dep.station.id, dep.station.name)
|
console.error('unknown station', dep.station.id, dep.station.name)
|
||||||
}
|
}
|
||||||
|
|
20
test/vbb.js
20
test/vbb.js
|
@ -21,6 +21,17 @@ const {
|
||||||
assertValidWhen
|
assertValidWhen
|
||||||
} = require('./util')
|
} = require('./util')
|
||||||
|
|
||||||
|
const assertValidStationProducts = (t, p) => {
|
||||||
|
t.ok(p)
|
||||||
|
t.equal(typeof p.suburban, 'boolean')
|
||||||
|
t.equal(typeof p.subway, 'boolean')
|
||||||
|
t.equal(typeof p.tram, 'boolean')
|
||||||
|
t.equal(typeof p.bus, 'boolean')
|
||||||
|
t.equal(typeof p.ferry, 'boolean')
|
||||||
|
t.equal(typeof p.express, 'boolean')
|
||||||
|
t.equal(typeof p.regional, 'boolean')
|
||||||
|
}
|
||||||
|
|
||||||
// todo
|
// todo
|
||||||
const findStation = (query) => stations(query, true, false)
|
const findStation = (query) => stations(query, true, false)
|
||||||
|
|
||||||
|
@ -41,11 +52,13 @@ test('journeys – station to station', co.wrap(function* (t) {
|
||||||
|
|
||||||
for (let journey of journeys) {
|
for (let journey of journeys) {
|
||||||
assertValidStation(t, journey.origin)
|
assertValidStation(t, journey.origin)
|
||||||
|
assertValidStationProducts(t, journey.origin.products)
|
||||||
t.ok(journey.origin.name.indexOf('(Berlin)') === -1)
|
t.ok(journey.origin.name.indexOf('(Berlin)') === -1)
|
||||||
t.strictEqual(journey.origin.id, spichernstr)
|
t.strictEqual(journey.origin.id, spichernstr)
|
||||||
assertValidWhen(t, journey.departure)
|
assertValidWhen(t, journey.departure)
|
||||||
|
|
||||||
assertValidStation(t, journey.destination)
|
assertValidStation(t, journey.destination)
|
||||||
|
assertValidStationProducts(t, journey.destination.products)
|
||||||
t.strictEqual(journey.destination.id, amrumerStr)
|
t.strictEqual(journey.destination.id, amrumerStr)
|
||||||
assertValidWhen(t, journey.arrival)
|
assertValidWhen(t, journey.arrival)
|
||||||
|
|
||||||
|
@ -56,11 +69,13 @@ test('journeys – station to station', co.wrap(function* (t) {
|
||||||
t.equal(typeof part.id, 'string')
|
t.equal(typeof part.id, 'string')
|
||||||
t.ok(part.id)
|
t.ok(part.id)
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, part.origin)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
t.ok(part.origin.name.indexOf('(Berlin)') === -1)
|
t.ok(part.origin.name.indexOf('(Berlin)') === -1)
|
||||||
t.strictEqual(part.origin.id, spichernstr)
|
t.strictEqual(part.origin.id, spichernstr)
|
||||||
assertValidWhen(t, part.departure)
|
assertValidWhen(t, part.departure)
|
||||||
|
|
||||||
assertValidStation(t, part.destination)
|
assertValidStation(t, part.destination)
|
||||||
|
assertValidStationProducts(t, part.destination.products)
|
||||||
t.strictEqual(part.destination.id, amrumerStr)
|
t.strictEqual(part.destination.id, amrumerStr)
|
||||||
assertValidWhen(t, part.arrival)
|
assertValidWhen(t, part.arrival)
|
||||||
|
|
||||||
|
@ -161,6 +176,7 @@ test('journeys – station to address', co.wrap(function* (t) {
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const part = journey.parts[journey.parts.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, part.origin)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
assertValidWhen(t, part.departure)
|
assertValidWhen(t, part.departure)
|
||||||
|
|
||||||
const dest = part.destination
|
const dest = part.destination
|
||||||
|
@ -187,6 +203,7 @@ test('journeys – station to POI', co.wrap(function* (t) {
|
||||||
const part = journey.parts[journey.parts.length - 1]
|
const part = journey.parts[journey.parts.length - 1]
|
||||||
|
|
||||||
assertValidStation(t, part.origin)
|
assertValidStation(t, part.origin)
|
||||||
|
assertValidStationProducts(t, part.origin.products)
|
||||||
assertValidWhen(t, part.departure)
|
assertValidWhen(t, part.departure)
|
||||||
|
|
||||||
const dest = part.destination
|
const dest = part.destination
|
||||||
|
@ -212,6 +229,7 @@ test('departures', co.wrap(function* (t) {
|
||||||
|
|
||||||
t.equal(dep.station.name, 'U Spichernstr.')
|
t.equal(dep.station.name, 'U Spichernstr.')
|
||||||
assertValidStation(t, dep.station)
|
assertValidStation(t, dep.station)
|
||||||
|
assertValidStationProducts(t, dep.station.products)
|
||||||
t.strictEqual(dep.station.id, spichernstr)
|
t.strictEqual(dep.station.id, spichernstr)
|
||||||
|
|
||||||
assertValidWhen(t, dep.when)
|
assertValidWhen(t, dep.when)
|
||||||
|
@ -311,8 +329,10 @@ test('radar', co.wrap(function* (t) {
|
||||||
t.ok(Array.isArray(v.frames))
|
t.ok(Array.isArray(v.frames))
|
||||||
for (let f of v.frames) {
|
for (let f of v.frames) {
|
||||||
assertValidStation(t, f.origin, true)
|
assertValidStation(t, f.origin, true)
|
||||||
|
assertValidStationProducts(t, f.origin.products)
|
||||||
t.strictEqual(f.origin.name.indexOf('(Berlin)'), -1)
|
t.strictEqual(f.origin.name.indexOf('(Berlin)'), -1)
|
||||||
assertValidStation(t, f.destination, true)
|
assertValidStation(t, f.destination, true)
|
||||||
|
assertValidStationProducts(t, f.destination.products)
|
||||||
t.strictEqual(f.destination.name.indexOf('(Berlin)'), -1)
|
t.strictEqual(f.destination.name.indexOf('(Berlin)'), -1)
|
||||||
t.equal(typeof f.t, 'number')
|
t.equal(typeof f.t, 'number')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue