2024-12-07 16:16:31 +00:00
|
|
|
import {parseRemarks} from './remarks.js';
|
2018-06-26 15:49:50 +02:00
|
|
|
|
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;
|
2018-06-26 15:49:50 +02:00
|
|
|
|
|
|
|
const res = {
|
2024-12-10 22:49:11 +00:00
|
|
|
tripId: d.journeyID || d.train.journeyId,
|
2024-12-07 22:46:04 +00:00
|
|
|
stop: profile.parseLocation(ctx, d.station),
|
2024-12-12 11:38:36 +00:00
|
|
|
...profile.parseWhen(ctx, null, d.timeSchedule ? d.timeSchedule : d.time, d.timeType != 'SCHEDULE' ? d.timePredicted ? d.timePredicted : d.time : null, d.canceled),
|
2024-12-10 17:51:20 +00:00
|
|
|
...profile.parsePlatform(ctx, d.platformSchedule ? d.platformSchedule : d.platform, d.platformPredicted ? d.platformPredicted : d.platform, d.canceled),
|
2024-12-08 21:42:57 +00:00
|
|
|
// prognosisType: TODO
|
2024-12-10 17:51:20 +00:00
|
|
|
direction: d.transport?.direction?.stopPlaces?.length > 0 && profile.parseStationName(ctx, d.transport?.direction?.stopPlaces[0].name) || profile.parseStationName(ctx, d.destination?.name) || null,
|
|
|
|
provenance: profile.parseStationName(ctx, d.transport?.origin?.name) || profile.parseStationName(ctx, d.origin?.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-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
|
|
|
|
2024-12-07 22:46:04 +00:00
|
|
|
if (d.canceled) {
|
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-07 22:46:04 +00:00
|
|
|
res.remarks = parseRemarks(ctx, d);
|
2018-06-28 13:45:56 +02:00
|
|
|
}
|
2024-12-07 22:46:04 +00:00
|
|
|
// TODO opt.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
|
|
|
};
|