From 97b6a76e75c2b3c877c9b7e1ed0a1b82c1745a83 Mon Sep 17 00:00:00 2001 From: Jannis R Date: Thu, 28 Oct 2021 00:25:58 +0200 Subject: [PATCH] =?UTF-8?q?parseTrip:=20expose=20realtimeDataUpdatedAt=20?= =?UTF-8?q?=E2=9C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 10 ++++++++++ parse/journey-leg.js | 1 - parse/trip.js | 7 ++++++- test/fixtures/oebb-trip.js | 1 + test/fixtures/rejseplanen-trip.js | 1 + test/fixtures/vbb-on-demand-trip.js | 1 + 6 files changed, 19 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e0373a84..d0ad7418 100644 --- a/index.js +++ b/index.js @@ -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 => { diff --git a/parse/journey-leg.js b/parse/journey-leg.js index d64cc6c3..6203f2d2 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -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 diff --git a/parse/trip.js b/parse/trip.js index 45ad030a..fb56f34d 100644 --- a/parse/trip.js +++ b/parse/trip.js @@ -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 } diff --git a/test/fixtures/oebb-trip.js b/test/fixtures/oebb-trip.js index 863f170b..d9d1c4f4 100644 --- a/test/fixtures/oebb-trip.js +++ b/test/fixtures/oebb-trip.js @@ -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, diff --git a/test/fixtures/rejseplanen-trip.js b/test/fixtures/rejseplanen-trip.js index 06db251c..55d9dbb1 100644 --- a/test/fixtures/rejseplanen-trip.js +++ b/test/fixtures/rejseplanen-trip.js @@ -21,6 +21,7 @@ module.exports = { product: 'national-train', operator: { type: 'operator', id: 'dsb', name: 'DSB' }, }, + realtimeDataUpdatedAt: 1634050700, origin: { type: 'stop', diff --git a/test/fixtures/vbb-on-demand-trip.js b/test/fixtures/vbb-on-demand-trip.js index f714fa8d..ad4499b3 100644 --- a/test/fixtures/vbb-on-demand-trip.js +++ b/test/fixtures/vbb-on-demand-trip.js @@ -25,6 +25,7 @@ module.exports = { night: false }, reachable: true, + realtimeDataUpdatedAt: 1635084435, origin: {}, departure: null,