mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parseLocation: parse fare zone, transit authority & more foreign stop IDs
closes #131 see also #5, #90
This commit is contained in:
parent
2a241375db
commit
3ea9380218
4 changed files with 44 additions and 3 deletions
|
@ -1,5 +1,6 @@
|
|||
'use strict'
|
||||
|
||||
const omit = require('lodash/omit')
|
||||
const findInTree = require('../lib/find-in-tree')
|
||||
|
||||
const parseCommonData = (_ctx) => {
|
||||
|
@ -9,6 +10,7 @@ const parseCommonData = (_ctx) => {
|
|||
'**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX',
|
||||
'**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX',
|
||||
'**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL',
|
||||
'**.msgL',
|
||||
]);
|
||||
|
||||
const common = {}
|
||||
|
@ -89,13 +91,29 @@ const parseCommonData = (_ctx) => {
|
|||
})
|
||||
}
|
||||
common.warnings = []
|
||||
if (opt.remarks && Array.isArray(c.himL)) {
|
||||
if (Array.isArray(c.himL)) {
|
||||
common.warnings = c.himL.map(w => profile.parseWarning(ctx, w))
|
||||
matches['**.himX'].forEach(([idx, parents]) => {
|
||||
if ('number' === typeof idx) parents[0].warning = common.warnings[idx]
|
||||
})
|
||||
}
|
||||
|
||||
// resolve .msgL[] references
|
||||
const parseRemarkRef = (ref) => {
|
||||
if (ref.type === 'REM' && ref.hint) {
|
||||
return omit(ref, ['type', 'remX'])
|
||||
}
|
||||
if (ref.type === 'HIM' && ref.warning) {
|
||||
return omit(ref, ['type', 'himX'])
|
||||
}
|
||||
return null
|
||||
}
|
||||
matches['**.msgL'].forEach(([refs, parents]) => {
|
||||
parents[0].remarkRefs = refs
|
||||
.map(parseRemarkRef)
|
||||
.filter(ref => ref !== null)
|
||||
})
|
||||
|
||||
common.polylines = []
|
||||
if (opt.polylines && Array.isArray(c.polyL)) {
|
||||
common.polylines = c.polyL.map(p => profile.parsePolyline(ctx, p))
|
||||
|
|
|
@ -5,10 +5,12 @@ const codesByIcon = Object.assign(Object.create(null), {
|
|||
})
|
||||
|
||||
const linkTypesByCode = Object.assign(Object.create(null), {
|
||||
BB: 'stop-website',
|
||||
// IFOPT-based DHID
|
||||
// https://wiki.openstreetmap.org/wiki/DE:Key:ref:IFOPT
|
||||
// https://trid.trb.org/view/1435440
|
||||
IF: 'stop-dhid',
|
||||
OZ: 'transit-authority',
|
||||
// todo: `{type: 'I',code: 'TD',icoX: 1,txtN: '8010224'}`
|
||||
// todo: `{type: 'I',code: 'TE',icoX: 1,txtN: '8024001'}`
|
||||
})
|
||||
|
@ -28,6 +30,9 @@ const parseHint = (ctx, h) => {
|
|||
if (h.code in linkTypesByCode) {
|
||||
return {type: linkTypesByCode[h.code], text: h.txtN}
|
||||
}
|
||||
if (h.code === 'TW' && h.txtN[0] === '$') {
|
||||
return {type: 'local-fare-zone', text: h.txtN.slice(1)}
|
||||
}
|
||||
if (h.code === 'TW' && h.txtN[0] === '#') {
|
||||
return {type: 'foreign-id', text: h.txtN.slice(1)}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,22 @@ const parseLocation = (ctx, l) => {
|
|||
stop.lines = l.lines
|
||||
}
|
||||
|
||||
const hints = l.hints || []
|
||||
const locHints = (l.remarkRefs || [])
|
||||
.filter(ref => !!ref.hint && Array.isArray(ref.tagL))
|
||||
.filter(({tagL}) => (
|
||||
tagL.includes('RES_LOC') ||
|
||||
tagL.find(t => t.slice(0, 8) === 'RES_LOC_') // e.g. `RES_LOC_H3`
|
||||
))
|
||||
.map(ref => ref.hint)
|
||||
const hints = [
|
||||
...(l.hints || []),
|
||||
...locHints,
|
||||
]
|
||||
const byType = type => hints.find(h => h.type === type)
|
||||
|
||||
const transitAuthority = (byType('transit-authority') || {}).text
|
||||
if (transitAuthority) stop.transitAuthority = transitAuthority
|
||||
|
||||
const dhid = (byType('stop-dhid') || {}).text
|
||||
if (dhid) {
|
||||
if (!stop.ids) stop.ids = {}
|
||||
|
|
7
test/fixtures/db-stop.js
vendored
7
test/fixtures/db-stop.js
vendored
|
@ -3,6 +3,10 @@
|
|||
module.exports = {
|
||||
type: 'stop',
|
||||
id: '8011155',
|
||||
ids: {
|
||||
dhid: 'de:11000:900100003',
|
||||
VBB: '900100003'
|
||||
},
|
||||
name: 'Berlin Alexanderplatz',
|
||||
location: {
|
||||
type: 'location',
|
||||
|
@ -21,5 +25,6 @@ module.exports = {
|
|||
subway: true,
|
||||
tram: true,
|
||||
taxi: false
|
||||
}
|
||||
},
|
||||
transitAuthority: 'VBB',
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue