db-vendo-client/parse/hint.js

281 lines
5.4 KiB
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
2018-07-02 18:48:23 +02:00
const trim = require('lodash/trim')
2018-06-01 11:12:54 +02:00
const hints = Object.assign(Object.create(null), {
fb: {
type: 'hint',
2018-06-07 15:41:00 +02:00
code: 'bicycle-conveyance',
summary: 'bicycles conveyed'
2018-06-01 11:12:54 +02:00
},
2018-06-30 18:02:48 +02:00
fr: {
type: 'hint',
code: 'bicycle-conveyance-reservation',
summary: 'bicycles conveyed, subject to reservation'
2018-06-30 18:02:48 +02:00
},
2018-06-07 15:41:00 +02:00
nf: {
type: 'hint',
code: 'no-bicycle-conveyance',
summary: 'bicycles not conveyed'
2018-06-07 15:41:00 +02:00
},
2018-06-01 11:12:54 +02:00
k2: {
type: 'hint',
code: '2nd-class-only',
summary: '2. class only'
2018-06-01 11:12:54 +02:00
},
eh: {
type: 'hint',
code: 'boarding-ramp',
summary: 'vehicle-mounted boarding ramp available'
2018-06-01 11:12:54 +02:00
},
2018-07-02 18:48:23 +02:00
ro: {
type: 'hint',
code: 'wheelchairs-space',
summary: 'space for wheelchairs'
},
oa: {
type: 'hint',
code: 'wheelchairs-space-reservation',
summary: 'space for wheelchairs, subject to reservation'
},
2018-06-01 11:12:54 +02:00
wv: {
type: 'hint',
code: 'wifi',
summary: 'WiFi available'
2018-06-01 11:12:54 +02:00
},
2018-06-30 18:02:48 +02:00
wi: {
type: 'hint',
code: 'wifi',
summary: 'WiFi available'
2018-06-30 18:02:48 +02:00
},
2018-06-01 11:12:54 +02:00
sn: {
type: 'hint',
code: 'snacks',
summary: 'snacks available for purchase'
2018-06-01 11:12:54 +02:00
},
2018-06-30 18:02:48 +02:00
mb: {
type: 'hint',
code: 'snacks',
summary: 'snacks available for purchase'
2018-06-30 18:02:48 +02:00
},
mp: {
type: 'hint',
code: 'snacks',
summary: 'snacks available for purchase at the seat'
2018-06-30 18:02:48 +02:00
},
2018-06-01 11:12:54 +02:00
bf: {
type: 'hint',
code: 'barrier-free',
summary: 'barrier-free'
2018-06-01 11:12:54 +02:00
},
2018-06-07 15:41:00 +02:00
rg: {
type: 'hint',
code: 'barrier-free-vehicle',
summary: 'barrier-free vehicle'
2018-06-07 15:41:00 +02:00
},
2018-06-01 11:12:54 +02:00
bt: {
type: 'hint',
code: 'on-board-bistro',
summary: 'Bordbistro available'
2018-06-01 11:12:54 +02:00
},
br: {
type: 'hint',
code: 'on-board-restaurant',
summary: 'Bordrestaurant available'
2018-06-01 11:12:54 +02:00
},
ki: {
type: 'hint',
code: 'childrens-area',
summary: `children's area available`
2018-06-01 11:12:54 +02:00
},
2018-07-02 18:48:23 +02:00
kk: {
type: 'hint',
code: 'parents-childrens-compartment',
summary: `parent-and-children compartment available`
},
2018-06-30 18:02:48 +02:00
kr: {
type: 'hint',
code: 'kids-service',
summary: 'DB Kids Service available'
2018-06-30 18:02:48 +02:00
},
2018-06-01 11:12:54 +02:00
ls: {
type: 'hint',
code: 'power-sockets',
summary: 'power sockets available'
2018-06-01 11:12:54 +02:00
},
ev: {
type: 'hint',
code: 'replacement-service',
summary: 'replacement service'
2018-06-01 11:12:54 +02:00
},
kl: {
type: 'hint',
code: 'air-conditioned',
summary: 'air-conditioned vehicle'
2018-06-11 21:37:13 +02:00
},
r0: {
type: 'hint',
code: 'upward-escalator',
summary: 'upward escalator'
2018-06-11 21:37:13 +02:00
},
au: {
type: 'hint',
code: 'elevator',
summary: 'elevator available'
},
ck: {
type: 'hint',
code: 'komfort-checkin',
summary: 'Komfort-Checkin available'
},
it: {
type: 'hint',
code: 'ice-sprinter',
summary: 'ICE Sprinter service'
2018-06-30 18:02:48 +02:00
},
rp: {
type: 'hint',
code: 'compulsory-reservation',
summary: 'compulsory seat reservation'
2018-06-30 18:02:48 +02:00
},
2018-07-02 18:48:23 +02:00
rm: {
type: 'hint',
code: 'optional-reservation',
summary: 'optional seat reservation'
},
scl: {
type: 'hint',
code: 'all-2nd-class-seats-reserved',
summary: 'all 2nd class seats reserved'
},
acl: {
type: 'hint',
code: 'all-seats-reserved',
summary: 'all seats reserved'
},
2018-06-30 18:02:48 +02:00
sk: {
type: 'hint',
code: 'oversize-luggage-forbidden',
summary: 'oversize luggage not allowed'
2018-06-30 18:02:48 +02:00
},
hu: {
type: 'hint',
code: 'animals-forbidden',
summary: 'animals not allowed, except guide dogs'
2018-06-30 18:02:48 +02:00
},
ik: {
type: 'hint',
code: 'baby-cot-required',
summary: 'baby cot/child seat required'
2018-06-30 18:02:48 +02:00
},
ee: {
type: 'hint',
code: 'on-board-entertainment',
summary: 'on-board entertainment available'
2018-06-30 18:02:48 +02:00
},
toilet: {
type: 'hint',
code: 'toilet',
summary: 'toilet available'
2018-06-30 18:02:48 +02:00
},
2018-07-02 18:48:23 +02:00
oc: {
type: 'hint',
code: 'wheelchair-accessible-toilet',
summary: 'wheelchair-accessible toilet available'
},
2018-06-30 18:02:48 +02:00
iz: {
type: 'hint',
code: 'intercity-2',
summary: 'Intercity 2'
2018-06-01 11:12:54 +02:00
}
})
const codesByIcon = Object.assign(Object.create(null), {
cancel: 'cancelled'
})
2017-11-12 01:23:34 +01:00
// todo: is passing in profile necessary?
const parseHint = (profile, h, icons) => {
2018-06-01 11:12:54 +02:00
// todo: C
2018-07-02 18:48:23 +02:00
// todo:
// { type: 'Q',
// code: '',
// icoX: 11,
// txtN:
// 'RE 3132: Berlin Zoologischer Garten - Brandenburg Hbf: Information. A railway carriage is missing',
// sIdx: 4 }
2018-06-11 18:41:53 +02:00
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
2018-06-07 15:41:00 +02:00
2018-06-11 19:50:44 +02:00
if (h.type === 'M') {
return {
type: 'status',
summary: h.txtS && h.txtS.trim() || '',
code,
2018-06-11 19:50:44 +02:00
text
}
}
2018-06-07 15:41:00 +02:00
// todo: find sth more reliable than this
2018-06-11 18:41:53 +02:00
if (h.type === 'P' && text.toLowerCase() === 'journey cancelled') {
2018-06-07 15:41:00 +02:00
return {
type: 'status',
code: 'journey-cancelled',
2018-06-11 18:41:53 +02:00
text
// todo: `h.sIdx`
2018-06-07 15:41:00 +02:00
}
}
2018-06-11 18:41:53 +02:00
if (h.type === 'U' && text.toLowerCase() === 'stop cancelled') {
return {
type: 'status',
2018-07-02 18:48:23 +02:00
code: 'stop-cancelled', // todo: change to stopover-cancelled
text
}
}
if (h.type === 'U' && trim(text.toLowerCase(), ' ()') === 'additional stop') {
return {
type: 'status',
code: 'additional-stopover',
2018-06-11 18:41:53 +02:00
text
}
}
if (h.type === 'G' && text.toLowerCase() === 'platform change') {
2018-06-11 18:41:53 +02:00
return {
type: 'status',
code: 'changed platform',
2018-06-11 18:41:53 +02:00
text
}
}
if (h.type === 'L') {
2018-06-01 11:12:54 +02:00
return {
type: 'status',
code: 'alternative-trip',
2018-06-11 18:41:53 +02:00
text,
tripId: h.jid
2018-06-01 11:12:54 +02:00
}
}
if (h.type === 'A') {
const hint = hints[h.code && h.code.trim().toLowerCase()]
if (hint) {
return Object.assign({text: h.txtN}, hint)
}
return null
2018-06-07 15:41:00 +02:00
}
if (h.type === 'D' || h.type === 'U' || h.type === 'R' || h.type === 'N') {
2018-06-01 11:12:54 +02:00
// todo: how can we identify the individual types?
2018-07-02 18:48:23 +02:00
// todo: does `D` mean "disturbance"?
2018-06-01 11:12:54 +02:00
return {
type: 'status',
code,
2018-06-11 18:41:53 +02:00
text
2018-06-01 11:12:54 +02:00
}
}
2018-07-02 18:48:23 +02:00
2018-06-01 11:12:54 +02:00
return null
2017-11-11 22:35:41 +01:00
}
module.exports = parseHint