parse admincode, operator where available

This commit is contained in:
Traines 2025-01-09 12:26:42 +00:00
parent 615c36650e
commit 126077582b
7 changed files with 76 additions and 12 deletions

View file

@ -11,13 +11,16 @@ const parseLine = (ctx, p) => {
public: true,
};
// TODO res.adminCode
const adminCode = p.administrationId || p.administration?.id || p.administration?.administrationID;
if (adminCode) {
res.adminCode = adminCode;
}
res.productName = p.verkehrsmittel?.kurzText || p.transport?.category || p.train?.category || p.kurztext;
const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.ris == p.transport?.type || pp.ris == p.train?.type || pp.ris_alt == p.train?.type || pp.dbnav_short == p.produktGattung);
res.mode = foundProduct?.mode;
res.product = foundProduct?.id;
res.operator = profile.parseOperator(ctx, p.verkehrsmittel?.zugattribute || p.zugattribute || p.attributNotizen); // TODO regio-guide op
res.operator = profile.parseOperator(ctx, p.verkehrsmittel?.zugattribute || p.zugattribute || p.attributNotizen || p.administration);
return res;
};

View file

@ -4,6 +4,13 @@ const parseOperator = (ctx, zugattrib) => {
if (!zugattrib) {
return null;
}
if (zugattrib.operatorName) {
return {
type: 'operator',
id: zugattrib.operatorCode,
name: zugattrib.operatorName,
};
}
const bef = zugattrib.find(z => z.key == 'BEF' || z.key == 'OP');
if (!bef) {
return null;

View file

@ -32,6 +32,7 @@ Depending on the configured profile, db-vendo-client will use multiple different
| polylines | only for `trip()` | only for `refreshJourney()/trip()`, mutually exclusive with tickets |
| trip ids used | HAFAS trip ids for journeys, RIS trip ids for boards (static on train splits?) | HAFAS trip ids |
| line.id/fahrtNr used | unreliable/route id for journeys, actual fahrtNr for boards | unreliable/route id |
| adminCode/operator | adminCode only for boards | only for `journeys()` |
| `stop()` | ❌ | ✅ |
| assumed backend API stability | less stable | more stable |

View file

@ -22,7 +22,12 @@ const dbArrivals = [
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
adminCode: '08',
operator: {
type: 'operator',
id: 'S',
name: 'DB Regio, S-Bahn Berlin',
},
},
remarks: [
{
@ -62,7 +67,12 @@ const dbArrivals = [
productName: 'U',
mode: 'train',
product: 'subway',
operator: null,
adminCode: 'vbbBVU',
operator: {
type: 'operator',
id: 'DPN',
name: 'Nahreisezug',
},
},
remarks: [
{
@ -108,7 +118,12 @@ const dbArrivals = [
productName: 'Bus',
mode: 'bus',
product: 'bus',
operator: null,
adminCode: 'vbbBVB',
operator: {
type: 'operator',
id: 'DPN',
name: 'Nahreisezug',
},
},
remarks: [
{
@ -154,7 +169,12 @@ const dbArrivals = [
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
adminCode: '08',
operator: {
type: 'operator',
id: 'S',
name: 'DB Regio, S-Bahn Berlin',
},
},
remarks: [
{
@ -194,7 +214,12 @@ const dbArrivals = [
productName: 'U',
mode: 'train',
product: 'subway',
operator: null,
adminCode: 'vbbBVU',
operator: {
type: 'operator',
id: 'DPN',
name: 'Nahreisezug',
},
},
remarks: [
{
@ -240,7 +265,12 @@ const dbArrivals = [
productName: 'S',
mode: 'train',
product: 'suburban',
operator: null,
adminCode: '08',
operator: {
type: 'operator',
id: 'S',
name: 'DB Regio, S-Bahn Berlin',
},
},
remarks: [
{
@ -280,7 +310,12 @@ const dbArrivals = [
productName: 'U',
mode: 'train',
product: 'subway',
operator: null,
adminCode: 'vbbBVU',
operator: {
type: 'operator',
id: 'DPN',
name: 'Nahreisezug',
},
},
remarks: [
{

View file

@ -22,7 +22,12 @@ const dbDepartures = [
productName: 'RE',
mode: 'train',
product: 'regional',
operator: null,
adminCode: 'GARE',
operator: {
type: 'operator',
id: 'RE',
name: 'Arverio Baden-Württemberg (RE)',
},
},
remarks: [],
origin: null,
@ -55,7 +60,12 @@ const dbDepartures = [
productName: 'Bus',
mode: 'bus',
product: 'bus',
operator: null,
adminCode: 'vgn063',
operator: {
type: 'operator',
id: 'DPN',
name: 'Nahreisezug',
},
},
remarks: [],
origin: null,
@ -88,7 +98,12 @@ const dbDepartures = [
productName: 'Bus',
mode: 'bus',
product: 'bus',
operator: null,
adminCode: 'vgn063',
operator: {
type: 'operator',
id: 'DPN',
name: 'Nahreisezug',
},
},
remarks: [],
origin: null,

View file

@ -41,6 +41,7 @@ const dbNavJourney = {
productName: 'RB',
mode: 'train',
product: 'regional',
adminCode: 'V6RB__',
operator: {
type: 'operator',
id: 'vlexx',
@ -151,6 +152,7 @@ const dbNavJourney = {
productName: 'IC',
mode: 'train',
product: 'national',
adminCode: '80____',
operator: {
type: 'operator',
id: 'db-fernverkehr-ag',

View file

@ -184,6 +184,7 @@ tap.test('parses regio guide ruf correctly', (t) => {
product: 'taxi',
productName: 'RUF',
mode: 'taxi',
adminCode: 'vrn062',
operator: null,
};