From 60656b0119c4a53b2ac581f6f14ad3deb25d0617 Mon Sep 17 00:00:00 2001 From: Traines Date: Sat, 11 Jan 2025 18:39:32 +0000 Subject: [PATCH] db: create fake walking leg for intra-station transfer --- parse/journey-leg.js | 4 ++-- parse/journey.js | 21 ++++++++++++++++++ test/fixtures/db-refresh-journey.js | 33 +++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/parse/journey-leg.js b/parse/journey-leg.js index 6d199901..d0bb39c9 100644 --- a/parse/journey-leg.js +++ b/parse/journey-leg.js @@ -48,7 +48,7 @@ const parseJourneyLeg = (ctx, pt, date, fallbackLocations) => { // pt = raw leg } const type = pt.verkehrsmittel?.typ || pt.typ; - if (type == 'WALK' || type == 'FUSSWEG' || type == 'TRANSFER') { // TODO invert default? + if (type == 'WALK' || type == 'FUSSWEG' || type == 'TRANSFER') { if (res.origin?.id == res.destination?.id) { res.arrival = res.departure; res.plannedArrival = res.plannedDeparture; @@ -60,7 +60,7 @@ const parseJourneyLeg = (ctx, pt, date, fallbackLocations) => { // pt = raw leg if (type == 'TRANSFER') { res.transfer = true; } - // TODO res.transfer, res.checkin + // TODO res.checkin } else { res.tripId = pt.journeyId || pt.zuglaufId; res.line = profile.parseLine(ctx, pt) || null; diff --git a/parse/journey.js b/parse/journey.js index f3ff79a1..eb25f177 100644 --- a/parse/journey.js +++ b/parse/journey.js @@ -1,5 +1,22 @@ import {parseRemarks} from './remarks.js'; +const createFakeWalkingLeg = (prevLeg, leg) => { + const fakeWalkingLeg = { + origin: prevLeg.destination, + destination: leg.origin, + }; + fakeWalkingLeg.departure = prevLeg.arrival; + fakeWalkingLeg.plannedDeparture = prevLeg.plannedArrival; + fakeWalkingLeg.departureDelay = prevLeg.delay; + fakeWalkingLeg.arrival = fakeWalkingLeg.departure; + fakeWalkingLeg.plannedArrival = fakeWalkingLeg.plannedDeparture; + fakeWalkingLeg.arrivalDelay = fakeWalkingLeg.departureDelay; + fakeWalkingLeg.public = true; + fakeWalkingLeg.walking = true; + fakeWalkingLeg.distance = null; + return fakeWalkingLeg; +} + const parseLocationsFromCtxRecon = (ctx, j) => { return (j.ctxRecon || j.kontext) .split('$') @@ -19,6 +36,10 @@ const parseJourney = (ctx, jj) => { // j = raw journey const legs = []; for (const l of j.verbindungsAbschnitte) { const leg = profile.parseJourneyLeg(ctx, l, null, fallbackLocations); + if (legs.length > 0 && !legs[legs.length-1].walking && !leg.walking) { + const fakeWalkingLeg = createFakeWalkingLeg(legs[legs.length - 1], leg); + legs.push(fakeWalkingLeg); + } legs.push(leg); } diff --git a/test/fixtures/db-refresh-journey.js b/test/fixtures/db-refresh-journey.js index 88bcac7d..63e38d49 100644 --- a/test/fixtures/db-refresh-journey.js +++ b/test/fixtures/db-refresh-journey.js @@ -86,6 +86,39 @@ const dbJourney = { ], loadFactor: 'low-to-medium', }, + { + origin: { + type: 'station', + id: '8000080', + name: 'Dortmund Hbf', + location: { + type: 'location', + id: '8000080', + latitude: 51.517899, + longitude: 7.459294, + }, + }, + destination: { + type: 'station', + id: '8000080', + name: 'Dortmund Hbf', + location: { + type: 'location', + id: '8000080', + latitude: 51.517899, + longitude: 7.459294, + }, + }, + departure: '2024-12-18T05:21:00+01:00', + plannedDeparture: '2024-12-18T05:21:00+01:00', + departureDelay: null, + arrival: '2024-12-18T05:21:00+01:00', + plannedArrival: '2024-12-18T05:21:00+01:00', + arrivalDelay: null, + public: true, + walking: true, + distance: null, + }, { origin: { type: 'station',