mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
parseCommon: resolve line references
This commit is contained in:
parent
0cc17ee780
commit
758deaf2d5
5 changed files with 18 additions and 18 deletions
|
@ -9,7 +9,7 @@ const DEPARTURE = 'd'
|
||||||
// todo: d.stbStop.dProgType/d.stbStop.aProgType
|
// todo: d.stbStop.dProgType/d.stbStop.aProgType
|
||||||
|
|
||||||
const createParseArrOrDep = (profile, opt, data, prefix) => {
|
const createParseArrOrDep = (profile, opt, data, prefix) => {
|
||||||
const {locations, lines, hints, warnings} = data
|
const {locations, hints, warnings} = data
|
||||||
if (prefix !== ARRIVAL && prefix !== DEPARTURE) throw new Error('invalid prefix')
|
if (prefix !== ARRIVAL && prefix !== DEPARTURE) throw new Error('invalid prefix')
|
||||||
|
|
||||||
const parseArrOrDep = (d) => {
|
const parseArrOrDep = (d) => {
|
||||||
|
@ -22,7 +22,7 @@ const createParseArrOrDep = (profile, opt, data, prefix) => {
|
||||||
when: profile.parseDateTime(profile, d.date, t, tz),
|
when: profile.parseDateTime(profile, d.date, t, tz),
|
||||||
// todo: for arrivals, this is the *origin*, not the *direction*
|
// todo: for arrivals, this is the *origin*, not the *direction*
|
||||||
direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null,
|
direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null,
|
||||||
line: lines[parseInt(d.prodX)] || null,
|
line: d.line || null,
|
||||||
remarks: []
|
remarks: []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,14 @@ const parseCommonData = (profile, opt, res) => {
|
||||||
if (Array.isArray(c.prodL)) {
|
if (Array.isArray(c.prodL)) {
|
||||||
const parse = profile.parseLine(profile, opt, res)
|
const parse = profile.parseLine(profile, opt, res)
|
||||||
res.lines = c.prodL.map(parse)
|
res.lines = c.prodL.map(parse)
|
||||||
|
|
||||||
|
resolveIdxRefs(res, '**.prodX', res.lines, 'line')
|
||||||
|
findIdxRefs(res, '**.pRefL', (idxs, parent) => {
|
||||||
|
parent.lines = idxs.filter(idx => !!res.lines[idx]).map(idx => res.lines[idx])
|
||||||
|
})
|
||||||
|
// todo
|
||||||
|
// resolveIdxRefs(res, '**.dep.dProdX', res.lines, 'departureLine')
|
||||||
|
// resolveIdxRefs(res, '**.arr.aProdX', res.lines, 'arrivalLine')
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locations = []
|
res.locations = []
|
||||||
|
|
|
@ -40,7 +40,7 @@ const applyRemarks = (leg, hints, warnings, refs) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const createParseJourneyLeg = (profile, opt, data) => {
|
const createParseJourneyLeg = (profile, opt, data) => {
|
||||||
const {locations, lines, hints, warnings, polylines} = data
|
const {locations, hints, warnings, polylines} = data
|
||||||
// todo: pt.status, pt.isPartCncl
|
// todo: pt.status, pt.isPartCncl
|
||||||
// todo: pt.isRchbl, pt.chRatingRT, pt.chgDurR, pt.minChg
|
// todo: pt.isRchbl, pt.chRatingRT, pt.chgDurR, pt.minChg
|
||||||
// todo: pt.dep.dProgType, pt.arr.dProgType
|
// todo: pt.dep.dProgType, pt.arr.dProgType
|
||||||
|
@ -100,7 +100,7 @@ const createParseJourneyLeg = (profile, opt, data) => {
|
||||||
} else if (pt.type === 'JNY') {
|
} else if (pt.type === 'JNY') {
|
||||||
// todo: pull `public` value from `profile.products`
|
// todo: pull `public` value from `profile.products`
|
||||||
res.tripId = pt.jny.jid
|
res.tripId = pt.jny.jid
|
||||||
res.line = lines[parseInt(pt.jny.prodX)] || null
|
res.line = pt.jny.line || null
|
||||||
res.direction = pt.jny.dirTxt && profile.parseStationName(pt.jny.dirTxt) || null
|
res.direction = pt.jny.dirTxt && profile.parseStationName(pt.jny.dirTxt) || null
|
||||||
|
|
||||||
res.arrivalPlatform = pt.arr.aPlatfR ||pt.arr.aPlatfS || null
|
res.arrivalPlatform = pt.arr.aPlatfR ||pt.arr.aPlatfS || null
|
||||||
|
@ -161,7 +161,7 @@ const createParseJourneyLeg = (profile, opt, data) => {
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
tripId: a.jid,
|
tripId: a.jid,
|
||||||
line: lines[parseInt(a.prodX)] || null,
|
line: a.line || null,
|
||||||
direction: a.dirTxt || null,
|
direction: a.dirTxt || null,
|
||||||
when, delay
|
when, delay
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ const ADDRESS = 'A'
|
||||||
const leadingZeros = /^0+/
|
const leadingZeros = /^0+/
|
||||||
|
|
||||||
// todo: what is s.rRefL?
|
// todo: what is s.rRefL?
|
||||||
const parseLocation = (profile, opt, {lines}, l) => {
|
const parseLocation = (profile, opt, _, l) => {
|
||||||
const lid = parse(l.lid, {delimiter: '@'})
|
const lid = parse(l.lid, {delimiter: '@'})
|
||||||
const res = {
|
const res = {
|
||||||
type: 'location',
|
type: 'location',
|
||||||
|
@ -32,16 +32,8 @@ const parseLocation = (profile, opt, {lines}, l) => {
|
||||||
if ('pCls' in l) stop.products = profile.parseProducts(l.pCls)
|
if ('pCls' in l) stop.products = profile.parseProducts(l.pCls)
|
||||||
if ('meta' in l) stop.isMeta = !!l.meta
|
if ('meta' in l) stop.isMeta = !!l.meta
|
||||||
|
|
||||||
if (
|
if (opt.linesOfStops && Array.isArray(l.lines)) {
|
||||||
opt.linesOfStops &&
|
stop.lines = l.lines
|
||||||
Array.isArray(l.pRefL) &&
|
|
||||||
Array.isArray(lines)
|
|
||||||
) {
|
|
||||||
stop.lines = []
|
|
||||||
for (let pRef of l.pRefL) {
|
|
||||||
const line = lines[pRef]
|
|
||||||
if (line) stop.lines.push(line)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return stop
|
return stop
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const createParseMovement = (profile, opt, data) => {
|
const createParseMovement = (profile, opt, data) => {
|
||||||
const {locations, lines, polylines} = data
|
const {locations, polylines} = data
|
||||||
|
|
||||||
// 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?
|
||||||
|
@ -15,7 +15,7 @@ const createParseMovement = (profile, opt, data) => {
|
||||||
const res = {
|
const res = {
|
||||||
direction: m.dirTxt ? profile.parseStationName(m.dirTxt) : null,
|
direction: m.dirTxt ? profile.parseStationName(m.dirTxt) : null,
|
||||||
tripId: m.jid || null,
|
tripId: m.jid || null,
|
||||||
line: lines[m.prodX] || null,
|
line: m.line || null,
|
||||||
location: m.pos ? {
|
location: m.pos ? {
|
||||||
type: 'location',
|
type: 'location',
|
||||||
latitude: m.pos.y / 1000000,
|
latitude: m.pos.y / 1000000,
|
||||||
|
|
Loading…
Add table
Reference in a new issue