db-vendo-client/parse/stopover.js

65 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

const parseStopover = (ctx, st, date) => { // st = raw stopover
const {profile, opt} = ctx;
2025-01-02 14:00:45 +00:00
const cancelled = profile.parseCancelled(st);
const arr = profile.parseWhen(ctx, date, st.ankunftsZeitpunkt || st.ankunftsDatum || st.arrivalTime?.target, st.ezAnkunftsZeitpunkt || st.ezAnkunftsDatum || st.arrivalTime?.timeType != 'SCHEDULE' && st.arrivalTime?.predicted, cancelled,
);
const arrPl = profile.parsePlatform(ctx, st.gleis || st.track?.target, st.ezGleis || st.track?.prediction);
const dep = profile.parseWhen(ctx, date, st.abfahrtsZeitpunkt || st.abgangsDatum || st.departureTime?.target, st.ezAbfahrtsZeitpunkt || st.ezAbgangsDatum || st.departureTime?.timeType != 'SCHEDULE' && st.departureTime?.predicted, cancelled,
);
const depPl = arrPl;
const res = {
stop: profile.parseLocation(ctx, st.ort || st.station || st) || null,
arrival: arr.when,
plannedArrival: arr.plannedWhen,
arrivalDelay: arr.delay,
arrivalPlatform: arrPl.platform,
2024-12-07 16:16:31 +00:00
arrivalPrognosisType: null, // TODO
plannedArrivalPlatform: arrPl.plannedPlatform,
departure: dep.when,
plannedDeparture: dep.plannedWhen,
departureDelay: dep.delay,
departurePlatform: depPl.platform,
2024-12-07 16:16:31 +00:00
departurePrognosisType: null, // TODO
plannedDeparturePlatform: depPl.plannedPlatform,
};
2017-11-11 22:35:41 +01:00
if (arr.prognosedWhen) {
res.prognosedArrival = arr.prognosedWhen;
}
if (arrPl.prognosedPlatform) {
res.prognosedArrivalPlatform = arrPl.prognosedPlatform;
}
if (dep.prognosedWhen) {
res.prognosedDeparture = dep.prognosedWhen;
}
if (depPl.prognosedPlatform) {
res.prognosedDeparturePlatform = depPl.prognosedPlatform;
}
2025-01-03 10:57:24 +00:00
const load = profile.parseLoadFactor(opt, st.auslastungsmeldungen || st.auslastungsInfos);
if (load) {
res.loadFactor = load;
}
// mark stations the train passes without stopping
2024-12-07 16:16:31 +00:00
// TODO risNotizen key text.realtime.stop.exit.disabled?
2024-12-07 16:16:31 +00:00
if (cancelled) {
res.cancelled = true;
Object.defineProperty(res, 'canceled', {value: true});
}
2024-12-07 16:16:31 +00:00
// TODO res.additional = true;
2024-12-07 16:16:31 +00:00
if (opt.remarks) {
2025-01-02 14:00:45 +00:00
res.remarks = profile.parseRemarks(ctx, st);
}
return res;
};
2017-11-11 22:35:41 +01:00
2022-05-07 16:17:37 +02:00
export {
parseStopover,
};