From a475f2048df447d323bd3c7c2f5124630b032d43 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Tue, 10 Jul 2018 23:32:34 +0200 Subject: [PATCH] parse stops and their stations --- lib/request.js | 12 +++++++++++- p/oebb/index.js | 2 +- p/vbb/index.js | 2 +- parse/location.js | 12 ++++++------ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/request.js b/lib/request.js index 1261a180..709fa483 100644 --- a/lib/request.js +++ b/lib/request.js @@ -104,8 +104,18 @@ const request = (profile, opt, data) => { d.lines = c.prodL.map(parse) } if (Array.isArray(c.locL)) { - const parse = loc => profile.parseLocation(profile, opt, {lines: d.lines}, loc) + const data = {lines: d.lines} + const parse = loc => profile.parseLocation(profile, opt, data, loc) + d.locations = c.locL.map(parse) + for (let i = 0; i < d.locations.length; i++) { + const raw = c.locL[i] + const loc = d.locations[i] + if ('number' === typeof raw.mMastLocX) { + loc.station = Object.assign({}, d.locations[raw.mMastLocX]) + loc.station.type = 'station' + } else if (raw.isMainMast) loc.type = 'station' + } } return d }) diff --git a/p/oebb/index.js b/p/oebb/index.js index c6fbb1e7..2dd24b49 100644 --- a/p/oebb/index.js +++ b/p/oebb/index.js @@ -30,7 +30,7 @@ const parseLocation = (profile, opt, data, l) => { // like station entrances, that are actually POIs. const res = _parseLocation(profile, opt, data, l) if ( - res.type === 'station' && + (res.type === 'station' || res.type === 'stop') && !res.products && res.name && res.id && res.id.length !== 7 diff --git a/p/vbb/index.js b/p/vbb/index.js index cfb14373..18909ded 100644 --- a/p/vbb/index.js +++ b/p/vbb/index.js @@ -45,7 +45,7 @@ const createParseLine = (profile, opt, data) => { const parseLocation = (profile, opt, data, l) => { const res = _parseLocation(profile, opt, data, l) - if (res.type === 'station') { + if (res.type === 'stop' || res.type === 'station') { res.name = shorten(res.name) res.id = to12Digit(res.id) if (!res.location.latitude || !res.location.longitude) { diff --git a/parse/location.js b/parse/location.js index 2e53f431..2283ef2b 100644 --- a/parse/location.js +++ b/parse/location.js @@ -13,28 +13,28 @@ const parseLocation = (profile, opt, {lines}, l) => { } if (l.type === STATION) { - const station = { - type: 'station', + const stop = { + type: l.isMainMast ? 'station' : 'stop', id: l.extId, name: l.name ? profile.parseStationName(l.name) : null, location: 'number' === typeof res.latitude ? res : null } - if ('pCls' in l) station.products = profile.parseProducts(l.pCls) + if ('pCls' in l) stop.products = profile.parseProducts(l.pCls) if ( opt.stationLines && Array.isArray(l.pRefL) && Array.isArray(lines) ) { - station.lines = [] + stop.lines = [] for (let pRef of l.pRefL) { const line = lines[pRef] - if (line) station.lines.push(line) + if (line) stop.lines.push(line) } } - return station + return stop } if (l.type === ADDRESS) res.address = l.name