mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 23:29:35 +02:00
parse: default to null
This commit is contained in:
parent
fb43a4e43b
commit
73d083f418
4 changed files with 9 additions and 10 deletions
|
@ -15,10 +15,10 @@ const createParseDeparture = (timezone, stations, lines, remarks) => {
|
||||||
const when = parseDateTime(timezone, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
const when = parseDateTime(timezone, d.date, d.stbStop.dTimeR || d.stbStop.dTimeS)
|
||||||
const res = {
|
const res = {
|
||||||
ref: d.jid,
|
ref: d.jid,
|
||||||
station: stations[parseInt(d.stbStop.locX)], // todo: default to null
|
station: stations[parseInt(d.stbStop.locX)] || null,
|
||||||
when: when.format(),
|
when: when.format(),
|
||||||
direction: d.dirTxt,
|
direction: d.dirTxt,
|
||||||
line: lines[parseInt(d.prodX)], // todo: default to null
|
line: lines[parseInt(d.prodX)] || null,
|
||||||
remarks: d.remL ? d.remL.map(findRemark) : [],
|
remarks: d.remL ? d.remL.map(findRemark) : [],
|
||||||
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
trip: +d.jid.split('|')[1] // todo: this seems brittle
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey
|
||||||
const dep = parseDateTime(tz, j.date, pt.dep.dTimeR || pt.dep.dTimeS)
|
const dep = parseDateTime(tz, j.date, pt.dep.dTimeR || pt.dep.dTimeS)
|
||||||
const arr = parseDateTime(tz, j.date, pt.arr.aTimeR || pt.arr.aTimeS)
|
const arr = parseDateTime(tz, j.date, pt.arr.aTimeR || pt.arr.aTimeS)
|
||||||
const res = {
|
const res = {
|
||||||
// todo: what about null?
|
origin: clone(stations[parseInt(pt.dep.locX)]) || null,
|
||||||
origin: clone(stations[parseInt(pt.dep.locX)]),
|
|
||||||
destination: clone(stations[parseInt(pt.arr.locX)]),
|
destination: clone(stations[parseInt(pt.arr.locX)]),
|
||||||
departure: dep.format(),
|
departure: dep.format(),
|
||||||
arrival: arr.format()
|
arrival: arr.format()
|
||||||
|
@ -55,7 +54,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey
|
||||||
res.mode = 'walking'
|
res.mode = 'walking'
|
||||||
} else if (pt.type === 'JNY') {
|
} else if (pt.type === 'JNY') {
|
||||||
res.id = pt.jny.jid
|
res.id = pt.jny.jid
|
||||||
res.line = lines[parseInt(pt.jny.prodX)] // todo: default null
|
res.line = lines[parseInt(pt.jny.prodX)] || null
|
||||||
res.direction = pt.jny.dirTxt // todo: parse this
|
res.direction = pt.jny.dirTxt // todo: parse this
|
||||||
|
|
||||||
if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS
|
if (pt.dep.dPlatfS) res.departurePlatform = pt.dep.dPlatfS
|
||||||
|
@ -71,7 +70,7 @@ const createParsePart = (tz, stations, lines, remarks, j) => { // j = journey
|
||||||
|
|
||||||
if (pt.jny.freq && pt.jny.freq.jnyL) {
|
if (pt.jny.freq && pt.jny.freq.jnyL) {
|
||||||
const parseAlternative = (a) => ({
|
const parseAlternative = (a) => ({
|
||||||
line: lines[parseInt(a.prodX)], // todo: default null
|
line: lines[parseInt(a.prodX)] || null,
|
||||||
when: parseDateTime(tz, j.date, a.stopL[0].dTimeS).format() // todo: realtime
|
when: parseDateTime(tz, j.date, a.stopL[0].dTimeS).format() // todo: realtime
|
||||||
})
|
})
|
||||||
res.alternatives = pt.jny.freq.jnyL
|
res.alternatives = pt.jny.freq.jnyL
|
||||||
|
|
|
@ -28,7 +28,7 @@ const createParseMovement = (tz, locations, lines, remarks) => {
|
||||||
|
|
||||||
const res = {
|
const res = {
|
||||||
direction: m.dirTxt,
|
direction: m.dirTxt,
|
||||||
line: lines[m.prodX], // default to null
|
line: lines[m.prodX] || null,
|
||||||
coordinates: m.pos ? {
|
coordinates: m.pos ? {
|
||||||
latitude: m.pos.y / 1000000,
|
latitude: m.pos.y / 1000000,
|
||||||
longitude: m.pos.x / 1000000
|
longitude: m.pos.x / 1000000
|
||||||
|
@ -40,8 +40,8 @@ const createParseMovement = (tz, locations, lines, remarks) => {
|
||||||
if (m.ani && Array.isArray(m.ani.mSec)) {
|
if (m.ani && Array.isArray(m.ani.mSec)) {
|
||||||
for (let i = 0; i < m.ani.mSec.length; i++) {
|
for (let i = 0; i < m.ani.mSec.length; i++) {
|
||||||
res.frames.push({
|
res.frames.push({
|
||||||
origin: locations[m.ani.fLocX[i]], // todo: default to null
|
origin: locations[m.ani.fLocX[i]] || null,
|
||||||
destination: locations[m.ani.tLocX[i]], // todo: default to null
|
destination: locations[m.ani.tLocX[i]] || null,
|
||||||
t: m.ani.mSec[i]
|
t: m.ani.mSec[i]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ const parseDateTime = require('./date-time')
|
||||||
const createParseStopover = (tz, stations, lines, remarks, connection) => {
|
const createParseStopover = (tz, stations, lines, remarks, connection) => {
|
||||||
const parseStopover = (st) => {
|
const parseStopover = (st) => {
|
||||||
const res = {
|
const res = {
|
||||||
station: stations[parseInt(st.locX)] // default to null
|
station: stations[parseInt(st.locX)] || null
|
||||||
}
|
}
|
||||||
if (st.aTimeR || st.aTimeS) {
|
if (st.aTimeR || st.aTimeS) {
|
||||||
const arr = parseDateTime(tz, connection.date, st.aTimeR || st.aTimeS)
|
const arr = parseDateTime(tz, connection.date, st.aTimeR || st.aTimeS)
|
||||||
|
|
Loading…
Add table
Reference in a new issue