File indexing completed on 2024-11-24 04:45:06
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "knowledgedb.h" 0010 #include "stationidentifier.h" 0011 #include "iatacode.h" 0012 0013 #include <QByteArray> 0014 #include <QString> 0015 #include <QUrl> 0016 0017 #include <map> 0018 #include <vector> 0019 0020 class QIODevice; 0021 class QJsonObject; 0022 0023 namespace KItinerary { 0024 namespace Generator { 0025 0026 /** Generate train station data tables. */ 0027 class TrainStationDbGenerator 0028 { 0029 public: 0030 bool generate(QIODevice *out); 0031 0032 struct Station 0033 { 0034 QUrl uri; 0035 QString name; 0036 KnowledgeDb::Coordinate coord; 0037 QString isoCode; 0038 }; 0039 0040 private: 0041 template <typename Id> 0042 bool fetch(const char *prop, const char *name, std::map<Id, QUrl> &idMap); 0043 bool fetchIndianRailwaysStationCode(); 0044 bool fetchFinishStationCodes(); 0045 bool fetchCountryInformation(); 0046 QUrl insertOrMerge(const QJsonObject &obj, bool mergeOnly = false); 0047 void processStations(); 0048 void writeStationData(QIODevice *out); 0049 template <typename Id> 0050 void writeIdMap(QIODevice *out, const std::map<Id, QUrl> &idMap, const char *tabName, const char *typeName) const; 0051 void writeIndianRailwaysMap(QIODevice *out); 0052 void writeVRMap(QIODevice *out); 0053 void printSummary(); 0054 0055 template <typename Id> 0056 QByteArray encodeId(Id id) const { return '"' + id.toString().toUtf8() + '"'; } 0057 QByteArray encodeId(KnowledgeDb::IBNR id) const { return QByteArray::number(id.value()); } 0058 QByteArray encodeId(KnowledgeDb::UICStation id) const { return QByteArray::number(id.value()); } 0059 0060 std::vector<Station> m_stations; 0061 std::map<KnowledgeDb::IBNR, QUrl> m_ibnrMap; 0062 std::map<KnowledgeDb::UICStation, QUrl> m_uicMap; 0063 std::map<KnowledgeDb::SncfStationId, QUrl> m_sncfIdMap; 0064 std::map<KnowledgeDb::BenerailStationId, QUrl> m_benerailIdMap; 0065 std::map<QString, QUrl> m_indianRailwaysMap; 0066 std::map<KnowledgeDb::VRStationCode, QUrl> m_vrfiMap; 0067 std::map<KnowledgeDb::IataCode, QUrl> m_iataMap; 0068 std::map<KnowledgeDb::AmtrakStationCode, QUrl> m_amtrakMap; 0069 std::map<KnowledgeDb::ViaRailStationCode, QUrl> m_viaRailMap; 0070 std::map<KnowledgeDb::UKRailwayStationCode, QUrl> m_ukMap; 0071 0072 int m_idConflicts = 0; 0073 int m_idFormatViolations = 0; 0074 int m_timezoneLookupFailure = 0; 0075 int m_coordinateConflicts = 0; 0076 int m_countryConflicts = 0; 0077 }; 0078 0079 } 0080 } 0081