Commit ffbab5fc authored by Volker Krause's avatar Volker Krause
Browse files

Allow to prefer line numbers over product names for Hafas

This gives us a way to strip non-canonical prefixes in the product names,
such as DB's "STR" for trams and SNCB's "Mét" for subways. Doing this
fixes merging with other results, and makes line mode icons show up.
parent acab3ab9
Pipeline #91821 passed with stage
in 1 minute and 33 seconds
......@@ -59,6 +59,7 @@ void HafasMgateBackend::init()
m_parser.setLocationIdentifierTypes(locationIdentifierType(), standardLocationIdentifierType());
m_parser.setLineModeMap(std::move(m_lineModeMap));
m_parser.setStandardLocationIdentfierCountries(std::move(m_uicCountryCodes));
m_parser.setPreferLineNumberProducts(std::move(m_lineNumberProducts));
}
AbstractBackend::Capabilities HafasMgateBackend::capabilities() const
......@@ -404,3 +405,15 @@ void HafasMgateBackend::setConGroups(const QJsonArray &conGroups)
m_conGroups.push_back(std::move(cg));
}
}
void HafasMgateBackend::setPreferLineNumberProducts(const QJsonArray &lineNumberProduducts)
{
m_lineNumberProducts.reserve(lineNumberProduducts.size());
for (const auto &lineNumV : lineNumberProduducts) {
const auto num = lineNumV.toInt();
if (num > 0) {
m_lineNumberProducts.push_back(num);
}
}
std::sort(m_lineNumberProducts.begin(), m_lineNumberProducts.end());
}
......@@ -45,6 +45,12 @@ class KPUBLICTRANSPORT_EXPORT HafasMgateBackend : public HafasBackend
* our transport modes.
*/
Q_PROPERTY(QJsonArray conGroups WRITE setConGroups)
/** Products (as numerical Hafas ids) for which we should prefer the line number over the line name.
* This is useful to strip non-canonical prefixes.
*/
Q_PROPERTY(QJsonArray preferLineNumberProducts WRITE setPreferLineNumberProducts)
public:
HafasMgateBackend();
~HafasMgateBackend() override;
......@@ -65,6 +71,7 @@ private:
void setMicMacSalt(const QString &salt);
void setChecksumSalt(const QString &salt);
void setConGroups(const QJsonArray &conGroups);
void setPreferLineNumberProducts(const QJsonArray &lineNumberProduducts);
QJsonObject locationToJson(const Location &loc) const;
mutable HafasMgateParser m_parser;
......@@ -82,6 +89,7 @@ private:
QString group;
};
std::vector<ConGroup> m_conGroups;
std::vector<int> m_lineNumberProducts;
};
}
......
......@@ -246,9 +246,20 @@ std::vector<Line> HafasMgateParser::parseLines(const QJsonArray &prodL, const st
lines.reserve(prodL.size());
for (const auto &prodV : prodL) {
const auto prodObj = prodV.toObject();
const auto prodCls = prodObj.value(QLatin1String("cls")).toInt();
Line line;
line.setName(prodObj.value(QLatin1String("name")).toString());
line.setMode(parseLineMode(prodObj.value(QLatin1String("cls")).toInt()));
line.setMode(parseLineMode(prodCls));
if (std::binary_search(m_lineNumberProducts.begin(), m_lineNumberProducts.end(), prodCls)) {
line.setName(prodObj.value(QLatin1String("line")).toString());
if (line.name().isEmpty()) {
line.setName(prodObj.value(QLatin1String("nameS")).toString());
}
}
if (line.name().isEmpty()) {
line.setName(prodObj.value(QLatin1String("name")).toString());
}
const auto icoIdx = prodObj.value(QLatin1String("icoX")).toInt();
if ((unsigned int)icoIdx < icos.size()) {
......@@ -794,3 +805,8 @@ QDateTime HafasMgateParser::parseDateTime(const QString &date, const QJsonValue
return dt;
}
void HafasMgateParser::setPreferLineNumberProducts(std::vector<int> &&lineNumberProducts)
{
m_lineNumberProducts = std::move(lineNumberProducts);
}
......@@ -41,6 +41,7 @@ class KPUBLICTRANSPORT_EXPORT HafasMgateParser : public HafasParser
public:
HafasMgateParser();
~HafasMgateParser();
void setPreferLineNumberProducts(std::vector<int> &&lineNumberProducts);
std::vector<Stopover> parseDepartures(const QByteArray &data) const;
std::vector<Location> parseLocations(const QByteArray &data) const;
......@@ -57,6 +58,8 @@ private:
std::vector<Location> parseLocations(const QJsonArray &locL) const;
std::vector<Journey> parseTripSearch(const QJsonObject &obj);
bool parseError(const QJsonObject &obj) const;
std::vector<int> m_lineNumberProducts;
};
}
......
......@@ -190,6 +190,7 @@
"customCaCertificate": "digicert-sha2-secure-server-ca.pem",
"endpoint": "https://www.belgianrail.be/jp/sncb-nmbs-routeplanner/mgate.exe",
"locationIdentifierType": "sncb",
"preferLineNumberProducts": [ 256, 1024 ],
"products": [
{
"bitmasks": [
......
......@@ -104,6 +104,7 @@
"endpoint": "https://reiseauskunft.bahn.de/bin/mgate.exe",
"ext": "DB.R20.12.b",
"locationIdentifierType": "db",
"preferLineNumberProducts": [ 256 ],
"products": [
{
"bitmasks": [
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment