From d77c450d11da9b7e659ee8470f6a9294c6fa6814 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 11 Dec 2017 14:41:28 +0100 Subject: [PATCH] fix products parsing :bug:, minor changes --- p/vbb/index.js | 2 +- p/vbb/modes.js | 44 +++++++++------------------------------ parse/departure.js | 1 + parse/products-bitmask.js | 4 ++-- test/db.js | 21 +++++++++++++++++++ test/vbb.js | 20 ++++++++++++++++++ 6 files changed, 55 insertions(+), 37 deletions(-) diff --git a/p/vbb/index.js b/p/vbb/index.js index 9bfd1a9a..4e0ddd72 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -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 } } diff --git a/p/vbb/modes.js b/p/vbb/modes.js index 0ce23156..65adc5be 100644 --- a/p/vbb/modes.js +++ b/p/vbb/modes.js @@ -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' } } diff --git a/parse/departure.js b/parse/departure.js index f159a98e..ba897cf5 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -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 diff --git a/parse/products-bitmask.js b/parse/products-bitmask.js index 6f31530c..4880da7d 100644 --- a/parse/products-bitmask.js +++ b/parse/products-bitmask.js @@ -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 diff --git a/test/db.js b/test/db.js index 9b7b927b..76ec2132 100644 --- a/test/db.js +++ b/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) } diff --git a/test/vbb.js b/test/vbb.js index 53b8de79..7e039dde 100644 --- a/test/vbb.js +++ b/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') }