journey leg passed stations: parse & expose delays

backporting 21c273c to master
This commit is contained in:
Jannis R 2018-06-07 18:52:12 +02:00
parent 92310ebdab
commit 49186ae2d1
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 23 additions and 1 deletions

View file

@ -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})

View file

@ -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)

View file

@ -5,16 +5,34 @@
const createParseStopover = (profile, stations, lines, remarks, date) => {
const parseStopover = (st) => {
const res = {
station: stations[parseInt(st.locX)] || null
station: stations[parseInt(st.locX)] || null,
arrival: 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