diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 1c376e6e..b71fb3a5 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -9,7 +9,7 @@ const DEPARTURE = 'd' // todo: d.stbStop.dProgType/d.stbStop.aProgType const createParseArrOrDep = (profile, opt, data, prefix) => { - const {locations, lines, hints, warnings} = data + const {locations, hints, warnings} = data if (prefix !== ARRIVAL && prefix !== DEPARTURE) throw new Error('invalid prefix') const parseArrOrDep = (d) => { @@ -22,7 +22,7 @@ const createParseArrOrDep = (profile, opt, data, prefix) => { when: profile.parseDateTime(profile, d.date, t, tz), // todo: for arrivals, this is the *origin*, not the *direction* direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null, - line: lines[parseInt(d.prodX)] || null, + line: d.line || null, remarks: [] } diff --git a/parse/common.js b/parse/common.js index 285b10c1..9fc84c35 100644 --- a/parse/common.js +++ b/parse/common.js @@ -33,6 +33,14 @@ const parseCommonData = (profile, opt, res) => { if (Array.isArray(c.prodL)) { const parse = profile.parseLine(profile, opt, res) res.lines = c.prodL.map(parse) + + resolveIdxRefs(res, '**.prodX', res.lines, 'line') + findIdxRefs(res, '**.pRefL', (idxs, parent) => { + parent.lines = idxs.filter(idx => !!res.lines[idx]).map(idx => res.lines[idx]) + }) + // todo + // resolveIdxRefs(res, '**.dep.dProdX', res.lines, 'departureLine') + // resolveIdxRefs(res, '**.arr.aProdX', res.lines, 'arrivalLine') } res.locations = [] diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 1097947e..288f0c20 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -40,7 +40,7 @@ const applyRemarks = (leg, hints, warnings, refs) => { } const createParseJourneyLeg = (profile, opt, data) => { - const {locations, lines, hints, warnings, polylines} = data + const {locations, hints, warnings, polylines} = data // todo: pt.status, pt.isPartCncl // todo: pt.isRchbl, pt.chRatingRT, pt.chgDurR, pt.minChg // todo: pt.dep.dProgType, pt.arr.dProgType @@ -100,7 +100,7 @@ const createParseJourneyLeg = (profile, opt, data) => { } else if (pt.type === 'JNY') { // todo: pull `public` value from `profile.products` res.tripId = pt.jny.jid - res.line = lines[parseInt(pt.jny.prodX)] || null + res.line = pt.jny.line || null res.direction = pt.jny.dirTxt && profile.parseStationName(pt.jny.dirTxt) || null res.arrivalPlatform = pt.arr.aPlatfR ||pt.arr.aPlatfS || null @@ -161,7 +161,7 @@ const createParseJourneyLeg = (profile, opt, data) => { } return { tripId: a.jid, - line: lines[parseInt(a.prodX)] || null, + line: a.line || null, direction: a.dirTxt || null, when, delay } diff --git a/parse/location.js b/parse/location.js index 22d1023f..80891e58 100644 --- a/parse/location.js +++ b/parse/location.js @@ -9,7 +9,7 @@ const ADDRESS = 'A' const leadingZeros = /^0+/ // todo: what is s.rRefL? -const parseLocation = (profile, opt, {lines}, l) => { +const parseLocation = (profile, opt, _, l) => { const lid = parse(l.lid, {delimiter: '@'}) const res = { type: 'location', @@ -32,16 +32,8 @@ const parseLocation = (profile, opt, {lines}, l) => { if ('pCls' in l) stop.products = profile.parseProducts(l.pCls) if ('meta' in l) stop.isMeta = !!l.meta - if ( - opt.linesOfStops && - Array.isArray(l.pRefL) && - Array.isArray(lines) - ) { - stop.lines = [] - for (let pRef of l.pRefL) { - const line = lines[pRef] - if (line) stop.lines.push(line) - } + if (opt.linesOfStops && Array.isArray(l.lines)) { + stop.lines = l.lines } return stop diff --git a/parse/movement.js b/parse/movement.js index 1ebbe4b8..975af21a 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -1,7 +1,7 @@ 'use strict' const createParseMovement = (profile, opt, data) => { - const {locations, lines, polylines} = data + const {locations, polylines} = data // todo: what is m.dirGeo? maybe the speed? // todo: what is m.stopL? @@ -15,7 +15,7 @@ const createParseMovement = (profile, opt, data) => { const res = { direction: m.dirTxt ? profile.parseStationName(m.dirTxt) : null, tripId: m.jid || null, - line: lines[m.prodX] || null, + line: m.line || null, location: m.pos ? { type: 'location', latitude: m.pos.y / 1000000,