2018-06-30 18:04:44 +02:00
|
|
|
const codesByIcon = Object.assign(Object.create(null), {
|
2020-03-18 21:37:31 +01:00
|
|
|
cancel: 'cancelled',
|
|
|
|
himWarn: 'disturbance',
|
2024-02-06 22:58:49 +01:00
|
|
|
});
|
2018-06-30 18:04:44 +02:00
|
|
|
|
2020-03-07 00:28:47 +01:00
|
|
|
const linkTypesByCode = Object.assign(Object.create(null), {
|
2020-03-07 00:31:25 +01:00
|
|
|
BB: 'stop-website',
|
2020-03-07 00:28:47 +01:00
|
|
|
// IFOPT-based DHID
|
|
|
|
// https://wiki.openstreetmap.org/wiki/DE:Key:ref:IFOPT
|
|
|
|
// https://trid.trb.org/view/1435440
|
|
|
|
IF: 'stop-dhid',
|
2020-03-07 00:31:25 +01:00
|
|
|
OZ: 'transit-authority',
|
2020-03-07 00:28:47 +01:00
|
|
|
// todo: `{type: 'I',code: 'TD',icoX: 1,txtN: '8010224'}`
|
|
|
|
// todo: `{type: 'I',code: 'TE',icoX: 1,txtN: '8024001'}`
|
2024-02-06 22:58:49 +01:00
|
|
|
});
|
2020-03-07 00:28:47 +01:00
|
|
|
|
2019-06-21 18:43:10 +02:00
|
|
|
// todo: pass in tag list from hint reference, e.g.:
|
|
|
|
// "tagL": [
|
|
|
|
// "RES_JNY_H3" // H3 = level 3 heading? shown on overview
|
|
|
|
// ]
|
|
|
|
// "tagL": [
|
|
|
|
// "RES_JNY_DTL" // only shown in journey detail
|
|
|
|
// ]
|
2019-09-03 15:33:30 +02:00
|
|
|
// todo: https://github.com/public-transport/hafas-client/issues/5
|
2020-03-18 21:35:43 +01:00
|
|
|
// todo: expose h.type somehow
|
2021-10-26 14:15:17 +02:00
|
|
|
// todo: https://github.com/KDE/kpublictransport/blob/39ac8f9586b9300fa8a9ba0dec010e96fab9ab08/src/lib/backends/hafasmgateparser.cpp#L56-L72
|
2021-11-18 18:29:25 +01:00
|
|
|
// todo: h.sty
|
2022-10-24 17:29:23 +02:00
|
|
|
|
|
|
|
// SNCB:
|
|
|
|
// {
|
|
|
|
// "type": "A",
|
|
|
|
// "code": "60",
|
|
|
|
// "prio": 10,
|
|
|
|
// "icoX": 2,
|
|
|
|
// "txtN": "Reservierungspflicht"
|
|
|
|
// }
|
|
|
|
// {
|
|
|
|
// "type": "A",
|
|
|
|
// "code": "64",
|
|
|
|
// "prio": 110,
|
|
|
|
// "icoX": 2,
|
|
|
|
// "txtN": "Zuschlag"
|
|
|
|
// }
|
|
|
|
// {
|
|
|
|
// "type": "I",
|
|
|
|
// "code": "CON_OVERVIEW_TARIF_HINT",
|
|
|
|
// "icoX": 2,
|
|
|
|
// "txtN": "Für diese Strecke ist ein internationales Ticket notwendig."
|
|
|
|
// }
|
2023-05-15 12:58:32 +02:00
|
|
|
|
|
|
|
// DB:
|
|
|
|
// {
|
|
|
|
// "type": "C",
|
|
|
|
// "code": "",
|
|
|
|
// "icoX": 2,
|
|
|
|
// "txtN": "Current information available."
|
|
|
|
// }
|
|
|
|
// {
|
|
|
|
// "type": "H",
|
|
|
|
// "code": "text.connection.section.arrival.date.deviation",
|
|
|
|
// "icoX": 4,
|
|
|
|
// "txtN": "Arrival Wednesday, 2023-05-10"
|
|
|
|
// }
|
|
|
|
// {
|
|
|
|
// "type": "H",
|
|
|
|
// "code": "text.connection.section.departure.date.deviation",
|
|
|
|
// "icoX": 4,
|
|
|
|
// "txtN": "Departure Wednesday, 2023-05-10"
|
|
|
|
// }
|
|
|
|
// {
|
|
|
|
// "type": "C",
|
|
|
|
// "code": "",
|
|
|
|
// "icoX": 8,
|
|
|
|
// "txtN": "Includes trains requiring a reservation"
|
|
|
|
// }
|
|
|
|
|
|
|
|
// DB:
|
|
|
|
// {
|
|
|
|
// "type": "A",
|
|
|
|
// "code": "RP",
|
|
|
|
// "icoX": 7,
|
|
|
|
// "txtN": "RP"
|
|
|
|
// }
|
|
|
|
// on this `jny`:
|
|
|
|
// {
|
|
|
|
// "jid": "1|327365|0|80|-1",
|
|
|
|
// "prodX": 27,
|
|
|
|
// "status": "P",
|
|
|
|
// "isRchbl": true,
|
|
|
|
// "pos": {
|
|
|
|
// "x": 9837336,
|
|
|
|
// "y": 52241377
|
|
|
|
// },
|
|
|
|
// "ctxRecon": "T$A=1@O=Hamburg Hbf@L=8002549@a=0@$A=1@O=Freiburg(Breisgau) Hbf@L=8000107@a=0@$202305092207$202305100721$NJ 471$$1$$$$$$",
|
|
|
|
// "msgL": [
|
|
|
|
// {
|
|
|
|
// "type": "REM",
|
|
|
|
// "remX": 3,
|
|
|
|
// "sty": "I",
|
|
|
|
// "tagL": [
|
|
|
|
// "RES_JNY_DTL_L"
|
|
|
|
// ],
|
|
|
|
// "sort": 818413568
|
|
|
|
// }
|
|
|
|
// ],
|
|
|
|
// "approxDelay": true,
|
|
|
|
// "subscr": "F",
|
|
|
|
// "sumLDrawStyleX": 4,
|
|
|
|
// "resLDrawStyleX": 1,
|
|
|
|
// "durS": "091400"
|
|
|
|
// }
|
|
|
|
|
2024-03-12 12:26:46 +01:00
|
|
|
// todo bvg:
|
|
|
|
// {"type": "R", "code": "text.realtime.journey.cancelled", "icoX": 7, "txtN": ": S41"} with icon {"res": "rt_cancel"}
|
|
|
|
|
2019-10-20 00:19:11 +02:00
|
|
|
const parseHint = (ctx, h) => {
|
2018-06-01 11:12:54 +02:00
|
|
|
// todo: C
|
2018-06-11 18:41:53 +02:00
|
|
|
|
2020-03-07 00:28:47 +01:00
|
|
|
if (h.type === 'I' && h.code && h.txtN) {
|
|
|
|
if (h.code in linkTypesByCode) {
|
2024-02-06 22:58:49 +01:00
|
|
|
const text = h.txtN === 'NULL'
|
|
|
|
? null
|
|
|
|
: h.txtN;
|
|
|
|
return {type: linkTypesByCode[h.code], text};
|
2020-03-07 00:28:47 +01:00
|
|
|
}
|
2020-03-07 00:31:25 +01:00
|
|
|
if (h.code === 'TW' && h.txtN[0] === '$') {
|
2024-02-06 22:58:49 +01:00
|
|
|
return {type: 'local-fare-zone', text: h.txtN.slice(1)};
|
2020-03-07 00:31:25 +01:00
|
|
|
}
|
2020-03-07 00:28:47 +01:00
|
|
|
if (h.code === 'TW' && h.txtN[0] === '#') {
|
2024-02-06 22:58:49 +01:00
|
|
|
return {type: 'foreign-id', text: h.txtN.slice(1)};
|
2020-03-07 00:28:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
const text = h.txtN && h.txtN.trim() || '';
|
|
|
|
const icon = h.icon || null;
|
|
|
|
const code = h.code || icon && icon.type && codesByIcon[icon.type] || null;
|
2018-06-07 15:41:00 +02:00
|
|
|
|
2018-06-11 19:50:44 +02:00
|
|
|
if (h.type === 'M') {
|
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
summary: h.txtS && h.txtS.trim() || '',
|
2018-06-30 18:04:44 +02:00
|
|
|
code,
|
2024-02-06 22:58:49 +01:00
|
|
|
text,
|
|
|
|
};
|
2018-06-11 19:50:44 +02:00
|
|
|
}
|
|
|
|
|
2018-06-07 16:00:28 +02:00
|
|
|
if (h.type === 'L') {
|
2018-06-01 11:12:54 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
|
|
|
code: 'alternative-trip',
|
2018-06-11 18:41:53 +02:00
|
|
|
text,
|
2024-02-06 22:58:49 +01:00
|
|
|
tripId: h.jid,
|
|
|
|
};
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
2018-10-28 16:37:19 +01:00
|
|
|
if (h.type === 'A' || h.type === 'I') {
|
2018-07-09 19:26:15 +02:00
|
|
|
return {
|
|
|
|
type: 'hint',
|
2019-09-03 15:33:30 +02:00
|
|
|
code,
|
2024-02-06 22:58:49 +01:00
|
|
|
text,
|
|
|
|
};
|
2018-06-07 15:41:00 +02:00
|
|
|
}
|
2018-06-30 18:04:44 +02:00
|
|
|
|
2019-11-24 16:59:50 +01:00
|
|
|
if (
|
2024-02-06 22:58:49 +01:00
|
|
|
h.type === 'D' || h.type === 'U' || h.type === 'R' || h.type === 'N'
|
|
|
|
|| h.type === 'Y' || h.type === 'Q' || h.type === 'P'
|
2019-11-24 16:59:50 +01:00
|
|
|
) {
|
2018-06-01 11:12:54 +02:00
|
|
|
// todo: how can we identify the individual types?
|
2018-07-02 18:48:23 +02:00
|
|
|
// todo: does `D` mean "disturbance"?
|
2018-06-01 11:12:54 +02:00
|
|
|
return {
|
|
|
|
type: 'status',
|
2018-06-30 18:04:44 +02:00
|
|
|
code,
|
2024-02-06 22:58:49 +01:00
|
|
|
text,
|
|
|
|
};
|
2018-06-01 11:12:54 +02:00
|
|
|
}
|
2018-07-02 18:48:23 +02:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
return null;
|
|
|
|
};
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
parseHint,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|