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

Remove explicit timezone information from the train station database

This is now provided by the generic geo coordinate based timezone lookup.
This also contains an update to the SNCF station code index to cover
international destinations as well.
parent 42d5b935
......@@ -163,12 +163,14 @@ private Q_SLOTS:
QCOMPARE(station.country, CountryId{"FR"});
station = KnowledgeDb::stationForSncfStationId(SncfStationId{"CHGVA"});
QEXPECT_FAIL("", "Wikidata does not supply ids for non-French stations yet", Continue);
QVERIFY(station.coordinate.isValid());
QEXPECT_FAIL("", "Wikidata does not supply ids for non-French stations yet", Continue);
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Zurich"));
QEXPECT_FAIL("", "Wikidata does not supply ids for non-French stations yet", Continue);
QCOMPARE(station.country, CountryId{"CH"});
station = KnowledgeDb::stationForSncfStationId(SncfStationId{"NLAMA"}); // vs. SNCB ID of NLASC
QVERIFY(station.coordinate.isValid());
QCOMPARE(toQTimeZone(station.timezone()), QTimeZone("Europe/Amsterdam"));
QCOMPARE(station.country, CountryId{"NL"});
}
void testCountryDb()
......
......@@ -53,16 +53,14 @@ bool TrainStationDbGenerator::generate(QIODevice *out)
return false;
}
// timezone lookup and filtering
// filtering out stations without useful information
processStations();
// code generation
CodeGen::writeLicenseHeader(out);
out->write(R"(
#include "knowledgedb.h"
#include "timezonedb.h"
#include "trainstationdb.h"
#include "timezonedb_data.h"
namespace KItinerary {
namespace KnowledgeDb {
......@@ -182,7 +180,7 @@ bool TrainStationDbGenerator::fetchSncf()
const auto stationObj = stationData.toObject();
const auto uri = insertOrMerge(stationObj);
const auto id = stationObj.value(QLatin1String("gareConnexionId")).toObject().value(QLatin1String("value")).toString().toUpper();
const auto id = stationObj.value(QLatin1String("sncfId")).toObject().value(QLatin1String("value")).toString().toUpper();
if (id.size() != 5 || !Util::containsOnlyLetters(id)) {
++m_idFormatViolations;
qWarning() << "SNCF ID format violation" << id << uri;
......@@ -350,13 +348,7 @@ void TrainStationDbGenerator::processStations()
qDebug() << "Station has no geo coordinates:" << (*it).name << (*it).uri;
}
(*it).tz = m_tzDb.timezoneForLocation((*it).isoCode, (*it).coord);
if ((*it).tz.isEmpty() && ((*it).coord.isValid() || !(*it).isoCode.isEmpty())) {
++m_timezoneLookupFailure;
qWarning() << "Timezone lookup failure:" << (*it).name << (*it).uri;
}
if (!(*it).coord.isValid() && (*it).tz.isEmpty() && (*it).isoCode.isEmpty()) { // no useful information
if (!(*it).coord.isValid() && (*it).isoCode.isEmpty()) { // no useful information
it = m_stations.erase(it);
} else {
++it;
......@@ -371,8 +363,6 @@ void TrainStationDbGenerator::writeStationData(QIODevice *out)
out->write(" {");
CodeGen::writeCoordinate(out, station.coord);
out->write(", ");
CodeGen::writeTimezone(out, station.tz);
out->write(", ");
CodeGen::writeCountryIsoCode(out, station.isoCode);
out->write("}, // ");
out->write(station.name.toUtf8());
......@@ -521,5 +511,4 @@ void TrainStationDbGenerator::printSummary()
qDebug() << "Identifier format violations:" << m_idFormatViolations;
qDebug() << "Coordinate conflicts:" << m_coordinateConflicts;
qDebug() << "Country ISO code conflicts: " << m_countryConflicts;
qDebug() << "Failed timezone lookups:" << m_timezoneLookupFailure;
}
......@@ -19,7 +19,6 @@
#define KITINERARY_GENERATOR_TRAINSTATIONDBGENERATOR_H
#include <knowledgedb.h>
#include <timezones.h>
#include <QByteArray>
#include <QString>
......@@ -45,7 +44,6 @@ public:
QUrl uri;
QString name;
KnowledgeDb::Coordinate coord;
QByteArray tz;
QString isoCode;
};
......@@ -72,7 +70,6 @@ private:
std::map<QString, QUrl> m_sncfIdMap;
std::map<QString, QUrl> m_indianRailwaysMap;
std::map<QString, QUrl> m_vrfiMap;
Timezones m_tzDb;
int m_idConflicts = 0;
int m_idFormatViolations = 0;
......
......@@ -37,7 +37,7 @@ static_assert(trainstation_table_size < (1 << (sizeof(TrainStationIndex) * 8)),
Tz TrainStation::timezone() const
{
return m_timezone;
return timezoneForLocation(coordinate.latitude, coordinate.longitude, country);
}
SncfStationId::SncfStationId(const QString& id)
......@@ -63,7 +63,7 @@ TrainStation KnowledgeDb::stationForIbnr(IBNR ibnr)
{
const auto ibnrIt = std::lower_bound(std::begin(ibnr_table), std::end(ibnr_table), ibnr);
if (ibnrIt == std::end(ibnr_table) || (*ibnrIt).stationId != ibnr) {
return {Coordinate{}, Tz::Undefined, CountryId{}};
return {};
}
return trainstation_table[(*ibnrIt).stationIndex.value()];
......@@ -73,7 +73,7 @@ TrainStation KnowledgeDb::stationForUic(UICStation uic)
{
const auto it = std::lower_bound(std::begin(uic_table), std::end(uic_table), uic);
if (it == std::end(uic_table) || (*it).stationId != uic) {
return {Coordinate{}, Tz::Undefined, CountryId{}};
return {};
}
return trainstation_table[(*it).stationIndex.value()];
}
......@@ -82,7 +82,7 @@ TrainStation KnowledgeDb::stationForSncfStationId(SncfStationId sncfId)
{
const auto it = std::lower_bound(std::begin(sncfStationId_table), std::end(sncfStationId_table), sncfId);
if (it == std::end(sncfStationId_table) || (*it).stationId != sncfId) {
return {Coordinate{}, Tz::Undefined, CountryId{}};
return {};
}
return trainstation_table[(*it).stationIndex.value()];
......@@ -95,7 +95,7 @@ TrainStation KnowledgeDb::stationForIndianRailwaysStationCode(const QString &cod
return strcmp(indianRailwaysSationCode_stringtable + lhs.offset, rhs.constData()) < 0;
});
if (it == std::end(indianRailwaysSationCode_index) || strcmp(indianRailwaysSationCode_stringtable + (*it).offset, codeStr.constData()) != 0) {
return {Coordinate{}, Tz::Undefined, CountryId{}};
return {};
}
return trainstation_table[(*it).stationIndex.value()];
......@@ -105,7 +105,7 @@ TrainStation KnowledgeDb::stationForVRStationCode(VRStationCode vrStation)
{
const auto it = std::lower_bound(std::begin(vrfiConnexionsId_table), std::end(vrfiConnexionsId_table), vrStation);
if (it == std::end(vrfiConnexionsId_table) || (*it).stationId != vrStation) {
return {Coordinate{}, Tz::Undefined, CountryId{}};
return {};
}
return trainstation_table[(*it).stationIndex.value()];
......
......@@ -57,7 +57,6 @@ struct TrainStationIdIndex {
*/
struct TrainStation {
Coordinate coordinate;
Tz m_timezone;
CountryId country;
KITINERARY_EXPORT Tz timezone() const;
......
This diff is collapsed.
Markdown is supported
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