db: create fake walking leg for intra-station transfer

This commit is contained in:
Traines 2025-01-11 18:39:32 +00:00
parent 232893f2dc
commit 60656b0119
3 changed files with 56 additions and 2 deletions

View file

@ -48,7 +48,7 @@ const parseJourneyLeg = (ctx, pt, date, fallbackLocations) => { // pt = raw leg
} }
const type = pt.verkehrsmittel?.typ || pt.typ; 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) { if (res.origin?.id == res.destination?.id) {
res.arrival = res.departure; res.arrival = res.departure;
res.plannedArrival = res.plannedDeparture; res.plannedArrival = res.plannedDeparture;
@ -60,7 +60,7 @@ const parseJourneyLeg = (ctx, pt, date, fallbackLocations) => { // pt = raw leg
if (type == 'TRANSFER') { if (type == 'TRANSFER') {
res.transfer = true; res.transfer = true;
} }
// TODO res.transfer, res.checkin // TODO res.checkin
} else { } else {
res.tripId = pt.journeyId || pt.zuglaufId; res.tripId = pt.journeyId || pt.zuglaufId;
res.line = profile.parseLine(ctx, pt) || null; res.line = profile.parseLine(ctx, pt) || null;

View file

@ -1,5 +1,22 @@
import {parseRemarks} from './remarks.js'; 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) => { const parseLocationsFromCtxRecon = (ctx, j) => {
return (j.ctxRecon || j.kontext) return (j.ctxRecon || j.kontext)
.split('$') .split('$')
@ -19,6 +36,10 @@ const parseJourney = (ctx, jj) => { // j = raw journey
const legs = []; const legs = [];
for (const l of j.verbindungsAbschnitte) { for (const l of j.verbindungsAbschnitte) {
const leg = profile.parseJourneyLeg(ctx, l, null, fallbackLocations); 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); legs.push(leg);
} }

View file

@ -86,6 +86,39 @@ const dbJourney = {
], ],
loadFactor: 'low-to-medium', 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: { origin: {
type: 'station', type: 'station',