mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parseLocation: parse foreign stop IDs from I
hints
`rRefL` seems to be used by older HAFAS endpoints, e.g. `ver: 1.11`. see also #5, #90, #131
This commit is contained in:
parent
b9d5c85a54
commit
2a241375db
4 changed files with 49 additions and 2 deletions
|
@ -8,7 +8,7 @@ const parseCommonData = (_ctx) => {
|
|||
const matches = findInTree(res, [
|
||||
'**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX',
|
||||
'**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX',
|
||||
'**.remX', '**.himX', '**.polyG.polyXL'
|
||||
'**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL',
|
||||
]);
|
||||
|
||||
const common = {}
|
||||
|
@ -77,11 +77,16 @@ const parseCommonData = (_ctx) => {
|
|||
}
|
||||
|
||||
common.hints = []
|
||||
if (opt.remarks && Array.isArray(c.remL)) {
|
||||
if (Array.isArray(c.remL)) {
|
||||
common.hints = c.remL.map(hint => profile.parseHint(ctx, hint))
|
||||
matches['**.remX'].forEach(([idx, parents]) => {
|
||||
if ('number' === typeof idx) parents[0].hint = common.hints[idx]
|
||||
})
|
||||
matches['**.rRefL'].forEach(([idxs, parents]) => {
|
||||
parents[0].hints = idxs
|
||||
.filter(idx => !!common.hints[idx])
|
||||
.map(idx => common.hints[idx])
|
||||
})
|
||||
}
|
||||
common.warnings = []
|
||||
if (opt.remarks && Array.isArray(c.himL)) {
|
||||
|
|
|
@ -4,6 +4,15 @@ const codesByIcon = Object.assign(Object.create(null), {
|
|||
cancel: 'cancelled'
|
||||
})
|
||||
|
||||
const linkTypesByCode = Object.assign(Object.create(null), {
|
||||
// IFOPT-based DHID
|
||||
// https://wiki.openstreetmap.org/wiki/DE:Key:ref:IFOPT
|
||||
// https://trid.trb.org/view/1435440
|
||||
IF: 'stop-dhid',
|
||||
// todo: `{type: 'I',code: 'TD',icoX: 1,txtN: '8010224'}`
|
||||
// todo: `{type: 'I',code: 'TE',icoX: 1,txtN: '8024001'}`
|
||||
})
|
||||
|
||||
// todo: pass in tag list from hint reference, e.g.:
|
||||
// "tagL": [
|
||||
// "RES_JNY_H3" // H3 = level 3 heading? shown on overview
|
||||
|
@ -15,6 +24,15 @@ const codesByIcon = Object.assign(Object.create(null), {
|
|||
const parseHint = (ctx, h) => {
|
||||
// todo: C
|
||||
|
||||
if (h.type === 'I' && h.code && h.txtN) {
|
||||
if (h.code in linkTypesByCode) {
|
||||
return {type: linkTypesByCode[h.code], text: h.txtN}
|
||||
}
|
||||
if (h.code === 'TW' && h.txtN[0] === '#') {
|
||||
return {type: 'foreign-id', text: h.txtN.slice(1)}
|
||||
}
|
||||
}
|
||||
|
||||
const text = h.txtN && h.txtN.trim() || ''
|
||||
const icon = h.icon || null
|
||||
const code = h.code || (icon && icon.type && codesByIcon[icon.type]) || null
|
||||
|
|
|
@ -38,6 +38,27 @@ const parseLocation = (ctx, l) => {
|
|||
stop.lines = l.lines
|
||||
}
|
||||
|
||||
const hints = l.hints || []
|
||||
const byType = type => hints.find(h => h.type === type)
|
||||
|
||||
const dhid = (byType('stop-dhid') || {}).text
|
||||
if (dhid) {
|
||||
if (!stop.ids) stop.ids = {}
|
||||
stop.ids.dhid = dhid
|
||||
}
|
||||
|
||||
const otherIds = hints
|
||||
.filter(h => h.type === 'foreign-id')
|
||||
.filter(h => 'string' === typeof h.text && h.text.includes(':'))
|
||||
.map(({text}) => {
|
||||
const i = text.indexOf(':')
|
||||
return [text.slice(0, i), text.slice(i + 1)]
|
||||
})
|
||||
if (otherIds.length > 0) {
|
||||
if (!stop.ids) stop.ids = {}
|
||||
for (const [src, id] of otherIds) stop.ids[src] = id
|
||||
}
|
||||
|
||||
return stop
|
||||
}
|
||||
|
||||
|
|
3
test/fixtures/insa-stop.js
vendored
3
test/fixtures/insa-stop.js
vendored
|
@ -3,6 +3,9 @@
|
|||
module.exports = {
|
||||
type: 'stop',
|
||||
id: '7341',
|
||||
ids: {
|
||||
dhid: 'de:15003:7341',
|
||||
},
|
||||
name: 'Magdeburg, S-Bahnhof SKET Industriepark',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
|
Loading…
Add table
Reference in a new issue