diff --git a/index.js b/index.js index ff474687..38fab4ab 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ const createClient = (profile, request = _request) => { }) .then((d) => { if (!Array.isArray(d.jnyL)) return [] // todo: throw err? - const parse = profile.parseDeparture(profile, d.locations, d.lines, d.hints) + const parse = profile.parseDeparture(profile, d.locations, d.lines, d.hints, d.warnings) return d.jnyL.map(parse) .sort((a, b) => new Date(a.when) - new Date(b.when)) }) @@ -164,7 +164,7 @@ const createClient = (profile, request = _request) => { if (!Array.isArray(d.outConL)) return [] const polylines = opt.polylines && d.common.polyL || [] - const parse = profile.parseJourney(profile, d.locations, d.lines, d.hints, polylines) + const parse = profile.parseJourney(profile, d.locations, d.lines, d.hints, d.warnings, polylines) if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB @@ -310,7 +310,7 @@ const createClient = (profile, request = _request) => { }) .then((d) => { const polylines = opt.polyline && d.common.polyL || [] - const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.hints, polylines) + const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.hints, d.warnings, polylines) const leg = { // pretend the leg is contained in a journey type: 'JNY', @@ -363,7 +363,7 @@ const createClient = (profile, request = _request) => { if (!Array.isArray(d.jnyL)) return [] const polylines = opt.polyline && d.common.polyL || [] - const parse = profile.parseMovement(profile, d.locations, d.lines, d.hints, polylines) + const parse = profile.parseMovement(profile, d.locations, d.lines, d.hints, d.warnings, polylines) return d.jnyL.map(parse) }) } diff --git a/parse/departure.js b/parse/departure.js index fddef97e..a9a5995e 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -8,7 +8,7 @@ const findRemark = require('./find-remark') // todo: d.stbStop.dProgType // 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 createParseDeparture = (profile, stations, lines, hints, warnings) => { const parseDeparture = (d) => { const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS) const res = { @@ -18,7 +18,7 @@ const createParseDeparture = (profile, stations, lines, hints) => { direction: profile.parseStationName(d.dirTxt), line: lines[parseInt(d.prodX)] || null, remarks: (d.remL - ? d.remL.map(ref => findRemark(hints, ref)) + ? d.remL.map(ref => findRemark(hints, warnings, ref)) : [] ), trip: +d.jid.split('|')[1] // todo: this seems brittle diff --git a/parse/find-remark.js b/parse/find-remark.js index c21aa8ab..9bf89884 100644 --- a/parse/find-remark.js +++ b/parse/find-remark.js @@ -10,9 +10,8 @@ // - warnings: notes from `himL` for cancellations, construction, etc // - remarks: both "notes" and "warnings" -const findRemark = (hints, ref) => { - // todo: `warnings[ref.himX]` - return hints[ref.remX] || null +const findRemark = (hints, warnings, ref) => { + return warnings[ref.himX] || hints[ref.remX] || null } module.exports = findRemark diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 31c743cd..4d98b609 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -5,9 +5,9 @@ const findRemark = require('./find-remark') const clone = obj => Object.assign({}, obj) -const applyRemarksToStopovers = (stopovers, hints, refs) => { +const applyRemarksToStopovers = (stopovers, hints, warnings, refs) => { for (let ref of refs) { - const remark = findRemark(hints, ref) + const remark = findRemark(hints, warnings, ref) for (let i = ref.fLocX; i <= ref.tLocX; i++) { const stopover = stopovers[i] if (Array.isArray(stopover.remarks)) { @@ -20,7 +20,7 @@ const applyRemarksToStopovers = (stopovers, hints, refs) => { } } -const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => { +const createParseJourneyLeg = (profile, stations, lines, hints, warnings, polylines) => { // todo: pt.sDays // todo: pt.dep.dProgType, pt.arr.dProgType // todo: what is pt.jny.dirFlg? @@ -68,14 +68,14 @@ const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => { if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS if (passed && pt.jny.stopL) { - const parse = profile.parseStopover(profile, stations, lines, hints, j.date) + const parse = profile.parseStopover(profile, stations, lines, hints, warnings, j.date) const passedStations = pt.jny.stopL.map(parse) // 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 if (Array.isArray(j.msgL)) { - applyRemarksToStopovers(passedStations, hints, j.msgL) + applyRemarksToStopovers(passedStations, hints, warnings, j.msgL) } } diff --git a/parse/journey.js b/parse/journey.js index d174dd4e..18cd3029 100644 --- a/parse/journey.js +++ b/parse/journey.js @@ -2,8 +2,8 @@ const clone = obj => Object.assign({}, obj) -const createParseJourney = (profile, stations, lines, hints, polylines) => { - const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, polylines) +const createParseJourney = (profile, stations, lines, hints, warnings, polylines) => { + const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, warnings, polylines) // todo: c.sDays // todo: c.conSubscr diff --git a/parse/movement.js b/parse/movement.js index 82176eb1..2aa48b84 100644 --- a/parse/movement.js +++ b/parse/movement.js @@ -1,6 +1,6 @@ 'use strict' -const createParseMovement = (profile, locations, lines, hints, polylines = []) => { +const createParseMovement = (profile, locations, lines, hints, warnings, polylines = []) => { // todo: what is m.dirGeo? maybe the speed? // todo: what is m.stopL? // todo: what is m.proc? wut? @@ -8,7 +8,7 @@ const createParseMovement = (profile, locations, lines, hints, polylines = []) = // todo: what is m.ani.dirGeo[n]? maybe the speed? // todo: what is m.ani.proc[n]? wut? const parseMovement = (m) => { - const pStopover = profile.parseStopover(profile, locations, lines, hints, m.date) + const pStopover = profile.parseStopover(profile, locations, lines, hints, warnings, m.date) const res = { direction: profile.parseStationName(m.dirTxt), diff --git a/parse/stopover.js b/parse/stopover.js index 622d3d56..c01dbc15 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -2,7 +2,7 @@ // todo: arrivalDelay, departureDelay or only delay ? // todo: arrivalPlatform, departurePlatform -const createParseStopover = (profile, stations, lines, hints, date) => { +const createParseStopover = (profile, stations, lines, hints, warnings, date) => { const parseStopover = (st) => { const res = { station: stations[parseInt(st.locX)] || null,