2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
// todos from derhuerst/hafas-client#2
|
|
|
|
// - stdStop.dPlatfS, stdStop.dPlatfR
|
|
|
|
// todo: what is d.jny.dirFlg?
|
|
|
|
// todo: d.stbStop.dProgType
|
2017-12-11 14:41:28 +01:00
|
|
|
// todo: d.freq, d.freq.jnyL, see https://github.com/derhuerst/hafas-client/blob/9203ed1481f08baacca41ac5e3c19bf022f01b0b/parse.js#L115
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2017-11-12 01:23:34 +01:00
|
|
|
const createParseDeparture = (profile, stations, lines, remarks) => {
|
2017-11-11 23:56:09 +01:00
|
|
|
const findRemark = rm => remarks[parseInt(rm.remX)] || null
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
const parseDeparture = (d) => {
|
2017-12-11 17:21:50 +01:00
|
|
|
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
2017-11-11 23:56:09 +01:00
|
|
|
const res = {
|
2017-12-11 15:20:50 +01:00
|
|
|
journeyId: d.jid,
|
2017-11-12 00:36:13 +01:00
|
|
|
station: stations[parseInt(d.stbStop.locX)] || null,
|
2017-12-11 19:53:26 +01:00
|
|
|
when: when.toISO(),
|
2017-12-11 15:20:50 +01:00
|
|
|
direction: profile.parseStationName(d.dirTxt),
|
2017-11-12 00:36:13 +01:00
|
|
|
line: lines[parseInt(d.prodX)] || null,
|
2017-11-11 23:56:09 +01:00
|
|
|
remarks: d.remL ? d.remL.map(findRemark) : [],
|
|
|
|
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
2018-01-23 02:37:08 +01:00
|
|
|
// todo: res.trip from rawLine.prodCtx.num?
|
2017-11-11 22:35:41 +01:00
|
|
|
|
|
|
|
if (d.stbStop.dTimeR && d.stbStop.dTimeS) {
|
2017-12-11 17:21:50 +01:00
|
|
|
const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR)
|
|
|
|
const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS)
|
2017-11-11 23:56:09 +01:00
|
|
|
res.delay = Math.round((realtime - planned) / 1000)
|
|
|
|
} else res.delay = null
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2017-12-18 21:11:35 +01:00
|
|
|
// todo: follow public-transport/friendly-public-transport-format#27 here
|
|
|
|
// see also derhuerst/vbb-rest#19
|
2017-12-18 23:33:29 +01:00
|
|
|
if (d.stbStop.aCncl || d.stbStop.dCncl) {
|
2017-12-18 21:11:35 +01:00
|
|
|
res.cancelled = true
|
2018-03-08 03:26:39 +01:00
|
|
|
Object.defineProperty(res, 'canceled', {value: true})
|
2017-12-18 21:11:35 +01:00
|
|
|
res.when = res.delay = null
|
2018-03-08 03:26:39 +01:00
|
|
|
|
|
|
|
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS)
|
|
|
|
res.formerScheduledWhen = when.toISO()
|
2017-12-18 21:11:35 +01:00
|
|
|
}
|
|
|
|
|
2017-11-11 23:56:09 +01:00
|
|
|
return res
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return parseDeparture
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createParseDeparture
|