mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
db: create fake walking leg for intra-station transfer
This commit is contained in:
parent
232893f2dc
commit
60656b0119
3 changed files with 56 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
33
test/fixtures/db-refresh-journey.js
vendored
33
test/fixtures/db-refresh-journey.js
vendored
|
@ -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',
|
||||
|
|
Loading…
Add table
Reference in a new issue