2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2017-11-12 01:23:34 +01:00
|
|
|
const createParseMovement = (profile, locations, lines, remarks) => {
|
|
|
|
const tz = profile.timezone
|
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) => {
|
2017-11-11 23:56:09 +01:00
|
|
|
const parseNextStop = (s) => {
|
|
|
|
const dep = s.dTimeR || s.dTimeS
|
2017-11-12 01:23:34 +01:00
|
|
|
? profile.parseDateTime(tz, m.date, s.dTimeR || s.dTimeS)
|
2017-11-11 23:56:09 +01:00
|
|
|
: null
|
|
|
|
const arr = s.aTimeR || s.aTimeS
|
2017-11-12 01:23:34 +01:00
|
|
|
? profile.parseDateTime(tz, m.date, s.aTimeR || s.aTimeS)
|
2017-11-11 23:56:09 +01:00
|
|
|
: null
|
|
|
|
|
|
|
|
return {
|
|
|
|
station: locations[s.locX],
|
|
|
|
departure: dep ? dep.format() : null,
|
|
|
|
arrival: arr ? arr.format() : null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
const res = {
|
2017-11-11 23:56:09 +01:00
|
|
|
direction: m.dirTxt,
|
2017-11-12 00:36:13 +01:00
|
|
|
line: lines[m.prodX] || null,
|
2017-11-11 23:56:09 +01:00
|
|
|
coordinates: m.pos ? {
|
2017-11-11 22:35:41 +01:00
|
|
|
latitude: m.pos.y / 1000000,
|
|
|
|
longitude: m.pos.x / 1000000
|
2017-11-11 23:56:09 +01:00
|
|
|
} : 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
|