2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-06-11 11:29:32 +02:00
|
|
|
const findRemark = require('./find-remark')
|
|
|
|
|
2017-12-18 21:11:35 +01:00
|
|
|
// todo: arrivalDelay, departureDelay or only delay ?
|
|
|
|
// todo: arrivalPlatform, departurePlatform
|
2018-06-07 18:48:45 +02:00
|
|
|
const createParseStopover = (profile, stations, lines, hints, warnings, date) => {
|
2017-11-11 22:35:41 +01:00
|
|
|
const parseStopover = (st) => {
|
|
|
|
const res = {
|
2018-06-25 11:33:26 +02:00
|
|
|
type: 'stopover',
|
|
|
|
stop: stations[parseInt(st.locX)] || null,
|
2018-03-29 02:45:15 +02:00
|
|
|
arrival: null,
|
2018-06-07 18:52:12 +02:00
|
|
|
arrivalDelay: null,
|
2018-06-22 13:38:47 +02:00
|
|
|
arrivalPlatform: st.aPlatfR || st.aPlatfS || null,
|
2018-06-07 18:52:12 +02:00
|
|
|
departure: null,
|
2018-06-22 13:38:47 +02:00
|
|
|
departureDelay: null,
|
|
|
|
departurePlatform: st.dPlatfR || st.dPlatfS || null
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2018-06-07 18:52:12 +02:00
|
|
|
|
|
|
|
// todo: DRY with parseDeparture
|
|
|
|
// todo: DRY with parseJourneyLeg
|
2017-11-11 22:35:41 +01:00
|
|
|
if (st.aTimeR || st.aTimeS) {
|
2018-03-17 16:41:57 +01:00
|
|
|
const arr = profile.parseDateTime(profile, date, st.aTimeR || st.aTimeS)
|
2017-12-11 19:40:46 +01:00
|
|
|
res.arrival = arr.toISO()
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2018-06-07 18:52:12 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
if (st.dTimeR || st.dTimeS) {
|
2018-03-17 16:41:57 +01:00
|
|
|
const dep = profile.parseDateTime(profile, date, st.dTimeR || st.dTimeS)
|
2017-12-11 19:40:46 +01:00
|
|
|
res.departure = dep.toISO()
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2018-06-07 18:52:12 +02:00
|
|
|
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)
|
|
|
|
}
|
2017-12-18 21:11:35 +01:00
|
|
|
|
2017-12-29 09:00:18 +01:00
|
|
|
// mark stations the train passes without stopping
|
|
|
|
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
|
|
|
|
2018-03-17 17:14:47 +01:00
|
|
|
// todo: DRY with parseDeparture
|
|
|
|
// todo: DRY with parseJourneyLeg
|
|
|
|
if (st.aCncl || st.dCncl) {
|
2017-12-18 21:11:35 +01:00
|
|
|
res.cancelled = true
|
2018-03-17 17:14:47 +01:00
|
|
|
Object.defineProperty(res, 'canceled', {value: true})
|
|
|
|
if (st.aCncl) {
|
|
|
|
res.arrival = res.arrivalDelay = null
|
2018-04-05 14:23:14 +02:00
|
|
|
const arr = profile.parseDateTime(profile, date, st.aTimeS)
|
2018-03-17 17:14:47 +01:00
|
|
|
res.formerScheduledArrival = arr.toISO()
|
|
|
|
}
|
|
|
|
if (st.dCncl) {
|
|
|
|
res.departure = res.departureDelay = null
|
2018-04-05 14:23:14 +02:00
|
|
|
const arr = profile.parseDateTime(profile, date, st.dTimeS)
|
2018-03-17 17:14:47 +01:00
|
|
|
res.formerScheduledDeparture = arr.toISO()
|
|
|
|
}
|
2017-12-18 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
2018-06-11 11:29:32 +02:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
return res
|
|
|
|
}
|
|
|
|
|
|
|
|
return parseStopover
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createParseStopover
|