Skip to content

Commit

Permalink
parseLocation: parse fare zone, transit authority & more foreign stop…
Browse files Browse the repository at this point in the history
… IDs

closes #131
see also #5, #90
  • Loading branch information
derhuerst committed Mar 8, 2020
1 parent 2a24137 commit 3ea9380
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
20 changes: 19 additions & 1 deletion parse/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

const omit = require('lodash/omit')
const findInTree = require('../lib/find-in-tree')

const parseCommonData = (_ctx) => {
Expand All @@ -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 = {}
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions parse/hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`
})
Expand All @@ -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)}
}
Expand Down
15 changes: 14 additions & 1 deletion parse/location.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
7 changes: 6 additions & 1 deletion test/fixtures/db-stop.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module.exports = {
type: 'stop',
id: '8011155',
ids: {
dhid: 'de:11000:900100003',
VBB: '900100003'
},
name: 'Berlin Alexanderplatz',
location: {
type: 'location',
Expand All @@ -21,5 +25,6 @@ module.exports = {
subway: true,
tram: true,
taxi: false
}
},
transitAuthority: 'VBB',
}

0 comments on commit 3ea9380

Please sign in to comment.