From 21c273cec7e71612b6a32b89068a211e56a8fa5d Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 7 Jun 2018 18:52:12 +0200 Subject: [PATCH] journey leg passed stations: parse & expose delays --- parse/departure.js | 2 ++ parse/journey-leg.js | 2 ++ parse/stopover.js | 18 +++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/parse/departure.js b/parse/departure.js index 158eb1ea..1a496bc7 100644 --- a/parse/departure.js +++ b/parse/departure.js @@ -30,6 +30,8 @@ const createParseDeparture = (profile, stations, lines, remarks) => { res.delay = Math.round((realtime - planned) / 1000) } else res.delay = null + // todo: DRY with parseStopover + // todo: DRY with parseJourneyLeg if (d.stbStop.aCncl || d.stbStop.dCncl) { res.cancelled = true Object.defineProperty(res, 'canceled', {value: true}) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index bbc3f9da..331f0c36 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -23,6 +23,8 @@ const createParseJourneyLeg = (profile, stations, lines, remarks, polylines) => arrival: arr.toISO() } + // todo: DRY with parseDeparture + // todo: DRY with parseStopover if (pt.dep.dTimeR && pt.dep.dTimeS) { const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR) const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) diff --git a/parse/stopover.js b/parse/stopover.js index 8315c814..52f69b17 100644 --- a/parse/stopover.js +++ b/parse/stopover.js @@ -7,16 +7,32 @@ const createParseStopover = (profile, stations, lines, remarks, date) => { const res = { station: stations[parseInt(st.locX)] || null, arrival: null, - departure: null + arrivalDelay: null, + departure: null, + departureDelay: null } + + // todo: DRY with parseDeparture + // todo: DRY with parseJourneyLeg if (st.aTimeR || st.aTimeS) { const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS) res.arrival = arr.toISO() } + if (st.aTimeR && st.aTimeS) { + const realtime = profile.parseDateTime(profile, date, st.aTimeR) + const planned = profile.parseDateTime(profile, date, st.aTimeS) + res.arrivalDelay = Math.round((realtime - planned) / 1000) + } + if (st.dTimeR || st.dTimeS) { const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS) res.departure = dep.toISO() } + if (st.dTimeR && st.dTimeS) { + const realtime = profile.parseDateTime(profile, date, st.dTimeR) + const planned = profile.parseDateTime(profile, date, st.dTimeS) + res.departureDelay = Math.round((realtime - planned) / 1000) + } // mark stations the train passes without stopping if(st.dInS === false && st.aOutS === false) res.passBy = true