From d3d23140fd1f4f2d1d78b2f9f7712c72ef7ce3a7 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 11 Jun 2018 11:29:32 +0200 Subject: [PATCH] (more) remarks for journeys, journey legs & stopovers --- parse/journey-leg.js | 25 +++++++++++++++---------- parse/journey.js | 10 +++++++++- parse/stopover.js | 10 ++++++++++ 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 4d98b609..cf7928b5 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -5,16 +5,21 @@ const findRemark = require('./find-remark') const clone = obj => Object.assign({}, obj) -const applyRemarksToStopovers = (stopovers, hints, warnings, refs) => { +const applyRemarks = (leg, hints, warnings, refs) => { for (let ref of refs) { const remark = findRemark(hints, warnings, 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] + if ('number' === typeof ref.fLocX && 'number' === typeof ref.tLocX) { + for (let i = ref.fLocX; i <= ref.tLocX; i++) { + const stopover = leg.passed[i] + if (Array.isArray(stopover.remarks)) { + stopover.remarks.push(remark) + } else { + stopover.remarks = [remark] + } } + } else { + if (Array.isArray(leg.remarks)) leg.remarks.push(remark) + else leg.remarks = [remark] } // todo: `ref.tagL` } @@ -73,9 +78,9 @@ const createParseJourneyLeg = (profile, stations, lines, hints, warnings, polyli // 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, warnings, j.msgL) + // todo: is there a `pt.jny.remL`? + if (Array.isArray(pt.jny.msgL)) { + applyRemarks(res, hints, warnings, pt.jny.msgL) } } diff --git a/parse/journey.js b/parse/journey.js index 18cd3029..d071013f 100644 --- a/parse/journey.js +++ b/parse/journey.js @@ -1,6 +1,6 @@ 'use strict' -const clone = obj => Object.assign({}, obj) +const findRemark = require('./find-remark') const createParseJourney = (profile, stations, lines, hints, warnings, polylines) => { const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, warnings, polylines) @@ -15,6 +15,14 @@ const createParseJourney = (profile, stations, lines, hints, warnings, polylines legs } + if (Array.isArray(j.msgL)) { + res.remarks = [] + for (let ref of j.msgL) { + const remark = findRemark(hints, warnings, ref) + if (remark) res.remarks.push(remark) + } + } + return res } diff --git a/parse/stopover.js b/parse/stopover.js index c01dbc15..5dc23e39 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -1,5 +1,7 @@ 'use strict' +const findRemark = require('./find-remark') + // todo: arrivalDelay, departureDelay or only delay ? // todo: arrivalPlatform, departurePlatform const createParseStopover = (profile, stations, lines, hints, warnings, date) => { @@ -38,6 +40,14 @@ const createParseStopover = (profile, stations, lines, hints, warnings, date) => } } + if (Array.isArray(st.msgL)) { + res.remarks = [] + for (let ref of st.msgL) { + const remark = findRemark(hints, warnings, ref) + if (remark) res.remarks.push(remark) + } + } + return res }