2017-11-11 22:35:41 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-06-26 11:47:43 +02:00
|
|
|
const createParseMovement = (profile, opt, data) => {
|
2018-07-16 11:35:47 +02:00
|
|
|
const {locations, lines, polylines} = data
|
2018-06-13 18:59:56 +02:00
|
|
|
|
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?
|
|
|
|
const parseMovement = (m) => {
|
2018-06-13 19:59:44 +02:00
|
|
|
const pStopover = profile.parseStopover(profile, opt, data, m.date)
|
2017-11-11 23:56:09 +01:00
|
|
|
|
2017-11-11 22:35:41 +01:00
|
|
|
const res = {
|
2017-11-20 17:37:08 +01:00
|
|
|
direction: profile.parseStationName(m.dirTxt),
|
2018-06-26 14:57:02 +02:00
|
|
|
tripId: m.jid || null,
|
2017-12-16 02:28:09 +01:00
|
|
|
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,
|
2017-12-11 19:25:29 +01:00
|
|
|
location: m.pos ? {
|
|
|
|
type: 'location',
|
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,
|
2018-03-17 16:41:57 +01:00
|
|
|
nextStops: m.stopL.map(pStopover),
|
2017-11-11 23:56:09 +01:00
|
|
|
frames: []
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 19:39:28 +02:00
|
|
|
if (m.ani) {
|
|
|
|
if (Array.isArray(m.ani.mSec)) {
|
|
|
|
for (let i = 0; i < m.ani.mSec.length; i++) {
|
|
|
|
res.frames.push({
|
|
|
|
origin: locations[m.ani.fLocX[i]] || null,
|
|
|
|
destination: locations[m.ani.tLocX[i]] || null,
|
|
|
|
t: m.ani.mSec[i]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-16 21:07:43 +02:00
|
|
|
if (m.ani.poly) {
|
2018-06-13 19:59:44 +02:00
|
|
|
const parse = profile.parsePolyline(profile, opt, data)
|
2018-05-16 21:07:43 +02:00
|
|
|
res.polyline = parse(m.ani.poly)
|
|
|
|
} else if (m.ani.polyG) {
|
|
|
|
let p = m.ani.polyG.polyXL
|
|
|
|
p = Array.isArray(p) && polylines[p[0]]
|
2018-05-15 19:39:28 +02:00
|
|
|
// todo: there can be >1 polyline
|
2018-06-13 19:59:44 +02:00
|
|
|
const parse = profile.parsePolyline(profile, opt, data)
|
2018-05-16 21:07:43 +02:00
|
|
|
res.polyline = p && parse(p) || null
|
2017-11-11 22:35:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res
|
|
|
|
}
|
|
|
|
return parseMovement
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = createParseMovement
|