diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 8c0f4d86..bbddf771 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -1,6 +1,7 @@ 'use strict' const parseWhen = require('./when') +const parsePlatform = require('./platform') const findRemarks = require('./find-remarks') const ARRIVAL = 'a' @@ -21,20 +22,14 @@ const createParseArrOrDep = (profile, opt, data, prefix) => { const res = { tripId: d.jid, stop: d.stbStop.location || null, - ...parseWhen(profile, d.date, tPlanned, tPrognosed, tzOffset, cancelled) + ...parseWhen(profile, d.date, tPlanned, tPrognosed, tzOffset, cancelled), + ...parsePlatform(profile, d.stbStop[prefix + 'PlatfS'], d.stbStop[prefix + 'PlatfR'], cancelled), // todo: for arrivals, this is the *origin*, not the *direction* direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null, line: d.line || null, remarks: [] } - // todo: DRY with parseStopover - // todo: DRY with parseJourneyLeg - const pR = d.stbStop[prefix + 'PlatfR'] - const pP = d.stbStop[prefix + 'PlatfS'] - res.platform = pR || pP || null - if (pR && pP && pR !== pP) res.scheduledPlatform = pP - if (cancelled) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index e0c49c64..87a138fd 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -1,6 +1,7 @@ 'use strict' const parseWhen = require('./when') +const parsePlatform = require('./platform') const findRemarks = require('./find-remarks') const clone = obj => Object.assign({}, obj) @@ -85,15 +86,15 @@ const createParseJourneyLeg = (profile, opt, data) => { 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 - if (pt.arr.aPlatfR && pt.arr.aPlatfS && pt.arr.aPlatfR !== pt.arr.aPlatfS) { - res.scheduledArrivalPlatform = pt.arr.aPlatfS - } + const arrPl = parsePlatform(profile, pt.arr.aPlatfS, pt.arr.aPlatfR, pt.arr.aCncl) + res.arrivalPlatform = arrPl.platform + res.plannedArrivalPlatform = arrPl.plannedPlatform + if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform - res.departurePlatform = pt.dep.dPlatfR || pt.dep.dPlatfS || null - if (pt.dep.dPlatfR && pt.dep.dPlatfS && pt.dep.dPlatfR !== pt.dep.dPlatfS) { - res.scheduledDeparturePlatform = pt.dep.dPlatfS - } + const depPl = parsePlatform(profile, pt.dep.dPlatfS, pt.dep.dPlatfR, pt.dep.dCncl) + res.departurePlatform = depPl.platform + res.plannedDeparturePlatform = depPl.plannedPlatform + if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform if (parseStopovers && pt.jny.stopL) { const parse = profile.parseStopover(profile, opt, data, j.date) diff --git a/parse/platform.js b/parse/platform.js new file mode 100644 index 00000000..10cefb3c --- /dev/null +++ b/parse/platform.js @@ -0,0 +1,20 @@ +'use strict' + +const parsePlatform = (profile, platfS, platfR, cncl = false) => { + let planned = platfS || null + let prognosed = platfR || null + + if (cncl) { + return { + platform: null, + plannedPlatform: planned, + prognosedPlatform: prognosed + } + } + return { + platform: prognosed, + plannedPlatform: planned + } +} + +module.exports = parsePlatform diff --git a/parse/stopover.js b/parse/stopover.js index 65785f38..eb501510 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -1,34 +1,34 @@ 'use strict' const parseWhen = require('./when') +const parsePlatform = require('./platform') const findRemarks = require('./find-remarks') const createParseStopover = (profile, opt, data, date) => { const parseStopover = (st) => { const arr = parseWhen(profile, date, st.aTimeS, st.aTimeR, st.aTZOffset, st.aCncl) + const arrPl = parsePlatform(profile, st.aPlatfS, st.aPlatfR, st.aCncl) const dep = parseWhen(profile, date, st.dTimeS, st.dTimeR, st.dTZOffset, st.dCncl) + const depPl = parsePlatform(profile, st.dPlatfS, st.dPlatfR, st.dCncl) const res = { stop: st.location || null, arrival: arr.when, plannedArrival: arr.plannedWhen, arrivalDelay: arr.delay, - arrivalPlatform: st.aPlatfR || st.aPlatfS || null, + arrivalPlatform: arrPl.platform, + plannedArrivalPlatform: arrPl.plannedPlatform, departure: dep.when, plannedDeparture: dep.plannedWhen, departureDelay: dep.delay, - departurePlatform: st.dPlatfR || st.dPlatfS || null + departurePlatform: depPl.platform, + plannedDeparturePlatform: depPl.plannedPlatform } if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen + if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform if (dep.prognosedWhen) res.prognosedDeparture = dep.prognosedWhen - - if (st.aPlatfR && st.aPlatfS && st.aPlatfR !== st.aPlatfS) { - res.scheduledArrivalPlatform = st.aPlatfS - } - if (st.dPlatfR && st.dPlatfS && st.dPlatfR !== st.dPlatfS) { - res.scheduledDeparturePlatform = st.dPlatfS - } + if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform // mark stations the train passes without stopping if(st.dInS === false && st.aOutS === false) res.passBy = true diff --git a/parse/when.js b/parse/when.js index 373d0963..4c2b689e 100644 --- a/parse/when.js +++ b/parse/when.js @@ -17,7 +17,7 @@ const parseWhen = (profile, date, timeS, timeR, tzOffset, cncl = false) => { return { when: null, plannedWhen: planned, - prognosedWhen: when, + prognosedWhen: prognosed, delay } }