db-vendo-client/parse/line.js
dabund24 c671e995cb
bahn.de boards (#12)
* parse bahn.de boards

* add optional chaining in line.js

* unit tests for bahn.de boards

* fix product check in line.js for bahn.de boards

* add integration tests for bahn.de boards

* allow letting hafas decide the amount of vias

* split dbweb and dbregioguide profiles; add db profile

* commit location-filter.js (forgot that in the last commit)

* simplify how db profile works

* remove `ezGleis` from coalesce for scheduled platform

* un-break parsing of remarks

* determine fahrtNr by removing all non-digits

* employ enrichStations for board stop property

* prevent timeouts in dbweb e2e test from calling `end()` twice

* use promises in dbweb e2e tests when waiting for enrichStations to work

* replace vias option with stopovers option for dbweb profile; enrich stations when only name is known

* change dbweb-departures test covering enrichStation feature for stop and stopovers

* remove check for not existing option

* move verkehrsmittel.name in front of verkehrsmittel.langText when parsing name in line.js
2025-02-09 00:46:21 +01:00

29 lines
1.8 KiB
JavaScript

import slugg from 'slugg';
const parseLine = (ctx, p) => {
const profile = ctx.profile;
const fahrtNr = p.verkehrsmittel?.nummer || p.transport?.number || p.train?.no || p.no || ((p.risZuglaufId || '') + '_').split('_')[1] || p.verkehrsmittelNummer || (p.verkehrmittel?.langText || p.verkehrsmittel?.langText || p.mitteltext || p.zugName || '').replace(/\D/g, '');
const res = {
type: 'line',
id: slugg(p.verkehrsmittel?.langText || p.verkehrmittel?.langText || p.transport?.journeyDescription || p.risZuglaufId || p.train && p.train.category + ' ' + p.train.lineName + ' ' + p.train.no || p.no && p.name + ' ' + p.no || p.langtext || p.mitteltext || p.zugName), // TODO terrible
fahrtNr: String(fahrtNr),
name: p.verkehrsmittel?.name || p.verkehrsmittel?.langText || p.verkehrmittel?.name || p.verkehrmittel?.langText || p.zugName || p.transport && p.transport.category + ' ' + p.transport.line || p.train && p.train.category + ' ' + p.train.lineName || p.name || p.mitteltext || p.langtext,
public: true,
};
const adminCode = p.administrationId || p.administration?.id || p.administration?.administrationID;
if (adminCode) {
res.adminCode = adminCode;
}
res.productName = p.verkehrsmittel?.kurzText || p.verkehrmittel?.kurzText || p.transport?.category || p.train?.category || p.category || p.kurztext;
const foundProduct = profile.products.find(pp => pp.vendo == p.verkehrsmittel?.produktGattung || pp.vendo == p.verkehrmittel?.produktGattung || pp.ris == p.transport?.type || pp.ris == p.train?.type || pp.ris == p.type || pp.ris_alt == p.train?.type || pp.ris_alt == p.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 || p.administration || p);
return res;
};
export {
parseLine,
};