From e9d95447c9d24dc4afef129f9c22902731818684 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Fri, 12 Aug 2016 03:41:10 +0200 Subject: [PATCH] parse movements, 0.6.0 --- package.json | 2 +- parse.js | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 66df9992..7ac140c4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hafas-client", "description": "JavaScript client for HAFAS mobile APIs.", - "version": "0.5.1", + "version": "0.6.0", "main": "index.js", "files": ["index.js", "parse.js", "stringify.js"], "author": "Jannis R ", diff --git a/parse.js b/parse.js index c38737e7..c907da3e 100644 --- a/parse.js +++ b/parse.js @@ -148,6 +148,39 @@ const nearby = (n) => { return result } +// todo: what is m.dirGeo? maybe the speed? +// todo: what is m.stopL? +// todo: what is m.proc? wut? +// todo: what is m.pos? +// todo: what is m.ani.dirGeo[n]? maybe the speed? +// todo: what is m.ani.proc[n]? wut? +// todo: how does m.ani.poly work? +// tz = timezone, l = locations, p = products, r = remarks +const movement = (tz, l, p, r) => (m) => { + const result = { + direction: m.dirTxt + , product: p[m.prodX] + , latitude: m.pos ? m.pos.y / 1000000 : null + , longitude: m.pos ? m.pos.x / 1000000 : null + , nextStops: m.stopL.map((s) => ({ + station: l[s.locX] + , departure: s.dTimeR || s.dTimeS ? + new Date(dateTime(tz, m.date, s.dTimeR || s.dTimeS)) : null + , arrival: s.aTimeR || s.aTimeS ? + new Date(dateTime(tz, m.date, s.aTimeR || s.aTimeS)) : null + })) + , frames: [] + } + if (m.ani && Array.isArray(m.ani.mSec)) + for (let i = 0; i < m.ani.mSec.length; i++) + result.frames.push({ + from: l[m.ani.fLocX[i]], + to: l[m.ani.tLocX[i]], + t: m.ani.mSec[i] + }) + return result +} + module.exports = { @@ -155,5 +188,6 @@ module.exports = { location, product, remark, agency, stop, applyRemark, part, route, departure, - nearby + nearby, + movement }