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 ?
|
2018-06-26 12:52:33 +02:00
|
|
|
const createParseStopover = (profile, opt, data, date) => {
|
|
|
|
const {locations, lines, hints, warnings} = data
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
const parseStopover = (st) => {
|
|
|
|
const res = {
|
2018-06-26 12:52:33 +02:00
|
|
|
stop: locations[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
|
|
|
|
2018-07-09 13:12:26 +02:00
|
|
|
if (st.aPlatfR && st.aPlatfS && st.aPlatfR !== st.aPlatfS) {
|
|
|
|
res.formerScheduledArrivalPlatform = st.aPlatfS
|
|
|
|
}
|
|
|
|
if (st.dPlatfR && st.dPlatfS && st.dPlatfR !== st.dPlatfS) {
|
|
|
|
res.formerScheduledDeparturePlatform = st.dPlatfS
|
|
|
|
}
|
|
|
|
|
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-06-28 16:34:49 +02:00
|
|
|
if (st.aTimeS) {
|
|
|
|
const arr = profile.parseDateTime(profile, date, st.aTimeS)
|
|
|
|
res.formerScheduledArrival = arr.toISO()
|
|
|
|
}
|
2018-03-17 17:14:47 +01:00
|
|
|
}
|
|
|
|
if (st.dCncl) {
|
|
|
|
res.departure = res.departureDelay = null
|
2018-06-28 16:34:49 +02:00
|
|
|
if (st.dTimeS) {
|
|
|
|
const arr = profile.parseDateTime(profile, date, st.dTimeS)
|
|
|
|
res.formerScheduledDeparture = arr.toISO()
|
|
|
|
}
|
2018-03-17 17:14:47 +01:00
|
|
|
}
|
2017-12-18 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 13:45:56 +02:00
|
|
|
if (opt.remarks && Array.isArray(st.msgL)) {
|
2018-06-11 11:29:32 +02:00
|
|
|
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
|