2024-12-07 16:16:31 +00:00
|
|
|
import {parseRemarks, isStopCancelled} from './remarks.js';
|
|
|
|
|
|
|
|
const locationFallback = (id, name) => {
|
|
|
|
return {
|
|
|
|
type: 'stop',
|
|
|
|
id: id,
|
|
|
|
name: name,
|
2024-12-08 21:42:57 +00:00
|
|
|
location: null,
|
|
|
|
};
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2017-11-20 15:43:13 +01:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const parseJourneyLeg = (ctx, pt, date) => { // pt = raw leg
|
2024-02-06 22:58:49 +01:00
|
|
|
const {profile, opt} = ctx;
|
2019-10-20 00:19:11 +02:00
|
|
|
|
|
|
|
const res = {
|
2024-12-07 16:16:31 +00:00
|
|
|
origin: pt.halte?.length > 0 ? profile.parseLocation(ctx, pt.halte[0]) : locationFallback(pt.abfahrtsOrtExtId, pt.abfahrtsOrt),
|
2024-12-08 21:42:57 +00:00
|
|
|
destination: pt.halte?.length > 0 ? profile.parseLocation(ctx, pt.halte[pt.halte.length - 1]) : locationFallback(pt.ankunftsOrtExtId, pt.ankunftsOrt),
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2019-06-08 12:54:59 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const cancelledDep = pt.halte?.length > 0 && isStopCancelled(pt.halte[0]);
|
|
|
|
const dep = profile.parseWhen(ctx, date, pt.abfahrtsZeitpunkt, pt.ezAbfahrtsZeitpunkt, cancelledDep);
|
2024-02-06 22:58:49 +01:00
|
|
|
res.departure = dep.when;
|
|
|
|
res.plannedDeparture = dep.plannedWhen;
|
|
|
|
res.departureDelay = dep.delay;
|
|
|
|
if (dep.prognosedWhen) {
|
|
|
|
res.prognosedDeparture = dep.prognosedWhen;
|
|
|
|
}
|
add planned(Arrival|Departure|When), scheduled* -> planned*/prognosed* :boom:
when not cancelled:
{when, delay} -> {when, plannedWhen, delay}
{arrival, arrivalDelay} -> {arrival, plannedArrival, arrivalDelay}
{departure, departureDelay} -> {departure, plannedDeparture, departureDelay}
when cancelled:
{when: null, delay: null, scheduledWhen} -> {when: null, plannedWhen, prognosedWhen, delay}
{arrival: null, arrivalDelay: null, scheduledArrival, formerArrivalDelay} -> {arrival: null, plannedArrival, arrivalDelay, prognosedArrival}
{departure: null, departureDelay: null, scheduledDeparture, formerDepartureDelay} -> {departure: null, plannedDeparture, departureDelay, prognosedDeparture}
2019-08-23 18:51:03 +02:00
|
|
|
|
2024-12-08 21:42:57 +00:00
|
|
|
const cancelledArr = pt.halte?.length > 0 && isStopCancelled(pt.halte[pt.halte.length - 1]);
|
2024-12-07 16:16:31 +00:00
|
|
|
const arr = profile.parseWhen(ctx, date, pt.ankunftsZeitpunkt, pt.ezAnkunftsZeitpunkt, cancelledArr);
|
2024-02-06 22:58:49 +01:00
|
|
|
res.arrival = arr.when;
|
|
|
|
res.plannedArrival = arr.plannedWhen;
|
|
|
|
res.arrivalDelay = arr.delay;
|
|
|
|
if (arr.prognosedWhen) {
|
|
|
|
res.prognosedArrival = arr.prognosedWhen;
|
|
|
|
}
|
2020-09-10 23:57:03 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
/* TODO res.reachable risNotizen [
|
|
|
|
{
|
|
|
|
"key": "text.realtime.connection.brokentrip",
|
|
|
|
"value": "Due to delays a connecting service may not be reachable."
|
|
|
|
}
|
|
|
|
] */
|
2017-11-20 15:43:13 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if (opt.polylines && pt.polylineGroup) {
|
|
|
|
res.polyline = profile.parsePolyline(ctx, pt.polylineGroup);
|
2019-10-20 00:19:11 +02:00
|
|
|
}
|
2018-04-30 12:49:58 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if (pt.verkehrsmittel?.typ === 'WALK') {
|
2024-02-06 22:58:49 +01:00
|
|
|
res.public = true;
|
|
|
|
res.walking = true;
|
2024-12-07 16:16:31 +00:00
|
|
|
res.distance = pt.distanz || null;
|
2024-12-08 21:42:57 +00:00
|
|
|
// TODO res.transfer, res.checkin
|
2024-12-07 16:16:31 +00:00
|
|
|
} else {
|
|
|
|
res.tripId = pt.journeyId;
|
|
|
|
res.line = profile.parseLine(ctx, pt) || null;
|
|
|
|
res.direction = pt.verkehrsmittel?.richtung || null;
|
|
|
|
|
|
|
|
// TODO res.currentLocation
|
|
|
|
if (pt.halte?.length > 0) {
|
2024-12-08 21:42:57 +00:00
|
|
|
const arrPl = profile.parsePlatform(ctx, pt.halte[pt.halte.length - 1].gleis, pt.halte[pt.halte.length - 1].ezGleis, cancelledArr);
|
2024-12-07 16:16:31 +00:00
|
|
|
res.arrivalPlatform = arrPl.platform;
|
|
|
|
res.plannedArrivalPlatform = arrPl.plannedPlatform;
|
|
|
|
if (arrPl.prognosedPlatform) {
|
|
|
|
res.prognosedArrivalPlatform = arrPl.prognosedPlatform;
|
2018-07-16 12:18:23 +02:00
|
|
|
}
|
2024-12-08 21:42:57 +00:00
|
|
|
// res.arrivalPrognosisType = null; // TODO
|
2018-06-25 13:54:30 +02:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const depPl = profile.parsePlatform(ctx, pt.halte[0].gleis, pt.halte[0].ezGleis, cancelledDep);
|
|
|
|
res.departurePlatform = depPl.platform;
|
|
|
|
res.plannedDeparturePlatform = depPl.plannedPlatform;
|
|
|
|
if (depPl.prognosedPlatform) {
|
|
|
|
res.prognosedDeparturePlatform = depPl.prognosedPlatform;
|
|
|
|
}
|
2024-12-08 21:42:57 +00:00
|
|
|
// res.departurePrognosisType = null; // TODO
|
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
|
|
|
|
if (opt.stopovers) {
|
|
|
|
res.stopovers = pt.halte.map(s => profile.parseStopover(ctx, s, date));
|
|
|
|
// filter stations the train passes without stopping, as this doesn't comply with fptf (yet)
|
|
|
|
res.stopovers = res.stopovers.filter((x) => !x.passBy);
|
2024-12-08 21:42:57 +00:00
|
|
|
}
|
2024-12-07 16:16:31 +00:00
|
|
|
if (opt.remarks) {
|
|
|
|
res.remarks = parseRemarks(ctx, pt);
|
2024-02-06 22:58:49 +01:00
|
|
|
}
|
2019-10-20 00:19:11 +02:00
|
|
|
}
|
2018-12-02 01:05:01 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
// TODO cycle, alternatives
|
2019-10-20 00:19:11 +02:00
|
|
|
}
|
2017-11-20 15:43:13 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
if (cancelledDep || cancelledArr) {
|
2024-02-06 22:58:49 +01:00
|
|
|
res.cancelled = true;
|
|
|
|
Object.defineProperty(res, 'canceled', {value: true});
|
2017-11-20 15:43:13 +01:00
|
|
|
}
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
return res;
|
|
|
|
};
|
2017-11-20 15:43:13 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
parseJourneyLeg,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|