mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19: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, [
|
const matches = findInTree(res, [
|
||||||
'**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX',
|
'**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX',
|
||||||
'**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX',
|
'**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX',
|
||||||
'**.remX', '**.himX', '**.polyG.polyXL'
|
'**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const common = {}
|
const common = {}
|
||||||
|
@ -77,11 +77,16 @@ const parseCommonData = (_ctx) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
common.hints = []
|
common.hints = []
|
||||||
if (opt.remarks && Array.isArray(c.remL)) {
|
if (Array.isArray(c.remL)) {
|
||||||
common.hints = c.remL.map(hint => profile.parseHint(ctx, hint))
|
common.hints = c.remL.map(hint => profile.parseHint(ctx, hint))
|
||||||
matches['**.remX'].forEach(([idx, parents]) => {
|
matches['**.remX'].forEach(([idx, parents]) => {
|
||||||
if ('number' === typeof idx) parents[0].hint = common.hints[idx]
|
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 = []
|
common.warnings = []
|
||||||
if (opt.remarks && Array.isArray(c.himL)) {
|
if (opt.remarks && Array.isArray(c.himL)) {
|
||||||
|
|
|
@ -4,6 +4,15 @@ const codesByIcon = Object.assign(Object.create(null), {
|
||||||
cancel: 'cancelled'
|
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.:
|
// todo: pass in tag list from hint reference, e.g.:
|
||||||
// "tagL": [
|
// "tagL": [
|
||||||
// "RES_JNY_H3" // H3 = level 3 heading? shown on overview
|
// "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) => {
|
const parseHint = (ctx, h) => {
|
||||||
// todo: C
|
// 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 text = h.txtN && h.txtN.trim() || ''
|
||||||
const icon = h.icon || null
|
const icon = h.icon || null
|
||||||
const code = h.code || (icon && icon.type && codesByIcon[icon.type]) || null
|
const code = h.code || (icon && icon.type && codesByIcon[icon.type]) || null
|
||||||
|
|
|
@ -38,6 +38,27 @@ const parseLocation = (ctx, l) => {
|
||||||
stop.lines = l.lines
|
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
|
return stop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
3
test/fixtures/insa-stop.js
vendored
3
test/fixtures/insa-stop.js
vendored
|
@ -3,6 +3,9 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
type: 'stop',
|
type: 'stop',
|
||||||
id: '7341',
|
id: '7341',
|
||||||
|
ids: {
|
||||||
|
dhid: 'de:15003:7341',
|
||||||
|
},
|
||||||
name: 'Magdeburg, S-Bahnhof SKET Industriepark',
|
name: 'Magdeburg, S-Bahnhof SKET Industriepark',
|
||||||
location: {
|
location: {
|
||||||
type: 'location',
|
type: 'location',
|
||||||
|
|
Loading…
Add table
Reference in a new issue