mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
add planned*Platform, scheduled* -> planned/prognosed* 💥
This commit is contained in:
parent
2b9280e6c3
commit
938a6f22b9
5 changed files with 42 additions and 26 deletions
|
@ -1,6 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const parseWhen = require('./when')
|
const parseWhen = require('./when')
|
||||||
|
const parsePlatform = require('./platform')
|
||||||
const findRemarks = require('./find-remarks')
|
const findRemarks = require('./find-remarks')
|
||||||
|
|
||||||
const ARRIVAL = 'a'
|
const ARRIVAL = 'a'
|
||||||
|
@ -21,20 +22,14 @@ const createParseArrOrDep = (profile, opt, data, prefix) => {
|
||||||
const res = {
|
const res = {
|
||||||
tripId: d.jid,
|
tripId: d.jid,
|
||||||
stop: d.stbStop.location || null,
|
stop: d.stbStop.location || null,
|
||||||
...parseWhen(profile, d.date, tPlanned, tPrognosed, tzOffset, cancelled)
|
...parseWhen(profile, d.date, tPlanned, tPrognosed, tzOffset, cancelled),
|
||||||
|
...parsePlatform(profile, d.stbStop[prefix + 'PlatfS'], d.stbStop[prefix + 'PlatfR'], cancelled),
|
||||||
// todo: for arrivals, this is the *origin*, not the *direction*
|
// todo: for arrivals, this is the *origin*, not the *direction*
|
||||||
direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null,
|
direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null,
|
||||||
line: d.line || null,
|
line: d.line || null,
|
||||||
remarks: []
|
remarks: []
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: DRY with parseStopover
|
|
||||||
// todo: DRY with parseJourneyLeg
|
|
||||||
const pR = d.stbStop[prefix + 'PlatfR']
|
|
||||||
const pP = d.stbStop[prefix + 'PlatfS']
|
|
||||||
res.platform = pR || pP || null
|
|
||||||
if (pR && pP && pR !== pP) res.scheduledPlatform = pP
|
|
||||||
|
|
||||||
if (cancelled) {
|
if (cancelled) {
|
||||||
res.cancelled = true
|
res.cancelled = true
|
||||||
Object.defineProperty(res, 'canceled', {value: true})
|
Object.defineProperty(res, 'canceled', {value: true})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const parseWhen = require('./when')
|
const parseWhen = require('./when')
|
||||||
|
const parsePlatform = require('./platform')
|
||||||
const findRemarks = require('./find-remarks')
|
const findRemarks = require('./find-remarks')
|
||||||
|
|
||||||
const clone = obj => Object.assign({}, obj)
|
const clone = obj => Object.assign({}, obj)
|
||||||
|
@ -85,15 +86,15 @@ const createParseJourneyLeg = (profile, opt, data) => {
|
||||||
res.line = pt.jny.line || null
|
res.line = pt.jny.line || null
|
||||||
res.direction = pt.jny.dirTxt && profile.parseStationName(pt.jny.dirTxt) || null
|
res.direction = pt.jny.dirTxt && profile.parseStationName(pt.jny.dirTxt) || null
|
||||||
|
|
||||||
res.arrivalPlatform = pt.arr.aPlatfR ||pt.arr.aPlatfS || null
|
const arrPl = parsePlatform(profile, pt.arr.aPlatfS, pt.arr.aPlatfR, pt.arr.aCncl)
|
||||||
if (pt.arr.aPlatfR && pt.arr.aPlatfS && pt.arr.aPlatfR !== pt.arr.aPlatfS) {
|
res.arrivalPlatform = arrPl.platform
|
||||||
res.scheduledArrivalPlatform = pt.arr.aPlatfS
|
res.plannedArrivalPlatform = arrPl.plannedPlatform
|
||||||
}
|
if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform
|
||||||
|
|
||||||
res.departurePlatform = pt.dep.dPlatfR || pt.dep.dPlatfS || null
|
const depPl = parsePlatform(profile, pt.dep.dPlatfS, pt.dep.dPlatfR, pt.dep.dCncl)
|
||||||
if (pt.dep.dPlatfR && pt.dep.dPlatfS && pt.dep.dPlatfR !== pt.dep.dPlatfS) {
|
res.departurePlatform = depPl.platform
|
||||||
res.scheduledDeparturePlatform = pt.dep.dPlatfS
|
res.plannedDeparturePlatform = depPl.plannedPlatform
|
||||||
}
|
if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform
|
||||||
|
|
||||||
if (parseStopovers && pt.jny.stopL) {
|
if (parseStopovers && pt.jny.stopL) {
|
||||||
const parse = profile.parseStopover(profile, opt, data, j.date)
|
const parse = profile.parseStopover(profile, opt, data, j.date)
|
||||||
|
|
20
parse/platform.js
Normal file
20
parse/platform.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const parsePlatform = (profile, platfS, platfR, cncl = false) => {
|
||||||
|
let planned = platfS || null
|
||||||
|
let prognosed = platfR || null
|
||||||
|
|
||||||
|
if (cncl) {
|
||||||
|
return {
|
||||||
|
platform: null,
|
||||||
|
plannedPlatform: planned,
|
||||||
|
prognosedPlatform: prognosed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
platform: prognosed,
|
||||||
|
plannedPlatform: planned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = parsePlatform
|
|
@ -1,34 +1,34 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const parseWhen = require('./when')
|
const parseWhen = require('./when')
|
||||||
|
const parsePlatform = require('./platform')
|
||||||
const findRemarks = require('./find-remarks')
|
const findRemarks = require('./find-remarks')
|
||||||
|
|
||||||
const createParseStopover = (profile, opt, data, date) => {
|
const createParseStopover = (profile, opt, data, date) => {
|
||||||
const parseStopover = (st) => {
|
const parseStopover = (st) => {
|
||||||
const arr = parseWhen(profile, date, st.aTimeS, st.aTimeR, st.aTZOffset, st.aCncl)
|
const arr = parseWhen(profile, date, st.aTimeS, st.aTimeR, st.aTZOffset, st.aCncl)
|
||||||
|
const arrPl = parsePlatform(profile, st.aPlatfS, st.aPlatfR, st.aCncl)
|
||||||
const dep = parseWhen(profile, date, st.dTimeS, st.dTimeR, st.dTZOffset, st.dCncl)
|
const dep = parseWhen(profile, date, st.dTimeS, st.dTimeR, st.dTZOffset, st.dCncl)
|
||||||
|
const depPl = parsePlatform(profile, st.dPlatfS, st.dPlatfR, st.dCncl)
|
||||||
|
|
||||||
const res = {
|
const res = {
|
||||||
stop: st.location || null,
|
stop: st.location || null,
|
||||||
arrival: arr.when,
|
arrival: arr.when,
|
||||||
plannedArrival: arr.plannedWhen,
|
plannedArrival: arr.plannedWhen,
|
||||||
arrivalDelay: arr.delay,
|
arrivalDelay: arr.delay,
|
||||||
arrivalPlatform: st.aPlatfR || st.aPlatfS || null,
|
arrivalPlatform: arrPl.platform,
|
||||||
|
plannedArrivalPlatform: arrPl.plannedPlatform,
|
||||||
departure: dep.when,
|
departure: dep.when,
|
||||||
plannedDeparture: dep.plannedWhen,
|
plannedDeparture: dep.plannedWhen,
|
||||||
departureDelay: dep.delay,
|
departureDelay: dep.delay,
|
||||||
departurePlatform: st.dPlatfR || st.dPlatfS || null
|
departurePlatform: depPl.platform,
|
||||||
|
plannedDeparturePlatform: depPl.plannedPlatform
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen
|
if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen
|
||||||
|
if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform
|
||||||
if (dep.prognosedWhen) res.prognosedDeparture = dep.prognosedWhen
|
if (dep.prognosedWhen) res.prognosedDeparture = dep.prognosedWhen
|
||||||
|
if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform
|
||||||
if (st.aPlatfR && st.aPlatfS && st.aPlatfR !== st.aPlatfS) {
|
|
||||||
res.scheduledArrivalPlatform = st.aPlatfS
|
|
||||||
}
|
|
||||||
if (st.dPlatfR && st.dPlatfS && st.dPlatfR !== st.dPlatfS) {
|
|
||||||
res.scheduledDeparturePlatform = st.dPlatfS
|
|
||||||
}
|
|
||||||
|
|
||||||
// mark stations the train passes without stopping
|
// mark stations the train passes without stopping
|
||||||
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
||||||
|
|
|
@ -17,7 +17,7 @@ const parseWhen = (profile, date, timeS, timeR, tzOffset, cncl = false) => {
|
||||||
return {
|
return {
|
||||||
when: null,
|
when: null,
|
||||||
plannedWhen: planned,
|
plannedWhen: planned,
|
||||||
prognosedWhen: when,
|
prognosedWhen: prognosed,
|
||||||
delay
|
delay
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue