mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09: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)]
|
||||
if (data) {
|
||||
res.mode = data.mode
|
||||
res.product = data.type
|
||||
res.product = data.product
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,7 @@ const m = {
|
|||
name: 'S-Bahn',
|
||||
mode: 'train',
|
||||
short: 'S',
|
||||
type: 'suburban',
|
||||
color: '#008c4f',
|
||||
unicode: '🚈',
|
||||
ansi: ['green'] // `chalk` color code
|
||||
product: 'suburban'
|
||||
},
|
||||
|
||||
subway: {
|
||||
|
@ -20,10 +17,7 @@ const m = {
|
|||
name: 'U-Bahn',
|
||||
mode: 'train',
|
||||
short: 'U',
|
||||
type: 'subway',
|
||||
color: '#0067ac',
|
||||
unicode: '🚇',
|
||||
ansi: ['blue'] // `chalk` color code
|
||||
product: 'subway'
|
||||
},
|
||||
|
||||
tram: {
|
||||
|
@ -32,34 +26,25 @@ const m = {
|
|||
name: 'Tram',
|
||||
mode: 'train',
|
||||
short: 'T',
|
||||
type: 'tram',
|
||||
color: '#e3001b',
|
||||
unicode: '🚋',
|
||||
ansi: ['red'] // `chalk` color code
|
||||
product: 'tram'
|
||||
},
|
||||
|
||||
bus: {
|
||||
category: 3,
|
||||
bitmask: 8,
|
||||
name: 'Bus',
|
||||
mode: 'train',
|
||||
mode: 'bus',
|
||||
short: 'B',
|
||||
type: 'bus',
|
||||
color: '#922A7D',
|
||||
unicode: '🚌',
|
||||
ansi: ['dim', 'magenta'] // `chalk` color codes
|
||||
product: 'bus'
|
||||
},
|
||||
|
||||
ferry: {
|
||||
category: 4,
|
||||
bitmask: 16,
|
||||
name: 'Fähre',
|
||||
mode: 'train',
|
||||
mode: 'ferry',
|
||||
short: 'F',
|
||||
type: 'ferry',
|
||||
color: '#099bd6',
|
||||
unicode: '🚢',
|
||||
ansi: ['cyan'] // `chalk` color code
|
||||
product: 'ferry'
|
||||
},
|
||||
|
||||
express: {
|
||||
|
@ -68,10 +53,7 @@ const m = {
|
|||
name: 'IC/ICE',
|
||||
mode: 'train',
|
||||
short: 'E',
|
||||
type: 'express',
|
||||
color: '#f4e613',
|
||||
unicode: '🚄',
|
||||
ansi: ['yellow'] // `chalk` color code
|
||||
product: 'express'
|
||||
},
|
||||
|
||||
regional: {
|
||||
|
@ -80,10 +62,7 @@ const m = {
|
|||
name: 'RB/RE',
|
||||
mode: 'train',
|
||||
short: 'R',
|
||||
type: 'regional',
|
||||
color: '#D9222A',
|
||||
unicode: '🚆',
|
||||
ansi: ['red'] // `chalk` color code
|
||||
product: 'regional'
|
||||
},
|
||||
|
||||
unknown: {
|
||||
|
@ -92,10 +71,7 @@ const m = {
|
|||
name: 'unknown',
|
||||
mode: null,
|
||||
short: '?',
|
||||
type: 'unknown',
|
||||
color: '#555555',
|
||||
unicode: '?',
|
||||
ansi: ['gray'] // `chalk` color code
|
||||
product: 'unknown'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
// - stdStop.dPlatfS, stdStop.dPlatfR
|
||||
// todo: what is d.jny.dirFlg?
|
||||
// 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 tz = profile.timezone
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const createParseBitmask = (bitmasks) => {
|
||||
const createBitmask = (bitmask) => {
|
||||
const parseBitmask = (bitmask) => {
|
||||
const products = {}
|
||||
let i = 1
|
||||
do {
|
||||
|
@ -10,7 +10,7 @@ const createParseBitmask = (bitmasks) => {
|
|||
} while (bitmasks[i] && bitmasks[i].product)
|
||||
return products
|
||||
}
|
||||
return createBitmask
|
||||
return parseBitmask
|
||||
}
|
||||
|
||||
module.exports = createParseBitmask
|
||||
|
|
21
test/db.js
21
test/db.js
|
@ -19,6 +19,20 @@ const {
|
|||
when, isValidWhen
|
||||
} = 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 stations = getStations()
|
||||
stations
|
||||
|
@ -71,6 +85,7 @@ test('Berlin Jungfernheide to München Hbf', co.wrap(function* (t) {
|
|||
t.ok(journeys.length > 0, 'no journeys')
|
||||
for (let journey of journeys) {
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
if (!(yield findStation(journey.origin.id))) {
|
||||
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))
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
if (!(yield findStation(journey.origin.id))) {
|
||||
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]
|
||||
|
||||
assertValidStation(t, part.origin)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
if (!(yield findStation(part.origin.id))) {
|
||||
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')
|
||||
|
||||
assertValidStation(t, part.destination)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
if (!(yield findStation(part.destination.id))) {
|
||||
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]
|
||||
|
||||
assertValidStation(t, part.origin)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
if (!(yield findStation(part.origin.id))) {
|
||||
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]
|
||||
|
||||
assertValidStation(t, part.origin)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
if (!(yield findStation(part.origin.id))) {
|
||||
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))
|
||||
for (let dep of deps) {
|
||||
assertValidStation(t, dep.station)
|
||||
assertValidStationProducts(t, dep.station.products)
|
||||
if (!(yield findStation(dep.station.id))) {
|
||||
console.error('unknown station', dep.station.id, dep.station.name)
|
||||
}
|
||||
|
|
20
test/vbb.js
20
test/vbb.js
|
@ -21,6 +21,17 @@ const {
|
|||
assertValidWhen
|
||||
} = 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
|
||||
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) {
|
||||
assertValidStation(t, journey.origin)
|
||||
assertValidStationProducts(t, journey.origin.products)
|
||||
t.ok(journey.origin.name.indexOf('(Berlin)') === -1)
|
||||
t.strictEqual(journey.origin.id, spichernstr)
|
||||
assertValidWhen(t, journey.departure)
|
||||
|
||||
assertValidStation(t, journey.destination)
|
||||
assertValidStationProducts(t, journey.destination.products)
|
||||
t.strictEqual(journey.destination.id, amrumerStr)
|
||||
assertValidWhen(t, journey.arrival)
|
||||
|
||||
|
@ -56,11 +69,13 @@ test('journeys – station to station', co.wrap(function* (t) {
|
|||
t.equal(typeof part.id, 'string')
|
||||
t.ok(part.id)
|
||||
assertValidStation(t, part.origin)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
t.ok(part.origin.name.indexOf('(Berlin)') === -1)
|
||||
t.strictEqual(part.origin.id, spichernstr)
|
||||
assertValidWhen(t, part.departure)
|
||||
|
||||
assertValidStation(t, part.destination)
|
||||
assertValidStationProducts(t, part.destination.products)
|
||||
t.strictEqual(part.destination.id, amrumerStr)
|
||||
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]
|
||||
|
||||
assertValidStation(t, part.origin)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
assertValidWhen(t, part.departure)
|
||||
|
||||
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]
|
||||
|
||||
assertValidStation(t, part.origin)
|
||||
assertValidStationProducts(t, part.origin.products)
|
||||
assertValidWhen(t, part.departure)
|
||||
|
||||
const dest = part.destination
|
||||
|
@ -212,6 +229,7 @@ test('departures', co.wrap(function* (t) {
|
|||
|
||||
t.equal(dep.station.name, 'U Spichernstr.')
|
||||
assertValidStation(t, dep.station)
|
||||
assertValidStationProducts(t, dep.station.products)
|
||||
t.strictEqual(dep.station.id, spichernstr)
|
||||
|
||||
assertValidWhen(t, dep.when)
|
||||
|
@ -311,8 +329,10 @@ test('radar', co.wrap(function* (t) {
|
|||
t.ok(Array.isArray(v.frames))
|
||||
for (let f of v.frames) {
|
||||
assertValidStation(t, f.origin, true)
|
||||
assertValidStationProducts(t, f.origin.products)
|
||||
t.strictEqual(f.origin.name.indexOf('(Berlin)'), -1)
|
||||
assertValidStation(t, f.destination, true)
|
||||
assertValidStationProducts(t, f.destination.products)
|
||||
t.strictEqual(f.destination.name.indexOf('(Berlin)'), -1)
|
||||
t.equal(typeof f.t, 'number')
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue