parseTrip: expose realtimeDataUpdatedAt

This commit is contained in:
Jannis R 2021-10-28 00:25:58 +02:00
parent 2f5c8f4619
commit 97b6a76e75
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
6 changed files with 19 additions and 2 deletions

View file

@ -74,6 +74,7 @@ const createClient = (profile, userAgent, opt = {}) => {
const req = profile.formatStationBoardReq({profile, opt}, station, type)
// todo [breaking]: return object with realtimeDataUpdatedAt
return profile.request({profile, opt}, userAgent, req)
.then(({res, common}) => {
if (!Array.isArray(res.jnyL)) return []
@ -227,6 +228,7 @@ const createClient = (profile, userAgent, opt = {}) => {
earlierRef: res.outCtxScrB,
laterRef: res.outCtxScrF,
journeys,
// todo [breaking]: rename to realtimeDataUpdatedAt
realtimeDataFrom: res.planrtTS ? parseInt(res.planrtTS) : null,
}
})
@ -260,6 +262,7 @@ const createClient = (profile, userAgent, opt = {}) => {
const ctx = {profile, opt, common, res}
return {
// todo [breaking]: rename to realtimeDataUpdatedAt
realtimeDataFrom: res.planrtTS ? parseInt(res.planrtTS) : null,
...profile.parseJourney(ctx, res.outConL[0])
}
@ -367,6 +370,7 @@ const createClient = (profile, userAgent, opt = {}) => {
if (!Array.isArray(res.outConL)) return []
const ctx = {profile, opt, common, res}
// todo [breaking]: return object with realtimeDataUpdatedAt
return res.outConL
.map(rawJourney => profile.parseJourney(ctx, rawJourney))
.map((journey) => {
@ -489,6 +493,7 @@ const createClient = (profile, userAgent, opt = {}) => {
const req = profile.formatTripReq({profile, opt}, id, lineName)
// todo [breaking]: return object with realtimeDataUpdatedAt
return profile.request({profile, opt}, userAgent, req)
.then(({common, res}) => {
const ctx = {profile, opt, common, res}
@ -565,6 +570,7 @@ const createClient = (profile, userAgent, opt = {}) => {
}
req.jnyFltrL = [...req.jnyFltrL, ...opt.additionalFilters]
// todo [breaking]: return object with realtimeDataUpdatedAt
return profile.request({profile, opt}, userAgent, {
cfg: {polyEnc: 'GPA'},
meth: 'JourneyMatch',
@ -600,6 +606,7 @@ const createClient = (profile, userAgent, opt = {}) => {
const req = profile.formatRadarReq({profile, opt}, north, west, south, east)
// todo [breaking]: return object with realtimeDataUpdatedAt
return profile.request({profile, opt}, userAgent, req)
.then(({res, common}) => {
if (!Array.isArray(res.jnyL)) return []
@ -650,6 +657,7 @@ const createClient = (profile, userAgent, opt = {}) => {
byDuration[i].stations.push(loc)
}
}
// todo [breaking]: return object with realtimeDataUpdatedAt
return byDuration
})
}
@ -686,6 +694,7 @@ const createClient = (profile, userAgent, opt = {}) => {
res, common,
} = await profile.request({profile, opt}, userAgent, req)
// todo [breaking]: return object with realtimeDataUpdatedAt
const ctx = {profile, opt, common, res}
return (res.msgL || [])
.map(w => profile.parseWarning(ctx, w))
@ -701,6 +710,7 @@ const createClient = (profile, userAgent, opt = {}) => {
res, common,
} = await profile.request({profile, opt}, userAgent, req)
// todo [breaking]: return object with realtimeDataUpdatedAt
if (!Array.isArray(res.lineL)) return []
const ctx = {profile, opt, common, res}
return res.lineL.map(l => {

View file

@ -49,7 +49,6 @@ const applyRemarks = (leg, refs) => {
// todo: what is `sty: 'UNDEF'`?
// todo: pt.prodL
// todo: pt.parJnyL (list of coupled trains)
// todo: pt.planrtTS
const parseJourneyLeg = (ctx, pt, date) => { // pt = raw leg
const {profile, opt} = ctx

View file

@ -5,7 +5,7 @@ const maxBy = require('lodash/maxBy')
const last = require('lodash/last')
const parseTrip = (ctx, t) => { // t = raw trip
const {profile} = ctx
const {profile, res} = ctx
// pretend the trip is a leg in a journey
const fakeLeg = {
@ -29,6 +29,11 @@ const parseTrip = (ctx, t) => { // t = raw trip
delete trip.tripId
// todo [breaking]: delete trip.reachable
if (res.planrtTS) {
// todo [breaking]: remove here
trip.realtimeDataUpdatedAt = parseInt(res.planrtTS)
}
return trip
}

View file

@ -100,6 +100,7 @@ module.exports = {
id: '2|#VN#0#ST#1591790769#PI#0#ZI#398470#TA#0#DA#110620#1S#8100353#1T#1633#LS#8100002#LT#1948#PU#81#RT#1#CA#RJ#ZE#742#ZB#RJ 742 #',
origin: wienFlughafen,
destination: salzburgHbf,
realtimeDataUpdatedAt: 1591881826,
arrival: '2020-06-11T19:48:00+02:00',
plannedArrival: '2020-06-11T19:48:00+02:00',
arrivalDelay: null,

View file

@ -21,6 +21,7 @@ module.exports = {
product: 'national-train',
operator: { type: 'operator', id: 'dsb', name: 'DSB' },
},
realtimeDataUpdatedAt: 1634050700,
origin: {
type: 'stop',

View file

@ -25,6 +25,7 @@ module.exports = {
night: false
},
reachable: true,
realtimeDataUpdatedAt: 1635084435,
origin: {},
departure: null,