diff --git a/parse/departure.js b/parse/departure.js index e1fb069b..fddef97e 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -1,5 +1,7 @@ 'use strict' +const findRemark = require('./find-remark') + // todos from public-transport/hafas-client#2 // - stdStop.dPlatfS, stdStop.dPlatfR // todo: what is d.jny.dirFlg? @@ -7,8 +9,6 @@ // todo: d.freq, d.freq.jnyL, see https://github.com/public-transport/hafas-client/blob/9203ed1481f08baacca41ac5e3c19bf022f01b0b/parse.js#L115 const createParseDeparture = (profile, stations, lines, hints) => { - const findHint = rm => hints[parseInt(rm.remX)] || null - const parseDeparture = (d) => { const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS) const res = { @@ -17,7 +17,10 @@ const createParseDeparture = (profile, stations, lines, hints) => { when: when.toISO(), direction: profile.parseStationName(d.dirTxt), line: lines[parseInt(d.prodX)] || null, - remarks: d.remL ? d.remL.map(findHint) : [], + remarks: (d.remL + ? d.remL.map(ref => findRemark(hints, ref)) + : [] + ), trip: +d.jid.split('|')[1] // todo: this seems brittle } // todo: res.trip from rawLine.prodCtx.num? diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 390d6320..31c743cd 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -1,9 +1,25 @@ 'use strict' const parseDateTime = require('./date-time') +const findRemark = require('./find-remark') const clone = obj => Object.assign({}, obj) +const applyRemarksToStopovers = (stopovers, hints, refs) => { + for (let ref of refs) { + const remark = findRemark(hints, ref) + for (let i = ref.fLocX; i <= ref.tLocX; i++) { + const stopover = stopovers[i] + if (Array.isArray(stopover.remarks)) { + stopover.remarks.push(remark) + } else { + stopover.remarks = [remark] + } + } + // todo: `ref.tagL` + } +} + const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => { // todo: pt.sDays // todo: pt.dep.dProgType, pt.arr.dProgType @@ -57,7 +73,10 @@ const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => { // filter stations the train passes without stopping, as this doesn't comply with fptf (yet) res.passed = passedStations.filter((x) => !x.passBy) - // todo: pt.jny.remL, j.msgL + // todo: pt.jny.remL + if (Array.isArray(j.msgL)) { + applyRemarksToStopovers(passedStations, hints, j.msgL) + } } const freq = pt.jny.freq || {}