mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
parse lines at a location
This commit is contained in:
parent
831672eeb9
commit
39636f12bf
7 changed files with 31 additions and 11 deletions
2
index.js
2
index.js
|
@ -133,7 +133,7 @@ const createClient = (profile, request = _request) => {
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
if (!d.match || !Array.isArray(d.match.locL)) return []
|
if (!d.match || !Array.isArray(d.match.locL)) return []
|
||||||
const parse = profile.parseLocation
|
const parse = profile.parseLocation
|
||||||
return d.match.locL.map(loc => parse(profile, loc))
|
return d.match.locL.map(loc => parse(profile, loc, d.lines))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,9 +54,6 @@ const request = (profile, data) => {
|
||||||
const d = b.svcResL[0].res
|
const d = b.svcResL[0].res
|
||||||
const c = d.common || {}
|
const c = d.common || {}
|
||||||
|
|
||||||
if (Array.isArray(c.locL)) {
|
|
||||||
d.locations = c.locL.map(loc => profile.parseLocation(profile, loc))
|
|
||||||
}
|
|
||||||
if (Array.isArray(c.remL)) {
|
if (Array.isArray(c.remL)) {
|
||||||
d.remarks = c.remL.map(rem => profile.parseRemark(profile, rem))
|
d.remarks = c.remL.map(rem => profile.parseRemark(profile, rem))
|
||||||
}
|
}
|
||||||
|
@ -67,6 +64,10 @@ const request = (profile, data) => {
|
||||||
const parse = profile.parseLine(profile, d.operators)
|
const parse = profile.parseLine(profile, d.operators)
|
||||||
d.lines = c.prodL.map(parse)
|
d.lines = c.prodL.map(parse)
|
||||||
}
|
}
|
||||||
|
if (Array.isArray(c.locL)) {
|
||||||
|
const parse = loc => profile.parseLocation(profile, loc, d.lines)
|
||||||
|
d.locations = c.locL.map(parse)
|
||||||
|
}
|
||||||
return d
|
return d
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,10 +48,10 @@ const createParseLine = (profile, operators) => {
|
||||||
return parseLineWithMode
|
return parseLineWithMode
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseLocation = (profile, l) => {
|
const parseLocation = (profile, l, lines) => {
|
||||||
// ÖBB has some 'stations' **in austria** with no departures/products,
|
// ÖBB has some 'stations' **in austria** with no departures/products,
|
||||||
// like station entrances, that are actually POIs.
|
// like station entrances, that are actually POIs.
|
||||||
const res = _parseLocation(profile, l)
|
const res = _parseLocation(profile, l, lines)
|
||||||
if (
|
if (
|
||||||
res.type === 'station' &&
|
res.type === 'station' &&
|
||||||
!res.products &&
|
!res.products &&
|
||||||
|
|
|
@ -55,8 +55,8 @@ const createParseLine = (profile, operators) => {
|
||||||
return parseLineWithMode
|
return parseLineWithMode
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseLocation = (profile, l) => {
|
const parseLocation = (profile, l, lines) => {
|
||||||
const res = _parseLocation(profile, l)
|
const res = _parseLocation(profile, l, lines)
|
||||||
|
|
||||||
if (res.type === 'station') {
|
if (res.type === 'station') {
|
||||||
res.name = shorten(res.name)
|
res.name = shorten(res.name)
|
||||||
|
|
|
@ -6,7 +6,9 @@ const ADDRESS = 'A'
|
||||||
|
|
||||||
// todo: what is s.rRefL?
|
// todo: what is s.rRefL?
|
||||||
// todo: is passing in profile necessary?
|
// todo: is passing in profile necessary?
|
||||||
const parseLocation = (profile, l) => {
|
|
||||||
|
// todo: [breaking] change to createParseLocation(profile, lines) => (l) => loc
|
||||||
|
const parseLocation = (profile, l, lines) => {
|
||||||
const res = {type: 'location'}
|
const res = {type: 'location'}
|
||||||
if (l.crd) {
|
if (l.crd) {
|
||||||
res.latitude = l.crd.y / 1000000
|
res.latitude = l.crd.y / 1000000
|
||||||
|
@ -20,7 +22,17 @@ const parseLocation = (profile, l) => {
|
||||||
name: l.name,
|
name: l.name,
|
||||||
location: res
|
location: res
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('pCls' in l) station.products = profile.parseProducts(l.pCls)
|
if ('pCls' in l) station.products = profile.parseProducts(l.pCls)
|
||||||
|
|
||||||
|
if (Array.isArray(l.pRefL) && Array.isArray(lines)) {
|
||||||
|
station.lines = []
|
||||||
|
for (let pRef of l.pRefL) {
|
||||||
|
const line = lines[pRef]
|
||||||
|
if (line) station.lines.push(line)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return station
|
return station
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,10 @@
|
||||||
// todo: what is s.pCls?
|
// todo: what is s.pCls?
|
||||||
// todo: what is s.wt?
|
// todo: what is s.wt?
|
||||||
// todo: what is s.dur?
|
// todo: what is s.dur?
|
||||||
const parseNearby = (profile, n) => {
|
|
||||||
const res = profile.parseLocation(profile, n)
|
// todo: [breaking] change to createParseNearby(profile, lines) => (n) => nearby
|
||||||
|
const parseNearby = (profile, n, lines) => {
|
||||||
|
const res = profile.parseLocation(profile, n, lines)
|
||||||
res.distance = n.dist
|
res.distance = n.dist
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,11 @@ const assertValidStation = (t, s, coordsOptional = false) => {
|
||||||
t.ok(s.location)
|
t.ok(s.location)
|
||||||
assertValidLocation(t, s.location, coordsOptional)
|
assertValidLocation(t, s.location, coordsOptional)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('lines' in s) {
|
||||||
|
t.ok(Array.isArray(s.lines))
|
||||||
|
for (let l of s.lines) assertValidLine(t, l)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const assertValidPoi = (t, p) => {
|
const assertValidPoi = (t, p) => {
|
||||||
|
|
Loading…
Add table
Reference in a new issue