2024-02-06 22:58:49 +01:00
|
|
|
const ARRIVAL = 'a';
|
|
|
|
const DEPARTURE = 'd';
|
2018-09-03 15:12:06 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const createParseArrOrDep = (prefix) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
if (prefix !== ARRIVAL && prefix !== DEPARTURE) {
|
|
|
|
throw new Error('invalid prefix');
|
|
|
|
}
|
2018-06-26 15:49:50 +02:00
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const parseArrOrDep = (ctx, d) => { // d = raw arrival/departure
|
2024-02-06 22:58:49 +01:00
|
|
|
const {profile, opt} = ctx;
|
2025-01-02 14:00:45 +00:00
|
|
|
const cancelled = profile.parseCancelled(d);
|
2018-06-26 15:49:50 +02:00
|
|
|
const res = {
|
2025-02-09 00:46:21 +01:00
|
|
|
tripId: d.journeyID || d.journeyId || d.train?.journeyId || d.zuglaufId,
|
|
|
|
stop: profile.parseLocation(ctx, d.station || d.abfrageOrt || {bahnhofsId: d.bahnhofsId}),
|
2025-01-02 14:00:45 +00:00
|
|
|
...profile.parseWhen(
|
|
|
|
ctx,
|
|
|
|
null,
|
2025-02-09 00:46:21 +01:00
|
|
|
d.timeSchedule || d.time || d.zeit || d.abgangsDatum || d.ankunftsDatum,
|
|
|
|
d.timeType != 'SCHEDULE' ? d.timePredicted || d.time || d.ezZeit || d.ezAbgangsDatum || d.ezAnkunftsDatum : null,
|
2025-01-02 14:00:45 +00:00
|
|
|
cancelled),
|
|
|
|
...profile.parsePlatform(ctx, d.platformSchedule || d.platform || d.gleis, d.platformPredicted || d.platform || d.ezGleis, cancelled),
|
2024-12-08 21:42:57 +00:00
|
|
|
// prognosisType: TODO
|
2025-02-09 00:46:21 +01:00
|
|
|
direction: d.transport?.direction?.stopPlaces?.length > 0 && profile.parseStationName(ctx, d.transport?.direction?.stopPlaces[0].name) || profile.parseStationName(ctx, d.destination?.name || d.richtung || d.terminus) || null,
|
2025-01-02 14:00:45 +00:00
|
|
|
provenance: profile.parseStationName(ctx, d.transport?.origin?.name || d.origin?.name || d.abgangsOrt?.name) || null,
|
2024-12-07 22:46:04 +00:00
|
|
|
line: profile.parseLine(ctx, d) || null,
|
2022-02-21 00:52:37 +01:00
|
|
|
remarks: [],
|
2024-12-10 17:51:20 +00:00
|
|
|
origin: profile.parseLocation(ctx, d.transport?.origin || d.origin) || null,
|
|
|
|
destination: profile.parseLocation(ctx, d.transport?.destination || d.destination) || null,
|
2024-12-21 15:26:49 +00:00
|
|
|
// loadFactor: profile.parseArrOrDepWithLoadFactor(ctx, d)
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|
2022-02-21 00:52:37 +01:00
|
|
|
|
2024-12-07 22:46:04 +00:00
|
|
|
// TODO pos
|
2021-10-12 17:50:05 +02:00
|
|
|
|
2025-01-02 14:00:45 +00:00
|
|
|
if (cancelled) {
|
2024-02-06 22:58:49 +01:00
|
|
|
res.cancelled = true;
|
|
|
|
Object.defineProperty(res, 'canceled', {value: true});
|
2018-06-26 15:49:50 +02:00
|
|
|
}
|
|
|
|
|
2018-06-28 13:45:56 +02:00
|
|
|
if (opt.remarks) {
|
2024-12-21 15:26:49 +00:00
|
|
|
res.remarks = profile.parseRemarks(ctx, d);
|
2018-06-28 13:45:56 +02:00
|
|
|
}
|
2025-02-09 00:46:21 +01:00
|
|
|
|
2025-02-13 20:09:18 +00:00
|
|
|
if ((opt.stopovers || opt.direction) && Array.isArray(d.ueber)) {
|
2025-02-09 00:46:21 +01:00
|
|
|
const stopovers = d.ueber
|
|
|
|
.map(viaName => profile.parseStopover(ctx, {name: viaName}, null));
|
|
|
|
|
|
|
|
if (prefix === ARRIVAL) {
|
|
|
|
res.previousStopovers = stopovers;
|
|
|
|
} else if (prefix === DEPARTURE) {
|
|
|
|
res.nextStopovers = stopovers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
return res;
|
|
|
|
};
|
2018-06-26 15:49:50 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
return parseArrOrDep;
|
|
|
|
};
|
2018-06-26 15:49:50 +02:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
createParseArrOrDep,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|