db-vendo-client/parse/movement.js

68 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-11-11 22:35:41 +01:00
'use strict'
2017-11-12 01:23:34 +01:00
const createParseMovement = (profile, locations, lines, remarks) => {
2017-11-11 22:35:41 +01:00
// 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?
const parseMovement = (m) => {
const parseNextStop = (s) => {
const dep = s.dTimeR || s.dTimeS
? profile.parseDateTime(profile, m.date, s.dTimeR || s.dTimeS)
: null
const arr = s.aTimeR || s.aTimeS
? profile.parseDateTime(profile, m.date, s.aTimeR || s.aTimeS)
: null
2017-12-18 11:57:48 +01:00
const res = {
station: locations[s.locX],
2017-12-11 19:40:46 +01:00
departure: dep ? dep.toISO() : null,
arrival: arr ? arr.toISO() : null
}
2017-12-18 11:57:48 +01:00
if (m.dTimeR && m.dTimeS) {
const plannedDep = profile.parseDateTime(profile, m.date, s.dTimeS)
res.departureDelay = Math.round((dep - plannedDep) / 1000)
} else res.departureDelay = null
if (m.aTimeR && m.aTimeS) {
const plannedArr = profile.parseDateTime(profile, m.date, s.aTimeS)
res.arrivalDelay = Math.round((arr - plannedArr) / 1000)
} else res.arrivalDelay = null
return res
}
2017-11-11 22:35:41 +01:00
const res = {
2017-11-20 17:37:08 +01:00
direction: profile.parseStationName(m.dirTxt),
trip: m.jid && +m.jid.split('|')[1] || null, // todo: this seems brittle
2017-11-12 00:36:13 +01:00
line: lines[m.prodX] || null,
location: m.pos ? {
type: 'location',
2017-11-11 22:35:41 +01:00
latitude: m.pos.y / 1000000,
longitude: m.pos.x / 1000000
} : null,
nextStops: m.stopL.map(parseNextStop),
frames: []
2017-11-11 22:35:41 +01:00
}
if (m.ani && Array.isArray(m.ani.mSec)) {
for (let i = 0; i < m.ani.mSec.length; i++) {
res.frames.push({
2017-11-12 00:36:13 +01:00
origin: locations[m.ani.fLocX[i]] || null,
destination: locations[m.ani.tLocX[i]] || null,
2017-11-11 22:35:41 +01:00
t: m.ani.mSec[i]
})
}
}
return res
}
return parseMovement
}
module.exports = createParseMovement