db-vendo-client/parse/departure.js
Jannis R d2257c26ff
rename d.remarks -> d.hints, parseRemark -> parseHint
HAFAS returns notes for journey legs, stopovers and departures.

There are two kinds of notes: "remarks" (in `remL`) and HAFAS
Information Manager (HIM) notes (in `himL`). The former describe
the regular operating situation, e.g. "bicycles allows", whereas
the latter describe cancellations, construction work, etc.

The planned naming scheme for hafas-client:
- hints: notes from `remL` for regular operation
- warnings: notes from `himL` for cancellations, construction, etc
- remarks: both "notes" and "warnings"

This commit prepares the new naming scheme by renaming the
existing parsing logic of `remL` to "hints". Follow-up commits
will add `parseWarning`.
2018-06-07 16:34:50 +02:00

48 lines
1.6 KiB
JavaScript

'use strict'
// todos from public-transport/hafas-client#2
// - stdStop.dPlatfS, stdStop.dPlatfR
// todo: what is d.jny.dirFlg?
// todo: d.stbStop.dProgType
// todo: d.freq, d.freq.jnyL, see https://github.com/public-transport/hafas-client/blob/9203ed1481f08baacca41ac5e3c19bf022f01b0b/parse.js#L115
const createParseDeparture = (profile, stations, lines, hints) => {
const findHint = rm => hints[parseInt(rm.remX)] || null
const parseDeparture = (d) => {
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
const res = {
journeyId: d.jid,
station: stations[parseInt(d.stbStop.locX)] || null,
when: when.toISO(),
direction: profile.parseStationName(d.dirTxt),
line: lines[parseInt(d.prodX)] || null,
remarks: d.remL ? d.remL.map(findHint) : [],
trip: +d.jid.split('|')[1] // todo: this seems brittle
}
// todo: res.trip from rawLine.prodCtx.num?
// todo: DRY with parseStopover
// todo: DRY with parseJourneyLeg
if (d.stbStop.dTimeR && d.stbStop.dTimeS) {
const realtime = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR)
const planned = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS)
res.delay = Math.round((realtime - planned) / 1000)
} else res.delay = null
if (d.stbStop.aCncl || d.stbStop.dCncl) {
res.cancelled = true
Object.defineProperty(res, 'canceled', {value: true})
res.when = res.delay = null
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeS)
res.formerScheduledWhen = when.toISO()
}
return res
}
return parseDeparture
}
module.exports = createParseDeparture