mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19: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'
|
||||
|
||||
const parseWhen = require('./when')
|
||||
const parsePlatform = require('./platform')
|
||||
const findRemarks = require('./find-remarks')
|
||||
|
||||
const ARRIVAL = 'a'
|
||||
|
@ -21,20 +22,14 @@ const createParseArrOrDep = (profile, opt, data, prefix) => {
|
|||
const res = {
|
||||
tripId: d.jid,
|
||||
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*
|
||||
direction: prefix === DEPARTURE && d.dirTxt && profile.parseStationName(d.dirTxt) || null,
|
||||
line: d.line || null,
|
||||
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) {
|
||||
res.cancelled = true
|
||||
Object.defineProperty(res, 'canceled', {value: true})
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
'use strict'
|
||||
|
||||
const parseWhen = require('./when')
|
||||
const parsePlatform = require('./platform')
|
||||
const findRemarks = require('./find-remarks')
|
||||
|
||||
const clone = obj => Object.assign({}, obj)
|
||||
|
@ -85,15 +86,15 @@ const createParseJourneyLeg = (profile, opt, data) => {
|
|||
res.line = pt.jny.line || null
|
||||
res.direction = pt.jny.dirTxt && profile.parseStationName(pt.jny.dirTxt) || null
|
||||
|
||||
res.arrivalPlatform = pt.arr.aPlatfR ||pt.arr.aPlatfS || null
|
||||
if (pt.arr.aPlatfR && pt.arr.aPlatfS && pt.arr.aPlatfR !== pt.arr.aPlatfS) {
|
||||
res.scheduledArrivalPlatform = pt.arr.aPlatfS
|
||||
}
|
||||
const arrPl = parsePlatform(profile, pt.arr.aPlatfS, pt.arr.aPlatfR, pt.arr.aCncl)
|
||||
res.arrivalPlatform = arrPl.platform
|
||||
res.plannedArrivalPlatform = arrPl.plannedPlatform
|
||||
if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform
|
||||
|
||||
res.departurePlatform = pt.dep.dPlatfR || pt.dep.dPlatfS || null
|
||||
if (pt.dep.dPlatfR && pt.dep.dPlatfS && pt.dep.dPlatfR !== pt.dep.dPlatfS) {
|
||||
res.scheduledDeparturePlatform = pt.dep.dPlatfS
|
||||
}
|
||||
const depPl = parsePlatform(profile, pt.dep.dPlatfS, pt.dep.dPlatfR, pt.dep.dCncl)
|
||||
res.departurePlatform = depPl.platform
|
||||
res.plannedDeparturePlatform = depPl.plannedPlatform
|
||||
if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform
|
||||
|
||||
if (parseStopovers && pt.jny.stopL) {
|
||||
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'
|
||||
|
||||
const parseWhen = require('./when')
|
||||
const parsePlatform = require('./platform')
|
||||
const findRemarks = require('./find-remarks')
|
||||
|
||||
const createParseStopover = (profile, opt, data, date) => {
|
||||
const parseStopover = (st) => {
|
||||
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 depPl = parsePlatform(profile, st.dPlatfS, st.dPlatfR, st.dCncl)
|
||||
|
||||
const res = {
|
||||
stop: st.location || null,
|
||||
arrival: arr.when,
|
||||
plannedArrival: arr.plannedWhen,
|
||||
arrivalDelay: arr.delay,
|
||||
arrivalPlatform: st.aPlatfR || st.aPlatfS || null,
|
||||
arrivalPlatform: arrPl.platform,
|
||||
plannedArrivalPlatform: arrPl.plannedPlatform,
|
||||
departure: dep.when,
|
||||
plannedDeparture: dep.plannedWhen,
|
||||
departureDelay: dep.delay,
|
||||
departurePlatform: st.dPlatfR || st.dPlatfS || null
|
||||
departurePlatform: depPl.platform,
|
||||
plannedDeparturePlatform: depPl.plannedPlatform
|
||||
}
|
||||
|
||||
if (arr.prognosedWhen) res.prognosedArrival = arr.prognosedWhen
|
||||
if (arrPl.prognosedPlatform) res.prognosedArrivalPlatform = arrPl.prognosedPlatform
|
||||
if (dep.prognosedWhen) res.prognosedDeparture = dep.prognosedWhen
|
||||
|
||||
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
|
||||
}
|
||||
if (depPl.prognosedPlatform) res.prognosedDeparturePlatform = depPl.prognosedPlatform
|
||||
|
||||
// mark stations the train passes without stopping
|
||||
if(st.dInS === false && st.aOutS === false) res.passBy = true
|
||||
|
|
|
@ -17,7 +17,7 @@ const parseWhen = (profile, date, timeS, timeR, tzOffset, cncl = false) => {
|
|||
return {
|
||||
when: null,
|
||||
plannedWhen: planned,
|
||||
prognosedWhen: when,
|
||||
prognosedWhen: prognosed,
|
||||
delay
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue