diff --git a/parse/line.js b/parse/line.js index fa024196..0b78103a 100644 --- a/parse/line.js +++ b/parse/line.js @@ -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; }; diff --git a/parse/operator.js b/parse/operator.js index 8c39ab00..84f9cda2 100644 --- a/parse/operator.js +++ b/parse/operator.js @@ -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; diff --git a/readme.md b/readme.md index 64dd9c22..f5da5720 100644 --- a/readme.md +++ b/readme.md @@ -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 | diff --git a/test/fixtures/db-arrivals.js b/test/fixtures/db-arrivals.js index e796a266..49843f42 100644 --- a/test/fixtures/db-arrivals.js +++ b/test/fixtures/db-arrivals.js @@ -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: [ { diff --git a/test/fixtures/db-departures-regio-guide.js b/test/fixtures/db-departures-regio-guide.js index 81a4b79b..bd8a664f 100644 --- a/test/fixtures/db-departures-regio-guide.js +++ b/test/fixtures/db-departures-regio-guide.js @@ -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, diff --git a/test/fixtures/dbnav-refresh-journey.js b/test/fixtures/dbnav-refresh-journey.js index 47b3af6b..5ec74937 100644 --- a/test/fixtures/dbnav-refresh-journey.js +++ b/test/fixtures/dbnav-refresh-journey.js @@ -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', diff --git a/test/parse/line.js b/test/parse/line.js index 1f5a9ecf..f95ecfc1 100644 --- a/test/parse/line.js +++ b/test/parse/line.js @@ -184,6 +184,7 @@ tap.test('parses regio guide ruf correctly', (t) => { product: 'taxi', productName: 'RUF', mode: 'taxi', + adminCode: 'vrn062', operator: null, };