From 352fa2e5646544a0f4d7691781dbdc6692db3399 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Mon, 25 Feb 2019 15:04:25 +0100 Subject: [PATCH] parse more warning fields --- parse/warning.js | 49 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/parse/warning.js b/parse/warning.js index f4162052..e87a72c4 100644 --- a/parse/warning.js +++ b/parse/warning.js @@ -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)