parse hint & warning types using icons

[ci skip]
This commit is contained in:
Jannis R 2018-06-30 18:04:44 +02:00
parent 5f03c8e878
commit d9b7df693a
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 61 additions and 56 deletions

View file

@ -83,11 +83,13 @@ const request = (profile, opt, data) => {
d.hints = [] d.hints = []
if (opt.remarks && Array.isArray(c.remL)) { if (opt.remarks && Array.isArray(c.remL)) {
d.hints = c.remL.map(hint => profile.parseHint(profile, hint)) const icons = opt.remarks && c.icoL || []
d.hints = c.remL.map(hint => profile.parseHint(profile, hint, icons))
} }
d.warnings = [] d.warnings = []
if (opt.remarks && Array.isArray(c.himL)) { if (opt.remarks && Array.isArray(c.himL)) {
d.warnings = c.himL.map(w => profile.parseWarning(profile, w)) const icons = opt.remarks && c.icoL || []
d.warnings = c.himL.map(w => profile.parseWarning(profile, w, icons))
} }
if (Array.isArray(c.opL)) { if (Array.isArray(c.opL)) {
d.operators = c.opL.map(op => profile.parseOperator(profile, op)) d.operators = c.opL.map(op => profile.parseOperator(profile, op))

View file

@ -4,173 +4,172 @@ const hints = Object.assign(Object.create(null), {
fb: { fb: {
type: 'hint', type: 'hint',
code: 'bicycle-conveyance', code: 'bicycle-conveyance',
text: 'bicycles conveyed' summary: 'bicycles conveyed'
}, },
fr: { fr: {
type: 'hint', type: 'hint',
code: 'bicycle-conveyance-reservation', code: 'bicycle-conveyance-reservation',
text: 'bicycles conveyed, subject to reservation' summary: 'bicycles conveyed, subject to reservation'
}, },
nf: { nf: {
type: 'hint', type: 'hint',
code: 'no-bicycle-conveyance', code: 'no-bicycle-conveyance',
text: 'bicycles not conveyed' summary: 'bicycles not conveyed'
}, },
k2: { k2: {
type: 'hint', type: 'hint',
code: '2nd-class-only', code: '2nd-class-only',
text: '2. class only' summary: '2. class only'
}, },
eh: { eh: {
type: 'hint', type: 'hint',
code: 'boarding-ramp', code: 'boarding-ramp',
text: 'vehicle-mounted boarding ramp available' summary: 'vehicle-mounted boarding ramp available'
}, },
wv: { wv: {
type: 'hint', type: 'hint',
code: 'wifi', code: 'wifi',
text: 'WiFi available' summary: 'WiFi available'
}, },
wi: { wi: {
type: 'hint', type: 'hint',
code: 'wifi', code: 'wifi',
text: 'WiFi available' summary: 'WiFi available'
}, },
sn: { sn: {
type: 'hint', type: 'hint',
code: 'snacks', code: 'snacks',
text: 'snacks available for purchase' summary: 'snacks available for purchase'
}, },
mb: { mb: {
type: 'hint', type: 'hint',
code: 'snacks', code: 'snacks',
text: 'snacks available for purchase' summary: 'snacks available for purchase'
}, },
mp: { mp: {
type: 'hint', type: 'hint',
code: 'snacks', code: 'snacks',
text: 'snacks available for purchase at the seat' summary: 'snacks available for purchase at the seat'
}, },
bf: { bf: {
type: 'hint', type: 'hint',
code: 'barrier-free', code: 'barrier-free',
text: 'barrier-free' summary: 'barrier-free'
}, },
rg: { rg: {
type: 'hint', type: 'hint',
code: 'barrier-free-vehicle', code: 'barrier-free-vehicle',
text: 'barrier-free vehicle' summary: 'barrier-free vehicle'
}, },
bt: { bt: {
type: 'hint', type: 'hint',
code: 'on-board-bistro', code: 'on-board-bistro',
text: 'Bordbistro available' summary: 'Bordbistro available'
}, },
br: { br: {
type: 'hint', type: 'hint',
code: 'on-board-restaurant', code: 'on-board-restaurant',
text: 'Bordrestaurant available' summary: 'Bordrestaurant available'
}, },
ki: { ki: {
type: 'hint', type: 'hint',
code: 'childrens-area', code: 'childrens-area',
text: `children's area available` summary: `children's area available`
}, },
kr: { kr: {
type: 'hint', type: 'hint',
code: 'kids-service', code: 'kids-service',
text: 'DB Kids Service available' summary: 'DB Kids Service available'
}, },
ls: { ls: {
type: 'hint', type: 'hint',
code: 'power-sockets', code: 'power-sockets',
text: 'power sockets available' summary: 'power sockets available'
}, },
ev: { ev: {
type: 'hint', type: 'hint',
code: 'replacement-service', code: 'replacement-service',
text: 'replacement service' summary: 'replacement service'
}, },
kl: { kl: {
type: 'hint', type: 'hint',
code: 'air-conditioned', code: 'air-conditioned',
text: 'air-conditioned vehicle' summary: 'air-conditioned vehicle'
}, },
r0: { r0: {
type: 'hint', type: 'hint',
code: 'upward-escalator', code: 'upward-escalator',
text: 'upward escalator' summary: 'upward escalator'
}, },
au: { au: {
type: 'hint', type: 'hint',
code: 'elevator', code: 'elevator',
text: 'elevator available' summary: 'elevator available'
}, },
ck: { ck: {
type: 'hint', type: 'hint',
code: 'komfort-checkin', code: 'komfort-checkin',
text: 'Komfort-Checkin available' summary: 'Komfort-Checkin available'
}, },
it: { it: {
type: 'hint', type: 'hint',
code: 'ice-sprinter', code: 'ice-sprinter',
text: 'ICE Sprinter service' summary: 'ICE Sprinter service'
}, },
rp: { rp: {
type: 'hint', type: 'hint',
code: 'compulsory-reservation', code: 'compulsory-reservation',
text: 'compulsory seat reservation' summary: 'compulsory seat reservation'
}, },
sk: { sk: {
type: 'hint', type: 'hint',
code: 'oversize-luggage-forbidden', code: 'oversize-luggage-forbidden',
text: 'oversize luggage not allowed' summary: 'oversize luggage not allowed'
}, },
hu: { hu: {
type: 'hint', type: 'hint',
code: 'animals-forbidden', code: 'animals-forbidden',
text: 'animals not allowed, except guide dogs' summary: 'animals not allowed, except guide dogs'
}, },
ik: { ik: {
type: 'hint', type: 'hint',
code: 'baby-cot-required', code: 'baby-cot-required',
text: 'baby cot/child seat required' summary: 'baby cot/child seat required'
}, },
ee: { ee: {
type: 'hint', type: 'hint',
code: 'on-board-entertainment', code: 'on-board-entertainment',
text: 'on-board entertainment available' summary: 'on-board entertainment available'
}, },
toilet: { toilet: {
type: 'hint', type: 'hint',
code: 'toilet', code: 'toilet',
text: 'toilet available' summary: 'toilet available'
}, },
iz: { iz: {
type: 'hint', type: 'hint',
code: 'intercity-2', code: 'intercity-2',
text: 'Intercity 2' summary: 'Intercity 2'
} }
}) })
const codesByIcon = Object.assign(Object.create(null), {
cancel: 'cancelled'
})
// todo: is passing in profile necessary? // todo: is passing in profile necessary?
const parseHint = (profile, h) => { const parseHint = (profile, h, icons) => {
// todo: C // todo: C
const text = h.txtN && h.txtN.trim() || '' const text = h.txtN && h.txtN.trim() || ''
const icon = 'number' === typeof h.icoX && icons[h.icoX] || null
const code = h.code || (icon && icon.res && codesByIcon[icon.res]) || null
if (h.type === 'M') { if (h.type === 'M') {
return { return {
type: 'status', type: 'status',
code: h.code || null,
summary: h.txtS && h.txtS.trim() || '', summary: h.txtS && h.txtS.trim() || '',
text code,
}
}
if (h.type === 'D') {
return {
type: 'status',
code: h.code || null,
text text
} }
} }
@ -191,21 +190,13 @@ const parseHint = (profile, h) => {
text text
} }
} }
// todo: if (h.type === 'G' && text.toLowerCase() === 'platform change') {
// {
// "type": "U",
// "code": "",
// "icoX": 3,
// "txtN": "entrance and exit not possible"
// }
if (h.type === 'U') {
return { return {
type: 'status', type: 'status',
code: h.code || null, code: 'changed platform',
text text
} }
} }
if (h.type === 'L') { if (h.type === 'L') {
return { return {
type: 'status', type: 'status',
@ -215,13 +206,18 @@ const parseHint = (profile, h) => {
} }
} }
if (h.type === 'A') { if (h.type === 'A') {
return hints[h.code && h.code.trim().toLowerCase()] || null const hint = hints[h.code && h.code.trim().toLowerCase()]
if (hint) {
return Object.assign({text: h.txtN}, hint)
} }
if (h.type === 'R') { return null
}
if (h.type === 'D' || h.type === 'U' || h.type === 'R' || h.type === 'N') {
// todo: how can we identify the individual types? // todo: how can we identify the individual types?
return { return {
type: 'status', type: 'status',
code: h.code, code,
text text
} }
} }

View file

@ -4,8 +4,12 @@ const brToNewline = require('br2nl')
const parseDateTime = require('./date-time') const parseDateTime = require('./date-time')
const typesByIcon = Object.assign(Object.create(null), {
HimWarn: 'status'
})
// todo: is passing in profile necessary? // todo: is passing in profile necessary?
const parseWarning = (profile, w) => { const parseWarning = (profile, w, icons) => {
// todo: hid, act, pub, lead, tckr, icoX, fLocX, tLocX, prod, comp, // todo: hid, act, pub, lead, tckr, icoX, fLocX, tLocX, prod, comp,
// todo: cat (1, 2), pubChL // todo: cat (1, 2), pubChL
// pubChL: // pubChL:
@ -20,8 +24,11 @@ const parseWarning = (profile, w) => {
// tDate: '20180713', // tDate: '20180713',
// tTime: '030000' } ] // tTime: '030000' } ]
const icon = 'number' === typeof h.icoX && icons[h.icoX] || null
const type = icon && icon.res && typesByIcon[icon.res] || 'warning'
return { return {
type: 'warning', type,
summary: brToNewline(w.head), summary: brToNewline(w.head),
text: brToNewline(w.text), text: brToNewline(w.text),
priority: w.prio, priority: w.prio,