mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
DB: parse gridL[].itemL[].remL[] 🐛
This commit is contained in:
parent
0f284e09b8
commit
c260e34f20
3 changed files with 35 additions and 88 deletions
|
@ -45,9 +45,21 @@ const slices = (n, arr) => {
|
|||
|
||||
const parseGrid = (g) => {
|
||||
// todo: g.type, e.g. `S`
|
||||
// todo: respect `g.itemL[].(col|row)`?
|
||||
|
||||
// todo
|
||||
// parseGrid is being called by parseLocWithDetails, which is being called as
|
||||
// profile.parseLocation by profile.parseCommon, parseCommon hasn't finished
|
||||
// resolving all references yet, so we have to resolve them manually here.
|
||||
// This would be fixed if we resolve references on-the-fly or in a recursive/
|
||||
// iterative process.
|
||||
return {
|
||||
title: g.title,
|
||||
rows: slices(g.nCols, g.itemL.map(item => item.msgL[0]))
|
||||
rows: slices(g.nCols, g.itemL.map(item => (
|
||||
Array.isArray(item.hints) && item.hints[0] ||
|
||||
Array.isArray(item.remarkRefs) && item.remarkRefs[0] && item.remarkRefs[0].hint ||
|
||||
{}
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,10 +105,9 @@ const parseLocWithDetails = ({parsed, common}, l) => {
|
|||
if (parsed.type !== 'stop' && parsed.type !== 'station') return parsed
|
||||
|
||||
if (Array.isArray(l.gridL)) {
|
||||
const resolveCell = cell => 'hint' in cell ? cell.hint.text : cell
|
||||
const resolveCells = grid => ({
|
||||
...grid,
|
||||
rows: grid.rows.map(row => row.map(resolveCell))
|
||||
rows: grid.rows.map(row => row.map(cell => cell && cell.text)),
|
||||
})
|
||||
|
||||
let grids = l.gridL
|
||||
|
|
|
@ -7,7 +7,7 @@ const findInTree = createFindInTree([
|
|||
'**.oprX', '**.icoX', '**.prodX', '**.pRefL', '**.locX',
|
||||
'**.ani.fLocX', '**.ani.tLocX', '**.fLocX', '**.tLocX',
|
||||
'**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL',
|
||||
'**.msgL',
|
||||
'**.msgL', '**.remL',
|
||||
])
|
||||
|
||||
const parseCommonData = (_ctx) => {
|
||||
|
@ -55,6 +55,12 @@ const parseCommonData = (_ctx) => {
|
|||
matches['**.remX'].forEach(([idx, parents]) => {
|
||||
if ('number' === typeof idx) parents[0].hint = common.hints[idx]
|
||||
})
|
||||
matches['**.remL'].forEach(([idxs, parents]) => {
|
||||
if (!Array.isArray(idxs)) return;
|
||||
parents[0].hints = idxs
|
||||
.filter(idx => !!common.hints[idx])
|
||||
.map(idx => common.hints[idx])
|
||||
})
|
||||
matches['**.rRefL'].forEach(([idxs, parents]) => {
|
||||
parents[0].hints = idxs
|
||||
.filter(idx => !!common.hints[idx])
|
||||
|
|
98
test/fixtures/db-stop.json
vendored
98
test/fixtures/db-stop.json
vendored
|
@ -15247,142 +15247,72 @@
|
|||
{
|
||||
"col": 0,
|
||||
"row": 0,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 23
|
||||
}
|
||||
]
|
||||
"remL": [23]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 0,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 24
|
||||
}
|
||||
]
|
||||
"remL": [24]
|
||||
},
|
||||
{
|
||||
"col": 0,
|
||||
"row": 1,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 25
|
||||
}
|
||||
]
|
||||
"remL": [25]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 1,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 24
|
||||
}
|
||||
]
|
||||
"remL": [24]
|
||||
},
|
||||
{
|
||||
"col": 0,
|
||||
"row": 2,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 26
|
||||
}
|
||||
]
|
||||
"remL": [26]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 2,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 24
|
||||
}
|
||||
]
|
||||
"remL": [24]
|
||||
},
|
||||
{
|
||||
"col": 0,
|
||||
"row": 3,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 27
|
||||
}
|
||||
]
|
||||
"remL": [27]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 3,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 24
|
||||
}
|
||||
]
|
||||
"remL": [24]
|
||||
},
|
||||
{
|
||||
"col": 0,
|
||||
"row": 4,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 28
|
||||
}
|
||||
]
|
||||
"remL": [28]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 4,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 24
|
||||
}
|
||||
]
|
||||
"remL": [24]
|
||||
},
|
||||
{
|
||||
"col": 0,
|
||||
"row": 5,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 29
|
||||
}
|
||||
]
|
||||
"remL": [29]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 5,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 30
|
||||
}
|
||||
]
|
||||
"remL": [30]
|
||||
},
|
||||
{
|
||||
"col": 0,
|
||||
"row": 6,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 31
|
||||
}
|
||||
]
|
||||
"remL": [31]
|
||||
},
|
||||
{
|
||||
"col": 1,
|
||||
"row": 6,
|
||||
"msgL": [
|
||||
{
|
||||
"type": "REM",
|
||||
"remX": 30
|
||||
}
|
||||
]
|
||||
"remL": [30]
|
||||
}
|
||||
],
|
||||
"type": "OH",
|
||||
|
|
Loading…
Add table
Reference in a new issue