pass warnings into parsers, apply warnings to journey legs

This commit is contained in:
Jannis R 2018-06-07 18:48:45 +02:00
parent d909be3b65
commit fa2cdc5177
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
7 changed files with 18 additions and 19 deletions

View file

@ -51,7 +51,7 @@ const createClient = (profile, request = _request) => {
})
.then((d) => {
if (!Array.isArray(d.jnyL)) return [] // todo: throw err?
const parse = profile.parseDeparture(profile, d.locations, d.lines, d.hints)
const parse = profile.parseDeparture(profile, d.locations, d.lines, d.hints, d.warnings)
return d.jnyL.map(parse)
.sort((a, b) => new Date(a.when) - new Date(b.when))
})
@ -164,7 +164,7 @@ const createClient = (profile, request = _request) => {
if (!Array.isArray(d.outConL)) return []
const polylines = opt.polylines && d.common.polyL || []
const parse = profile.parseJourney(profile, d.locations, d.lines, d.hints, polylines)
const parse = profile.parseJourney(profile, d.locations, d.lines, d.hints, d.warnings, polylines)
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
@ -310,7 +310,7 @@ const createClient = (profile, request = _request) => {
})
.then((d) => {
const polylines = opt.polyline && d.common.polyL || []
const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.hints, polylines)
const parse = profile.parseJourneyLeg(profile, d.locations, d.lines, d.hints, d.warnings, polylines)
const leg = { // pretend the leg is contained in a journey
type: 'JNY',
@ -363,7 +363,7 @@ const createClient = (profile, request = _request) => {
if (!Array.isArray(d.jnyL)) return []
const polylines = opt.polyline && d.common.polyL || []
const parse = profile.parseMovement(profile, d.locations, d.lines, d.hints, polylines)
const parse = profile.parseMovement(profile, d.locations, d.lines, d.hints, d.warnings, polylines)
return d.jnyL.map(parse)
})
}

View file

@ -8,7 +8,7 @@ const findRemark = require('./find-remark')
// 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 createParseDeparture = (profile, stations, lines, hints, warnings) => {
const parseDeparture = (d) => {
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
const res = {
@ -18,7 +18,7 @@ const createParseDeparture = (profile, stations, lines, hints) => {
direction: profile.parseStationName(d.dirTxt),
line: lines[parseInt(d.prodX)] || null,
remarks: (d.remL
? d.remL.map(ref => findRemark(hints, ref))
? d.remL.map(ref => findRemark(hints, warnings, ref))
: []
),
trip: +d.jid.split('|')[1] // todo: this seems brittle

View file

@ -10,9 +10,8 @@
// - warnings: notes from `himL` for cancellations, construction, etc
// - remarks: both "notes" and "warnings"
const findRemark = (hints, ref) => {
// todo: `warnings[ref.himX]`
return hints[ref.remX] || null
const findRemark = (hints, warnings, ref) => {
return warnings[ref.himX] || hints[ref.remX] || null
}
module.exports = findRemark

View file

@ -5,9 +5,9 @@ const findRemark = require('./find-remark')
const clone = obj => Object.assign({}, obj)
const applyRemarksToStopovers = (stopovers, hints, refs) => {
const applyRemarksToStopovers = (stopovers, hints, warnings, refs) => {
for (let ref of refs) {
const remark = findRemark(hints, ref)
const remark = findRemark(hints, warnings, ref)
for (let i = ref.fLocX; i <= ref.tLocX; i++) {
const stopover = stopovers[i]
if (Array.isArray(stopover.remarks)) {
@ -20,7 +20,7 @@ const applyRemarksToStopovers = (stopovers, hints, refs) => {
}
}
const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => {
const createParseJourneyLeg = (profile, stations, lines, hints, warnings, polylines) => {
// todo: pt.sDays
// todo: pt.dep.dProgType, pt.arr.dProgType
// todo: what is pt.jny.dirFlg?
@ -68,14 +68,14 @@ const createParseJourneyLeg = (profile, stations, lines, hints, polylines) => {
if (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS
if (passed && pt.jny.stopL) {
const parse = profile.parseStopover(profile, stations, lines, hints, j.date)
const parse = profile.parseStopover(profile, stations, lines, hints, warnings, j.date)
const passedStations = pt.jny.stopL.map(parse)
// 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
if (Array.isArray(j.msgL)) {
applyRemarksToStopovers(passedStations, hints, j.msgL)
applyRemarksToStopovers(passedStations, hints, warnings, j.msgL)
}
}

View file

@ -2,8 +2,8 @@
const clone = obj => Object.assign({}, obj)
const createParseJourney = (profile, stations, lines, hints, polylines) => {
const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, polylines)
const createParseJourney = (profile, stations, lines, hints, warnings, polylines) => {
const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, warnings, polylines)
// todo: c.sDays
// todo: c.conSubscr

View file

@ -1,6 +1,6 @@
'use strict'
const createParseMovement = (profile, locations, lines, hints, polylines = []) => {
const createParseMovement = (profile, locations, lines, hints, warnings, polylines = []) => {
// todo: what is m.dirGeo? maybe the speed?
// todo: what is m.stopL?
// todo: what is m.proc? wut?
@ -8,7 +8,7 @@ const createParseMovement = (profile, locations, lines, hints, polylines = []) =
// todo: what is m.ani.dirGeo[n]? maybe the speed?
// todo: what is m.ani.proc[n]? wut?
const parseMovement = (m) => {
const pStopover = profile.parseStopover(profile, locations, lines, hints, m.date)
const pStopover = profile.parseStopover(profile, locations, lines, hints, warnings, m.date)
const res = {
direction: profile.parseStationName(m.dirTxt),

View file

@ -2,7 +2,7 @@
// todo: arrivalDelay, departureDelay or only delay ?
// todo: arrivalPlatform, departurePlatform
const createParseStopover = (profile, stations, lines, hints, date) => {
const createParseStopover = (profile, stations, lines, hints, warnings, date) => {
const parseStopover = (st) => {
const res = {
station: stations[parseInt(st.locX)] || null,