mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
parse more warning fields
This commit is contained in:
parent
35e44d4c92
commit
352fa2e564
1 changed files with 43 additions and 6 deletions
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const brToNewline = require('@derhuerst/br2nl')
|
||||
const omit = require('lodash/omit')
|
||||
|
||||
const parseDateTime = require('./date-time')
|
||||
|
||||
|
@ -8,11 +9,28 @@ const typesByIcon = Object.assign(Object.create(null), {
|
|||
HimWarn: 'status'
|
||||
})
|
||||
|
||||
// todo: is passing in profile necessary?
|
||||
const parseMsgEdge = (profile, data) => (e) => {
|
||||
const res = omit(e, ['icoX', 'fLocX', 'tLocX'])
|
||||
const icons = data.icoL || []
|
||||
res.icon = 'number' === typeof e.icoX && icons[e.icoX] || null
|
||||
res.fromLoc = 'number' === typeof e.fLocX && data.locations[e.fLocX] || null
|
||||
res.toLoc = 'number' === typeof e.tLocX && data.locations[e.tLocX] || null
|
||||
return res
|
||||
}
|
||||
const parseMsgEvent = (profile, data) => (e) => {
|
||||
return {
|
||||
fromLoc: 'number' === typeof e.fLocX && data.locations[e.fLocX] || null,
|
||||
toLoc: 'number' === typeof e.tLocX && data.locations[e.tLocX] || null,
|
||||
start: parseDateTime(profile, e.fDate, e.fTime, null),
|
||||
end: parseDateTime(profile, e.tDate, e.tTime, null),
|
||||
sections: e.sectionNums || [] // todo: parse
|
||||
}
|
||||
}
|
||||
|
||||
const parseWarning = (profile, w, data) => {
|
||||
const icons = data.icoL || []
|
||||
// todo: hid, act, pub, lead, tckr, icoX, fLocX, tLocX, prod, comp,
|
||||
// todo: cat (1, 2), pubChL
|
||||
// todo: act, pub, lead, tckr, fLocX, tLocX, prod, comp,
|
||||
// todo: cat (1, 2), pubChL, rRefL, impactL
|
||||
// pubChL:
|
||||
// [ { name: 'timetable',
|
||||
// fDate: '20180606',
|
||||
|
@ -24,6 +42,11 @@ const parseWarning = (profile, w, data) => {
|
|||
// fTime: '073000',
|
||||
// tDate: '20180713',
|
||||
// tTime: '030000' } ]
|
||||
// { name: '1',
|
||||
// fDate: '20190219',
|
||||
// fTime: '000000',
|
||||
// tDate: '20190225',
|
||||
// tTime: '120000' }
|
||||
|
||||
const icon = 'number' === typeof w.icoX && icons[w.icoX] || null
|
||||
const type = icon && icon.type && typesByIcon[icon.type] || 'warning'
|
||||
|
@ -31,12 +54,26 @@ const parseWarning = (profile, w, data) => {
|
|||
const res = {
|
||||
id: w.hid || null,
|
||||
type,
|
||||
summary: w.head ? brToNewline(w.head) : null, // todo: decode HTML entities
|
||||
text: w.text ? brToNewline(w.text) : null, // todo: decode HTML entities
|
||||
summary: w.head ? brToNewline(w.head) : null, // todo: decode HTML entities?
|
||||
text: w.text ? brToNewline(w.text) : null, // todo: decode HTML entities?
|
||||
icon,
|
||||
priority: w.prio,
|
||||
category: w.cat || null // todo: parse to sth meaningful
|
||||
}
|
||||
if ('prod' in w) res.products = profile.parseProducts(61442)
|
||||
if ('prod' in w) res.products = profile.parseProducts(w.prod)
|
||||
|
||||
if (w.edgeRefL && data.himMsgEdgeL) {
|
||||
res.edges = w.edgeRefL
|
||||
.map(i => data.himMsgEdgeL[i])
|
||||
.filter(e => !!e)
|
||||
.map(parseMsgEdge(profile, data))
|
||||
}
|
||||
if (w.eventRefL && data.himMsgEventL) {
|
||||
res.events = w.eventRefL
|
||||
.map(i => data.himMsgEventL[i])
|
||||
.filter(e => !!e)
|
||||
.map(parseMsgEvent(profile, data))
|
||||
}
|
||||
|
||||
if (w.sDate && w.sTime) res.validFrom = parseDateTime(profile, w.sDate, w.sTime, null)
|
||||
if (w.eDate && w.eTime) res.validUntil = parseDateTime(profile, w.eDate, w.eTime, null)
|
||||
|
|
Loading…
Add table
Reference in a new issue