DB: parse gridL[].itemL[].remL[] 🐛

This commit is contained in:
Jannis R 2021-01-26 21:04:10 +01:00
parent 0f284e09b8
commit c260e34f20
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 35 additions and 88 deletions

View file

@ -45,9 +45,21 @@ const slices = (n, arr) => {
const parseGrid = (g) => { const parseGrid = (g) => {
// todo: g.type, e.g. `S` // 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 { return {
title: g.title, 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 (parsed.type !== 'stop' && parsed.type !== 'station') return parsed
if (Array.isArray(l.gridL)) { if (Array.isArray(l.gridL)) {
const resolveCell = cell => 'hint' in cell ? cell.hint.text : cell
const resolveCells = grid => ({ const resolveCells = grid => ({
...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 let grids = l.gridL

View file

@ -7,7 +7,7 @@ const findInTree = createFindInTree([
'**.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', '**.rRefL', '**.remX', '**.himX', '**.polyG.polyXL', '**.rRefL',
'**.msgL', '**.msgL', '**.remL',
]) ])
const parseCommonData = (_ctx) => { const parseCommonData = (_ctx) => {
@ -55,6 +55,12 @@ const parseCommonData = (_ctx) => {
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['**.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]) => { matches['**.rRefL'].forEach(([idxs, parents]) => {
parents[0].hints = idxs parents[0].hints = idxs
.filter(idx => !!common.hints[idx]) .filter(idx => !!common.hints[idx])

View file

@ -15247,142 +15247,72 @@
{ {
"col": 0, "col": 0,
"row": 0, "row": 0,
"msgL": [ "remL": [23]
{
"type": "REM",
"remX": 23
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 0, "row": 0,
"msgL": [ "remL": [24]
{
"type": "REM",
"remX": 24
}
]
}, },
{ {
"col": 0, "col": 0,
"row": 1, "row": 1,
"msgL": [ "remL": [25]
{
"type": "REM",
"remX": 25
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 1, "row": 1,
"msgL": [ "remL": [24]
{
"type": "REM",
"remX": 24
}
]
}, },
{ {
"col": 0, "col": 0,
"row": 2, "row": 2,
"msgL": [ "remL": [26]
{
"type": "REM",
"remX": 26
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 2, "row": 2,
"msgL": [ "remL": [24]
{
"type": "REM",
"remX": 24
}
]
}, },
{ {
"col": 0, "col": 0,
"row": 3, "row": 3,
"msgL": [ "remL": [27]
{
"type": "REM",
"remX": 27
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 3, "row": 3,
"msgL": [ "remL": [24]
{
"type": "REM",
"remX": 24
}
]
}, },
{ {
"col": 0, "col": 0,
"row": 4, "row": 4,
"msgL": [ "remL": [28]
{
"type": "REM",
"remX": 28
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 4, "row": 4,
"msgL": [ "remL": [24]
{
"type": "REM",
"remX": 24
}
]
}, },
{ {
"col": 0, "col": 0,
"row": 5, "row": 5,
"msgL": [ "remL": [29]
{
"type": "REM",
"remX": 29
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 5, "row": 5,
"msgL": [ "remL": [30]
{
"type": "REM",
"remX": 30
}
]
}, },
{ {
"col": 0, "col": 0,
"row": 6, "row": 6,
"msgL": [ "remL": [31]
{
"type": "REM",
"remX": 31
}
]
}, },
{ {
"col": 1, "col": 1,
"row": 6, "row": 6,
"msgL": [ "remL": [30]
{
"type": "REM",
"remX": 30
}
]
} }
], ],
"type": "OH", "type": "OH",