db-vendo-client/parse/movement.js
Jannis R d2257c26ff
rename d.remarks -> d.hints, parseRemark -> parseHint
HAFAS returns notes for journey legs, stopovers and departures.

There are two kinds of notes: "remarks" (in `remL`) and HAFAS
Information Manager (HIM) notes (in `himL`). The former describe
the regular operating situation, e.g. "bicycles allows", whereas
the latter describe cancellations, construction work, etc.

The planned naming scheme for hafas-client:
- hints: notes from `remL` for regular operation
- warnings: notes from `himL` for cancellations, construction, etc
- remarks: both "notes" and "warnings"

This commit prepares the new naming scheme by renaming the
existing parsing logic of `remL` to "hints". Follow-up commits
will add `parseWarning`.
2018-06-07 16:34:50 +02:00

55 lines
1.5 KiB
JavaScript

'use strict'
const createParseMovement = (profile, locations, lines, hints, polylines = []) => {
// 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) => {
const pStopover = profile.parseStopover(profile, locations, lines, hints, m.date)
const res = {
direction: profile.parseStationName(m.dirTxt),
journeyId: m.jid || null,
trip: m.jid && +m.jid.split('|')[1] || null, // todo: this seems brittle
line: lines[m.prodX] || null,
location: m.pos ? {
type: 'location',
latitude: m.pos.y / 1000000,
longitude: m.pos.x / 1000000
} : null,
nextStops: m.stopL.map(pStopover),
frames: []
}
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]
})
}
}
if (m.ani.poly) {
const parse = profile.parsePolyline(locations)
res.polyline = parse(m.ani.poly)
} else if (m.ani.polyG) {
let p = m.ani.polyG.polyXL
p = Array.isArray(p) && polylines[p[0]]
// todo: there can be >1 polyline
const parse = profile.parsePolyline(locations)
res.polyline = p && parse(p) || null
}
}
return res
}
return parseMovement
}
module.exports = createParseMovement