journey leg passed stations: parse & expose delays

This commit is contained in:
Jannis R 2018-06-07 18:52:12 +02:00
parent 0136189aa4
commit 21c273cec7
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 21 additions and 1 deletions

View file

@ -30,6 +30,8 @@ const createParseDeparture = (profile, stations, lines, remarks) => {
res.delay = Math.round((realtime - planned) / 1000) res.delay = Math.round((realtime - planned) / 1000)
} else res.delay = null } else res.delay = null
// todo: DRY with parseStopover
// todo: DRY with parseJourneyLeg
if (d.stbStop.aCncl || d.stbStop.dCncl) { if (d.stbStop.aCncl || d.stbStop.dCncl) {
res.cancelled = true res.cancelled = true
Object.defineProperty(res, 'canceled', {value: true}) Object.defineProperty(res, 'canceled', {value: true})

View file

@ -23,6 +23,8 @@ const createParseJourneyLeg = (profile, stations, lines, remarks, polylines) =>
arrival: arr.toISO() arrival: arr.toISO()
} }
// todo: DRY with parseDeparture
// todo: DRY with parseStopover
if (pt.dep.dTimeR && pt.dep.dTimeS) { if (pt.dep.dTimeR && pt.dep.dTimeS) {
const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR) const realtime = profile.parseDateTime(profile, j.date, pt.dep.dTimeR)
const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS) const planned = profile.parseDateTime(profile, j.date, pt.dep.dTimeS)

View file

@ -7,16 +7,32 @@ const createParseStopover = (profile, stations, lines, remarks, date) => {
const res = { const res = {
station: stations[parseInt(st.locX)] || null, station: stations[parseInt(st.locX)] || null,
arrival: null, arrival: null,
departure: null arrivalDelay: null,
departure: null,
departureDelay: null
} }
// todo: DRY with parseDeparture
// todo: DRY with parseJourneyLeg
if (st.aTimeR || st.aTimeS) { if (st.aTimeR || st.aTimeS) {
const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS) const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS)
res.arrival = arr.toISO() 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) { if (st.dTimeR || st.dTimeS) {
const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS) const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS)
res.departure = dep.toISO() 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 // mark stations the train passes without stopping
if(st.dInS === false && st.aOutS === false) res.passBy = true if(st.dInS === false && st.aOutS === false) res.passBy = true