mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
pass warnings into parsers, apply warnings to journey legs
This commit is contained in:
parent
d909be3b65
commit
fa2cdc5177
7 changed files with 18 additions and 19 deletions
8
index.js
8
index.js
|
@ -51,7 +51,7 @@ const createClient = (profile, request = _request) => {
|
||||||
})
|
})
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
if (!Array.isArray(d.jnyL)) return [] // todo: throw err?
|
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)
|
return d.jnyL.map(parse)
|
||||||
.sort((a, b) => new Date(a.when) - new Date(b.when))
|
.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 []
|
if (!Array.isArray(d.outConL)) return []
|
||||||
|
|
||||||
const polylines = opt.polylines && d.common.polyL || []
|
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
|
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ const createClient = (profile, request = _request) => {
|
||||||
})
|
})
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
const polylines = opt.polyline && d.common.polyL || []
|
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
|
const leg = { // pretend the leg is contained in a journey
|
||||||
type: 'JNY',
|
type: 'JNY',
|
||||||
|
@ -363,7 +363,7 @@ const createClient = (profile, request = _request) => {
|
||||||
if (!Array.isArray(d.jnyL)) return []
|
if (!Array.isArray(d.jnyL)) return []
|
||||||
|
|
||||||
const polylines = opt.polyline && d.common.polyL || []
|
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)
|
return d.jnyL.map(parse)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ const findRemark = require('./find-remark')
|
||||||
// todo: d.stbStop.dProgType
|
// todo: d.stbStop.dProgType
|
||||||
// todo: d.freq, d.freq.jnyL, see https://github.com/public-transport/hafas-client/blob/9203ed1481f08baacca41ac5e3c19bf022f01b0b/parse.js#L115
|
// 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 parseDeparture = (d) => {
|
||||||
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
const when = profile.parseDateTime(profile, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
||||||
const res = {
|
const res = {
|
||||||
|
@ -18,7 +18,7 @@ const createParseDeparture = (profile, stations, lines, hints) => {
|
||||||
direction: profile.parseStationName(d.dirTxt),
|
direction: profile.parseStationName(d.dirTxt),
|
||||||
line: lines[parseInt(d.prodX)] || null,
|
line: lines[parseInt(d.prodX)] || null,
|
||||||
remarks: (d.remL
|
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
|
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
||||||
|
|
|
@ -10,9 +10,8 @@
|
||||||
// - warnings: notes from `himL` for cancellations, construction, etc
|
// - warnings: notes from `himL` for cancellations, construction, etc
|
||||||
// - remarks: both "notes" and "warnings"
|
// - remarks: both "notes" and "warnings"
|
||||||
|
|
||||||
const findRemark = (hints, ref) => {
|
const findRemark = (hints, warnings, ref) => {
|
||||||
// todo: `warnings[ref.himX]`
|
return warnings[ref.himX] || hints[ref.remX] || null
|
||||||
return hints[ref.remX] || null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = findRemark
|
module.exports = findRemark
|
||||||
|
|
|
@ -5,9 +5,9 @@ const findRemark = require('./find-remark')
|
||||||
|
|
||||||
const clone = obj => Object.assign({}, obj)
|
const clone = obj => Object.assign({}, obj)
|
||||||
|
|
||||||
const applyRemarksToStopovers = (stopovers, hints, refs) => {
|
const applyRemarksToStopovers = (stopovers, hints, warnings, refs) => {
|
||||||
for (let ref of 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++) {
|
for (let i = ref.fLocX; i <= ref.tLocX; i++) {
|
||||||
const stopover = stopovers[i]
|
const stopover = stopovers[i]
|
||||||
if (Array.isArray(stopover.remarks)) {
|
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.sDays
|
||||||
// todo: pt.dep.dProgType, pt.arr.dProgType
|
// todo: pt.dep.dProgType, pt.arr.dProgType
|
||||||
// todo: what is pt.jny.dirFlg?
|
// 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 (pt.arr.aPlatfS) res.arrivalPlatform = pt.arr.aPlatfS
|
||||||
|
|
||||||
if (passed && pt.jny.stopL) {
|
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)
|
const passedStations = pt.jny.stopL.map(parse)
|
||||||
// filter stations the train passes without stopping, as this doesn't comply with fptf (yet)
|
// filter stations the train passes without stopping, as this doesn't comply with fptf (yet)
|
||||||
res.passed = passedStations.filter((x) => !x.passBy)
|
res.passed = passedStations.filter((x) => !x.passBy)
|
||||||
|
|
||||||
// todo: pt.jny.remL
|
// todo: pt.jny.remL
|
||||||
if (Array.isArray(j.msgL)) {
|
if (Array.isArray(j.msgL)) {
|
||||||
applyRemarksToStopovers(passedStations, hints, j.msgL)
|
applyRemarksToStopovers(passedStations, hints, warnings, j.msgL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
const clone = obj => Object.assign({}, obj)
|
const clone = obj => Object.assign({}, obj)
|
||||||
|
|
||||||
const createParseJourney = (profile, stations, lines, hints, polylines) => {
|
const createParseJourney = (profile, stations, lines, hints, warnings, polylines) => {
|
||||||
const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, polylines)
|
const parseLeg = profile.parseJourneyLeg(profile, stations, lines, hints, warnings, polylines)
|
||||||
|
|
||||||
// todo: c.sDays
|
// todo: c.sDays
|
||||||
// todo: c.conSubscr
|
// todo: c.conSubscr
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict'
|
'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.dirGeo? maybe the speed?
|
||||||
// todo: what is m.stopL?
|
// todo: what is m.stopL?
|
||||||
// todo: what is m.proc? wut?
|
// 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.dirGeo[n]? maybe the speed?
|
||||||
// todo: what is m.ani.proc[n]? wut?
|
// todo: what is m.ani.proc[n]? wut?
|
||||||
const parseMovement = (m) => {
|
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 = {
|
const res = {
|
||||||
direction: profile.parseStationName(m.dirTxt),
|
direction: profile.parseStationName(m.dirTxt),
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
// todo: arrivalDelay, departureDelay or only delay ?
|
// todo: arrivalDelay, departureDelay or only delay ?
|
||||||
// todo: arrivalPlatform, departurePlatform
|
// todo: arrivalPlatform, departurePlatform
|
||||||
const createParseStopover = (profile, stations, lines, hints, date) => {
|
const createParseStopover = (profile, stations, lines, hints, warnings, date) => {
|
||||||
const parseStopover = (st) => {
|
const parseStopover = (st) => {
|
||||||
const res = {
|
const res = {
|
||||||
station: stations[parseInt(st.locX)] || null,
|
station: stations[parseInt(st.locX)] || null,
|
||||||
|
|
Loading…
Add table
Reference in a new issue