remarks for journey legs

This commit is contained in:
Jannis R 2018-06-07 16:38:54 +02:00
parent d2257c26ff
commit b6e37595a5
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
2 changed files with 26 additions and 4 deletions

View file

@ -1,5 +1,7 @@
'use strict'
const findRemark = require('./find-remark')
// todos from public-transport/hafas-client#2
// - stdStop.dPlatfS, stdStop.dPlatfR
// todo: what is d.jny.dirFlg?
@ -7,8 +9,6 @@
// 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 = {
@ -17,7 +17,10 @@ const createParseDeparture = (profile, stations, lines, hints) => {
when: when.toISO(),
direction: profile.parseStationName(d.dirTxt),
line: lines[parseInt(d.prodX)] || null,
remarks: d.remL ? d.remL.map(findHint) : [],
remarks: (d.remL
? d.remL.map(ref => findRemark(hints, ref))
: []
),
trip: +d.jid.split('|')[1] // todo: this seems brittle
}
// todo: res.trip from rawLine.prodCtx.num?

View file

@ -1,9 +1,25 @@
'use strict'
const parseDateTime = require('./date-time')
const findRemark = require('./find-remark')
const clone = obj => Object.assign({}, obj)
const applyRemarksToStopovers = (stopovers, hints, refs) => {
for (let ref of refs) {
const remark = findRemark(hints, ref)
for (let i = ref.fLocX; i <= ref.tLocX; i++) {
const stopover = stopovers[i]
if (Array.isArray(stopover.remarks)) {
stopover.remarks.push(remark)
} else {
stopover.remarks = [remark]
}
}
// todo: `ref.tagL`
}
}
const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => {
// todo: pt.sDays
// todo: pt.dep.dProgType, pt.arr.dProgType
@ -57,7 +73,10 @@ const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => {
// filter stations the train passes without stopping, as this doesn't comply with fptf (yet)
res.passed = passedStations.filter((x) => !x.passBy)
// todo: pt.jny.remL, j.msgL
// todo: pt.jny.remL
if (Array.isArray(j.msgL)) {
applyRemarksToStopovers(passedStations, hints, j.msgL)
}
}
const freq = pt.jny.freq || {}