From 5dbd5cdb379110cc915dd0936518b6abb93423e0 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sat, 22 Sep 2018 15:32:07 +0200 Subject: [PATCH 01/16] Added position queries for station engine --- src/engines/station/stationfactory.cpp | 79 +++++++++++++++++++- src/include/engines/station/stationfactory.h | 8 ++ 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/engines/station/stationfactory.cpp b/src/engines/station/stationfactory.cpp index 666ffbd..0eda623 100644 --- a/src/engines/station/stationfactory.cpp +++ b/src/engines/station/stationfactory.cpp @@ -78,8 +78,7 @@ StationEngine::Factory *StationEngine::Factory::getInstance() * In case something goes wrong, a StationEngine::NullStation instance is * returned. */ -StationEngine::Station * -StationEngine::Factory::getStationByURI(const QUrl &uri) +StationEngine::Station *StationEngine::Factory::getStationByURI(const QUrl &uri) { // Init StationEngine::Station variable StationEngine::Station *station; @@ -328,6 +327,82 @@ StationEngine::Factory::getStationByURI(const QUrl &uri) return station; } +/** + * @file stationfactory.cpp + * @author Dylan Van Assche + * @date 09 Aug 2018 + * @brief Retrieves a station by URI + * @param const QGeoCoordinate &position + * @param const qreal &radius + * @param const qint32 &maxResults + * @return QList &nearbyStations + * @package StationEngine + * @public + * @note The radius is defined in kilometres, with the given station as the centre of the circle. + * Fetches nearby stations from database using the Haversine formula (Google's solution). + * In case something goes wrong, a StationEngine::NullStation instance is + * pushed to the QList &nearbyStations. + */ +QList StationEngine::Factory::getNearbyStationsByPosition( + const QGeoCoordinate &position, + const qreal &radius, + const qint32 &maxResults) +{ + /* + * Fetch nearby stations from database using the Haversine formula (Google's solution) + * INFO: https://stackoverflow.com/questions/2234204/latitude-longitude-find-nearest-latitude-longitude-complex-sql-or-complex-calc + */ + Q_UNUSED(maxResults); // bypass compiler + QList nearbyStations = QList(); + QSqlQuery query(this->db()->database()); + + // SQLite doesn't support trigonometric functions, we have calculate the Haversine formula outside the SQL query. + query.prepare("SELECT " + "uri, " + "latitude, " + "longitude " + "FROM stations "); + this->db()->execute(query); + + //Read the results from the query + qreal latitudeRadianCenter = qDegreesToRadians(position.latitude()); + qreal longitudeRadianCenter = qDegreesToRadians(position.longitude()); + while (query.next()) { + // Using the field name in overload query.value(x) is less efficient then + // using indexes according to the Qt 5.6.3 docs + QUrl uri = query.value(0).toUrl(); + qreal latitudeStation = query.value(1).toReal(); + qreal longitudeStation = query.value(2).toReal(); + + qreal latitudeRadianStation = qDegreesToRadians(latitudeStation); + qreal longitudeRadianStation = qDegreesToRadians(longitudeStation); + + qreal differenceLatitude = latitudeRadianStation - latitudeRadianCenter; + qreal differenceLongitude = longitudeRadianStation - longitudeRadianCenter; + + // Haversine + qreal computation = qAsin(qSqrt(qSin(differenceLatitude / 2) * qSin(differenceLatitude / 2) + qCos( + latitudeRadianCenter) * qCos(latitudeRadianStation) * qSin(differenceLongitude / 2) * qSin( + differenceLongitude / 2))); + qreal distance = 2 * 6372.8 * computation; // Earth radius in km + if (distance < radius) { + QRail::StationEngine::Station *station = this->getStationByURI(uri); + nearbyStations.append(station); + //nearbyStations.append(QPair(nearbyStation, distance)); + //qDebug() << "Found nearby station:" << nearbyStation->name().value(QLocale::Dutch) << "distance:" << distance << "kilometres"; + } + } + + return nearbyStations; +} + +StationEngine::Station *StationEngine::Factory::getNearestStationByPosition( + const QGeoCoordinate &position) +{ + // We only need the nearest station, the list is automatically sorted by distance anyway. + return this->getNearbyStationsByPosition(position, SEARCH_RADIUS_NEAREST_STATION, 1).first(); +} + /** * @file stationfactory.cpp * @author Dylan Van Assche diff --git a/src/include/engines/station/stationfactory.h b/src/include/engines/station/stationfactory.h index 3022414..c5d5aa3 100644 --- a/src/include/engines/station/stationfactory.h +++ b/src/include/engines/station/stationfactory.h @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include #include "qrail.h" #include "engines/station/stationstation.h" @@ -40,6 +42,8 @@ // Uncomment to enable verbose output //#define VERBOSE_CACHE +#define SEARCH_RADIUS_NEAREST_STATION 3.0 // 3.0 km + namespace QRail { namespace StationEngine { class QRAIL_SHARED_EXPORT Factory : public QObject @@ -48,6 +52,10 @@ class QRAIL_SHARED_EXPORT Factory : public QObject public: static Factory *getInstance(); Station *getStationByURI(const QUrl &uri); + QList getNearbyStationsByPosition(const QGeoCoordinate &position, + const qreal &radius, + const qint32 &maxResults); + QRail::StationEngine::Station *getNearestStationByPosition(const QGeoCoordinate &position); private: QRail::Database::Manager *m_db; From ff7d8e58ac56788b2f9a73419b6cd619b90bfb23 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sat, 22 Sep 2018 15:33:43 +0200 Subject: [PATCH 02/16] Renamed obscure method --- src/engines/station/stationfactory.cpp | 2 +- src/include/engines/station/stationfactory.h | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/engines/station/stationfactory.cpp b/src/engines/station/stationfactory.cpp index 0eda623..aa3bfef 100644 --- a/src/engines/station/stationfactory.cpp +++ b/src/engines/station/stationfactory.cpp @@ -343,7 +343,7 @@ StationEngine::Station *StationEngine::Factory::getStationByURI(const QUrl &uri) * In case something goes wrong, a StationEngine::NullStation instance is * pushed to the QList &nearbyStations. */ -QList StationEngine::Factory::getNearbyStationsByPosition( +QList StationEngine::Factory::getStationsInTheAreaByPosition( const QGeoCoordinate &position, const qreal &radius, const qint32 &maxResults) diff --git a/src/include/engines/station/stationfactory.h b/src/include/engines/station/stationfactory.h index c5d5aa3..e8ff30f 100644 --- a/src/include/engines/station/stationfactory.h +++ b/src/include/engines/station/stationfactory.h @@ -52,9 +52,10 @@ class QRAIL_SHARED_EXPORT Factory : public QObject public: static Factory *getInstance(); Station *getStationByURI(const QUrl &uri); - QList getNearbyStationsByPosition(const QGeoCoordinate &position, - const qreal &radius, - const qint32 &maxResults); + QList getStationsInTheAreaByPosition( + const QGeoCoordinate &position, + const qreal &radius, + const qint32 &maxResults); QRail::StationEngine::Station *getNearestStationByPosition(const QGeoCoordinate &position); private: From 737c813c1c547368803c1ab66dd1a9166b77cbbb Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sat, 22 Sep 2018 16:01:08 +0200 Subject: [PATCH 03/16] WIP FootpathProfile --- qrail.pri | 6 ++- .../engines/router/routerfootpathprofile.cpp | 23 ++++++++++++ .../engines/router/routerfootpathprofile.h | 37 +++++++++++++++++++ src/include/engines/router/routerplanner.h | 1 + 4 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 src/include/engines/router/routerfootpathprofile.cpp create mode 100644 src/include/engines/router/routerfootpathprofile.h diff --git a/qrail.pri b/qrail.pri index 6eceb18..21678f1 100644 --- a/qrail.pri +++ b/qrail.pri @@ -47,7 +47,8 @@ SOURCES += \ $$PWD/src/fragments/fragmentspage.cpp \ $$PWD/src/fragments/fragmentsfactory.cpp \ $$PWD/src/fragments/fragmentsdispatcher.cpp \ - $$PWD/src/qrail.cpp + $$PWD/src/qrail.cpp \ + $$PWD/src/include/engines/router/routerfootpathprofile.cpp HEADERS += \ $$PWD/src/include/engines/alerts/alertsmessage.h \ @@ -74,7 +75,8 @@ HEADERS += \ $$PWD/src/include/fragments/fragmentsfactory.h \ $$PWD/src/include/fragments/fragmentsdispatcher.h \ $$PWD/qtcsv/include/qtcsv/stringdata.h \ - $$PWD/src/include/qrail.h + $$PWD/src/include/qrail.h \ + $$PWD/src/include/engines/router/routerfootpathprofile.h DISTFILES += \ $$PWD/rpm/qrail.changes diff --git a/src/include/engines/router/routerfootpathprofile.cpp b/src/include/engines/router/routerfootpathprofile.cpp new file mode 100644 index 0000000..c37b419 --- /dev/null +++ b/src/include/engines/router/routerfootpathprofile.cpp @@ -0,0 +1,23 @@ +/* + * This file is part of QRail. + * + * QRail is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QRail is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QRail. If not, see . + */ +#include "routerfootpathprofile.h" +using namespace QRail; + +RouterEngine::FootpathProfile::FootpathProfile(QObject *parent) : QObject(parent) +{ + +} diff --git a/src/include/engines/router/routerfootpathprofile.h b/src/include/engines/router/routerfootpathprofile.h new file mode 100644 index 0000000..e26539b --- /dev/null +++ b/src/include/engines/router/routerfootpathprofile.h @@ -0,0 +1,37 @@ +/* + * This file is part of QRail. + * + * QRail is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * QRail is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with QRail. If not, see . + */ +#ifndef ROUTERFOOTPATHPROFILE_H +#define ROUTERFOOTPATHPROFILE_H + +#include + +namespace QRail { +namespace RouterEngine { +class FootpathProfile : public QObject +{ + Q_OBJECT +public: + explicit FootpathProfile(QObject *parent = nullptr); + +signals: + +public slots: +}; +} +} + +#endif // ROUTERFOOTPATHPROFILE_H diff --git a/src/include/engines/router/routerplanner.h b/src/include/engines/router/routerplanner.h index eb4f01b..c9a87e2 100644 --- a/src/include/engines/router/routerplanner.h +++ b/src/include/engines/router/routerplanner.h @@ -98,6 +98,7 @@ class QRAIL_SHARED_EXPORT Planner : public QObject QList m_routes; QMap> m_SArray; QMap m_TArray; + QMap m_DArray; QList m_usedPages; explicit Planner(QObject *parent = nullptr); static QRail::RouterEngine::Planner *m_instance; From 26deacf8bd41739cfdaa4fb3642d52fbb18606e3 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sat, 22 Sep 2018 16:09:36 +0200 Subject: [PATCH 04/16] Fixed build --- qrail.pri | 4 +- rpm/qrail.spec.11186 | 63 +++++++++++++++++++ .../engines/router/routerfootpathprofile.cpp | 2 +- src/engines/station/stationfactory.cpp | 2 +- src/include/engines/router/routerplanner.h | 1 + 5 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 rpm/qrail.spec.11186 rename src/{include => }/engines/router/routerfootpathprofile.cpp (94%) diff --git a/qrail.pri b/qrail.pri index 21678f1..edb884f 100644 --- a/qrail.pri +++ b/qrail.pri @@ -32,6 +32,7 @@ SOURCES += \ $$PWD/src/engines/router/routerroutelegend.cpp \ $$PWD/src/engines/router/routerstationstopprofile.cpp \ $$PWD/src/engines/router/routertrainprofile.cpp \ + $$PWD/src/engines/router/routerfootpathprofile.cpp \ $$PWD/src/engines/liveboard/liveboardfactory.cpp \ $$PWD/src/engines/liveboard/liveboardboard.cpp \ $$PWD/src/engines/station/stationstation.cpp \ @@ -47,8 +48,7 @@ SOURCES += \ $$PWD/src/fragments/fragmentspage.cpp \ $$PWD/src/fragments/fragmentsfactory.cpp \ $$PWD/src/fragments/fragmentsdispatcher.cpp \ - $$PWD/src/qrail.cpp \ - $$PWD/src/include/engines/router/routerfootpathprofile.cpp + $$PWD/src/qrail.cpp HEADERS += \ $$PWD/src/include/engines/alerts/alertsmessage.h \ diff --git a/rpm/qrail.spec.11186 b/rpm/qrail.spec.11186 new file mode 100644 index 0000000..bb0ef30 --- /dev/null +++ b/rpm/qrail.spec.11186 @@ -0,0 +1,63 @@ +# +# This file is part of QRail. +# +# QRail is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# QRail is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with QRail. If not, see . +# + +Name: qrail + +%{!?qtc_qmake:%define qtc_qmake %qmake} +%{!?qtc_qmake5:%define qtc_qmake5 %qmake5} +%{!?qtc_make:%define qtc_make make} +%{?qtc_builddir:%define _builddir %qtc_builddir} +Summary: QRail +Version: 0.0.1 +Release: 1 +Group: Qt/Qt +License: GPLv3 +URL: https://dylanvanassche.be/ +Source0: %{name}-%{version}.tar.bz2 +BuildRequires: pkgconfig(Qt5Core) +BuildRequires: pkgconfig(Qt5Network) +BuildRequires: pkgconfig(Qt5Sql) +BuildRequires: pkgconfig(Qt5Positioning) +BuildRequires: pkgconfig(Qt5Concurrent) +BuildRequires: desktop-file-utils + +%description +QRail is a Qt library to access Linked Connections data resources. + +%prep +%setup -q -n %{name}-%{version} + +%build +%qtc_qmake5 \ + VERSION=%{version} +%qtc_make %{?_smp_mflags} + +%install +rm -rf %{buildroot} +%qmake5_install +desktop-file-install --delete-original \ + --dir %{buildroot}%{_datadir}/applications \ + %{buildroot}%{_datadir}/applications/*.desktop + +%files +%defattr(-,root,root,-) +%{_bindir} +%{_datadir}/%{name} +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/*/apps/%{name}.png +# >> files +# << files diff --git a/src/include/engines/router/routerfootpathprofile.cpp b/src/engines/router/routerfootpathprofile.cpp similarity index 94% rename from src/include/engines/router/routerfootpathprofile.cpp rename to src/engines/router/routerfootpathprofile.cpp index c37b419..7a87378 100644 --- a/src/include/engines/router/routerfootpathprofile.cpp +++ b/src/engines/router/routerfootpathprofile.cpp @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with QRail. If not, see . */ -#include "routerfootpathprofile.h" +#include "engines/router/routerfootpathprofile.h" using namespace QRail; RouterEngine::FootpathProfile::FootpathProfile(QObject *parent) : QObject(parent) diff --git a/src/engines/station/stationfactory.cpp b/src/engines/station/stationfactory.cpp index aa3bfef..c4d7976 100644 --- a/src/engines/station/stationfactory.cpp +++ b/src/engines/station/stationfactory.cpp @@ -400,7 +400,7 @@ StationEngine::Station *StationEngine::Factory::getNearestStationByPosition( const QGeoCoordinate &position) { // We only need the nearest station, the list is automatically sorted by distance anyway. - return this->getNearbyStationsByPosition(position, SEARCH_RADIUS_NEAREST_STATION, 1).first(); + return this->getStationsInTheAreaByPosition(position, SEARCH_RADIUS_NEAREST_STATION, 1).first(); } /** diff --git a/src/include/engines/router/routerplanner.h b/src/include/engines/router/routerplanner.h index c9a87e2..7ea8408 100644 --- a/src/include/engines/router/routerplanner.h +++ b/src/include/engines/router/routerplanner.h @@ -36,6 +36,7 @@ #include "engines/router/routerstationstopprofile.h" #include "engines/router/routertrainprofile.h" #include "engines/router/routertransfer.h" +#include "engines/router/routerfootpathprofile.h" #include "engines/station/stationfactory.h" #include "engines/station/stationstation.h" #include "fragments/fragmentsfactory.h" From b85a8f1aa228adc9b05c40efea0205614f96a67d Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 11:01:34 +0200 Subject: [PATCH 05/16] Requests pages only when init is really finished --- src/engines/liveboard/liveboardfactory.cpp | 3 ++- src/engines/router/routerplanner.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/engines/liveboard/liveboardfactory.cpp b/src/engines/liveboard/liveboardfactory.cpp index 596f345..54324d6 100644 --- a/src/engines/liveboard/liveboardfactory.cpp +++ b/src/engines/liveboard/liveboardfactory.cpp @@ -112,7 +112,6 @@ void QRail::LiveboardEngine::Factory::getLiveboardByStationURI(const QUrl &uri, this->setMode(mode); this->setFrom(from); this->setUntil(until); - this->fragmentsFactory()->getPage(this->until(), this); this->setLiveboard(new QRail::LiveboardEngine::Board(this)); this->liveboard()->setEntries(QList()); this->liveboard()->setFrom(this->from()); @@ -120,6 +119,8 @@ void QRail::LiveboardEngine::Factory::getLiveboardByStationURI(const QUrl &uri, this->liveboard()->setMode(this->mode()); this->liveboard()->setStation(this->stationFactory()->getStationByURI(this->stationURI())); this->initUsedPages(); + this->fragmentsFactory()->getPage(this->until(), this); + qApp->processEvents(); } // Helpers diff --git a/src/engines/router/routerplanner.cpp b/src/engines/router/routerplanner.cpp index eec07a7..97456d2 100644 --- a/src/engines/router/routerplanner.cpp +++ b/src/engines/router/routerplanner.cpp @@ -118,8 +118,9 @@ void QRail::RouterEngine::Planner::getConnections(const QUrl &departureStation, this->setArrivalTime(this->calculateArrivalTime(this->departureTime())); this->setMaxTransfers(maxTransfers); this->setRoutes(QList()); - this->fragmentsFactory()->getPage(this->arrivalTime(), this); this->initUsedPages(); + this->fragmentsFactory()->getPage(this->arrivalTime(), this); + qApp->processEvents(); qDebug() << "CSA init OK"; } From 6ff3dfa0f2f51be5b66bbfc383b65125ebf84e09 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 14:21:30 +0200 Subject: [PATCH 06/16] WIP benchmarking liveboard --- src/fragments/fragmentsfactory.cpp | 8 +++-- src/network/networkmanager.cpp | 8 +++-- .../liveboard/liveboardfactorytest.cpp | 31 +++++++++++-------- .../engines/liveboard/liveboardfactorytest.h | 2 -- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/fragments/fragmentsfactory.cpp b/src/fragments/fragmentsfactory.cpp index 4c2b439..af51077 100644 --- a/src/fragments/fragmentsfactory.cpp +++ b/src/fragments/fragmentsfactory.cpp @@ -33,6 +33,9 @@ QRail::Fragments::Factory::Factory(QObject *parent) : QObject(parent) { // Setup the QRail::Network::Manager this->setHttp(QRail::Network::Manager::getInstance()); + + // Setup dispatcher + this->setDispatcher(new QRail::Fragments::Dispatcher()); /* * QNAM and callers are living in different threads! * INFO: @@ -40,9 +43,6 @@ QRail::Fragments::Factory::Factory(QObject *parent) : QObject(parent) */ connect(this, SIGNAL(getResource(QUrl, QObject *)), this->http(), SLOT(getResource(QUrl, QObject *))); - - // Setup dispatcher - this->setDispatcher(new QRail::Fragments::Dispatcher()); } /** @@ -121,7 +121,9 @@ void QRail::Fragments::Factory::getPage(const QDateTime &departureTime, QObject void QRail::Fragments::Factory::customEvent(QEvent *event) { + qDebug() << "Received event in factory:" << event; if (event->type() == this->http()->dispatcher()->eventType()) { + qDebug() << "Network event!"; event->accept(); QRail::Network::DispatcherEvent *networkEvent = reinterpret_cast (event); diff --git a/src/network/networkmanager.cpp b/src/network/networkmanager.cpp index 284cbc0..647b032 100644 --- a/src/network/networkmanager.cpp +++ b/src/network/networkmanager.cpp @@ -32,6 +32,11 @@ QRail::Network::Manager::Manager(QObject *parent): QObject(parent) { // Initiate a new QNetworkAccessManager with cache this->setQNAM(new QNetworkAccessManager(this)); + + // Init the dispatcher + this->setDispatcher(new QRail::Network::Dispatcher(this)); + + // Init cache QNetworkConfigurationManager QNAMConfig; this->QNAM()->setConfiguration(QNAMConfig.defaultConfiguration()); this->setCache(new QNetworkDiskCache(this)); @@ -47,9 +52,6 @@ QRail::Network::Manager::Manager(QObject *parent): QObject(parent) ((QNetworkDiskCache *)this->cache())->setCacheDirectory(path); this->QNAM()->setCache(this->cache()); - // Init the dispatcher - this->setDispatcher(new QRail::Network::Dispatcher(this)); - // Connect QNetworkAccessManager signals connect(this->QNAM(), SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility))); diff --git a/tests/src/engines/liveboard/liveboardfactorytest.cpp b/tests/src/engines/liveboard/liveboardfactorytest.cpp index 6af061a..ea01c50 100644 --- a/tests/src/engines/liveboard/liveboardfactorytest.cpp +++ b/tests/src/engines/liveboard/liveboardfactorytest.cpp @@ -28,22 +28,27 @@ void LiveboardEngine::FactoryTest::initLiveboardFactoryTest() void QRail::LiveboardEngine::FactoryTest::runLiveboardFactoryTest() { qDebug() << "Running LiveboardEngine::Factory test"; + QBENCHMARK { + factory->getLiveboardByStationURI( + QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde + LiveboardEngine::Board::Mode::DEPARTURES); - // Activate QSignalSpy - qRegisterMetaType("QRail::LiveboardEngine::Board"); // register custom class - QSignalSpy spyLiveboard(factory, SIGNAL(finished(QRail::LiveboardEngine::Board *))); + // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events + QEventLoop loop1; + connect(factory, SIGNAL(finished(QRail::LiveboardEngine::Board *)), &loop1, SLOT(quit())); + loop1.exec(); + } - qDebug() << "Liveboard arrivals (now) for station Vilvoorde"; - factory->getLiveboardByStationURI( - QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde - LiveboardEngine::Board::Mode::ARRIVALS); - QVERIFY(spyLiveboard.wait(LIVEBOARD_WAIT_TIME)); + /*QBENCHMARK { + factory->getLiveboardByStationURI( + QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde + LiveboardEngine::Board::Mode::ARRIVALS); - qDebug() << "Liveboard departures (now) for station Vilvoorde"; - factory->getLiveboardByStationURI( - QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde - LiveboardEngine::Board::Mode::DEPARTURES); - QVERIFY(spyLiveboard.wait(LIVEBOARD_WAIT_TIME)); + // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events + QEventLoop loop2; + connect(factory, SIGNAL(finished(QRail::LiveboardEngine::Board *)), &loop2, SLOT(quit())); + loop2.exec(); + }*/ } void QRail::LiveboardEngine::FactoryTest::cleanLiveboardFactoryTest() diff --git a/tests/src/engines/liveboard/liveboardfactorytest.h b/tests/src/engines/liveboard/liveboardfactorytest.h index df28987..b5fc7b6 100644 --- a/tests/src/engines/liveboard/liveboardfactorytest.h +++ b/tests/src/engines/liveboard/liveboardfactorytest.h @@ -24,8 +24,6 @@ #include "engines/liveboard/liveboardfactory.h" -#define LIVEBOARD_WAIT_TIME 15000 - namespace QRail { namespace LiveboardEngine { class FactoryTest : public QObject From 15ae228a2009e22be42ffee5d4fdea3fd643cd55 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 15:02:24 +0200 Subject: [PATCH 07/16] QBENCHMARK macro introduced some weird side effects, removed it --- .../liveboard/liveboardfactorytest.cpp | 30 +++++++------------ .../src/engines/router/routerplannertest.cpp | 26 ++++++++-------- tests/src/engines/router/routerplannertest.h | 1 + 3 files changed, 26 insertions(+), 31 deletions(-) diff --git a/tests/src/engines/liveboard/liveboardfactorytest.cpp b/tests/src/engines/liveboard/liveboardfactorytest.cpp index ea01c50..1351a34 100644 --- a/tests/src/engines/liveboard/liveboardfactorytest.cpp +++ b/tests/src/engines/liveboard/liveboardfactorytest.cpp @@ -28,27 +28,19 @@ void LiveboardEngine::FactoryTest::initLiveboardFactoryTest() void QRail::LiveboardEngine::FactoryTest::runLiveboardFactoryTest() { qDebug() << "Running LiveboardEngine::Factory test"; - QBENCHMARK { - factory->getLiveboardByStationURI( - QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde - LiveboardEngine::Board::Mode::DEPARTURES); + QDateTime start = QDateTime::currentDateTime(); + factory->getLiveboardByStationURI( + QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde + LiveboardEngine::Board::Mode::DEPARTURES); - // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events - QEventLoop loop1; - connect(factory, SIGNAL(finished(QRail::LiveboardEngine::Board *)), &loop1, SLOT(quit())); - loop1.exec(); - } - - /*QBENCHMARK { - factory->getLiveboardByStationURI( - QUrl("http://irail.be/stations/NMBS/008811189"), // Vilvoorde - LiveboardEngine::Board::Mode::ARRIVALS); + // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events + QEventLoop loop; + connect(factory, SIGNAL(finished(QRail::LiveboardEngine::Board *)), &loop, SLOT(quit())); + loop.exec(); - // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events - QEventLoop loop2; - connect(factory, SIGNAL(finished(QRail::LiveboardEngine::Board *)), &loop2, SLOT(quit())); - loop2.exec(); - }*/ + qInfo() << "Liveboard Vilvoorde DEPARTURES took" + << (QDateTime::currentDateTime()).secsTo(start) + << "msecs"; } void QRail::LiveboardEngine::FactoryTest::cleanLiveboardFactoryTest() diff --git a/tests/src/engines/router/routerplannertest.cpp b/tests/src/engines/router/routerplannertest.cpp index ffc4413..f54011e 100644 --- a/tests/src/engines/router/routerplannertest.cpp +++ b/tests/src/engines/router/routerplannertest.cpp @@ -51,19 +51,21 @@ void QRail::RouterEngine::PlannerTest::runCSAPlannerTest() * https://lc2irail.thesis.bertmarcelis.be/connections/008811189/008891009/departing/2018-08-02T13:00:00+00:00 */ - QBENCHMARK { - planner->getConnections( - QUrl("http://irail.be/stations/NMBS/008811189"), // From: Vilvoorde - QUrl("http://irail.be/stations/NMBS/008891009"), // To: Brugge - QDateTime::fromString("2018-09-20T13:00:00.000Z", Qt::ISODate), // Departure time (UTC) - 4 // Max transfers - ); + QDateTime start = QDateTime::currentDateTime(); + planner->getConnections( + QUrl("http://irail.be/stations/NMBS/008811189"), // From: Vilvoorde + QUrl("http://irail.be/stations/NMBS/008891009"), // To: Brugge + QDateTime::fromString("2018-09-21T13:00:00.000Z", Qt::ISODate), // Departure time (UTC) + 4 // Max transfers + ); - // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events - QEventLoop loop; - connect(planner, SIGNAL(routesFound(QList)), &loop, SLOT(quit())); - loop.exec(); - } + // Start an eventloop to wait for the routesFound signal to allow benchmarking of asynchronous events + QEventLoop loop; + connect(planner, SIGNAL(routesFound(QList)), &loop, SLOT(quit())); + loop.exec(); + qInfo() << "Routing Vilvoorde -> Brugge took" + << (QDateTime::currentDateTime()).secsTo(start) + << "msecs"; } void QRail::RouterEngine::PlannerTest::cleanCSAPlannerTest() diff --git a/tests/src/engines/router/routerplannertest.h b/tests/src/engines/router/routerplannertest.h index c4ee92d..1116687 100644 --- a/tests/src/engines/router/routerplannertest.h +++ b/tests/src/engines/router/routerplannertest.h @@ -20,6 +20,7 @@ #include "engines/router/routerplanner.h" #include #include +#include #include #include From 96cd7caceafa9343959ccb5e9bed594a7d7fbede Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 15:04:18 +0200 Subject: [PATCH 08/16] Make benchmarking more precise --- tests/rpm/qrail-tests.spec.21080 | 65 +++++++++++++++++++ .../liveboard/liveboardfactorytest.cpp | 2 +- .../src/engines/router/routerplannertest.cpp | 3 +- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 tests/rpm/qrail-tests.spec.21080 diff --git a/tests/rpm/qrail-tests.spec.21080 b/tests/rpm/qrail-tests.spec.21080 new file mode 100644 index 0000000..a8190f2 --- /dev/null +++ b/tests/rpm/qrail-tests.spec.21080 @@ -0,0 +1,65 @@ +# +# This file is part of QRail. +# +# QRail is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# QRail is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with QRail. If not, see . +# + +Name: qrail-tests + +%{!?qtc_qmake:%define qtc_qmake %qmake} +%{!?qtc_qmake5:%define qtc_qmake5 %qmake5} +%{!?qtc_make:%define qtc_make make} +%{?qtc_builddir:%define _builddir %qtc_builddir} +Summary: QRail tests +Version: 0.0.1 +Release: 1 +Group: Qt/Qt +License: GPLv3 +URL: https://dylanvanassche.be/ +Source0: %{name}-%{version}.tar.bz2 +BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 +BuildRequires: pkgconfig(Qt5Core) +BuildRequires: pkgconfig(Qt5Network) +BuildRequires: pkgconfig(Qt5Sql) +BuildRequires: pkgconfig(Qt5Positioning) +BuildRequires: pkgconfig(Qt5Concurrent) +BuildRequires: pkgconfig(Qt5Quick) +BuildRequires: pkgconfig(Qt5Qml) +BuildRequires: pkgconfig(Qt5Test) +BuildRequires: desktop-file-utils + +%description +QRail unit tests for CI/CD purposes. + +%prep +%setup -q -n %{name}-%{version} + +%build + +%qtc_qmake5 +%qtc_make %{?_smp_mflags} + +%install +rm -rf %{buildroot} +%qmake5_install +desktop-file-install --delete-original \ + --dir %{buildroot}%{_datadir}/applications \ + %{buildroot}%{_datadir}/applications/*.desktop + +%files +%defattr(-,root,root,-) +%{_bindir} +%{_datadir}/%{name} +%{_datadir}/applications/%{name}.desktop +%{_datadir}/icons/hicolor/*/apps/%{name}.png diff --git a/tests/src/engines/liveboard/liveboardfactorytest.cpp b/tests/src/engines/liveboard/liveboardfactorytest.cpp index 1351a34..4c84a0c 100644 --- a/tests/src/engines/liveboard/liveboardfactorytest.cpp +++ b/tests/src/engines/liveboard/liveboardfactorytest.cpp @@ -39,7 +39,7 @@ void QRail::LiveboardEngine::FactoryTest::runLiveboardFactoryTest() loop.exec(); qInfo() << "Liveboard Vilvoorde DEPARTURES took" - << (QDateTime::currentDateTime()).secsTo(start) + << start.msecsTo(QDateTime::currentDateTime()) << "msecs"; } diff --git a/tests/src/engines/router/routerplannertest.cpp b/tests/src/engines/router/routerplannertest.cpp index f54011e..8b50e43 100644 --- a/tests/src/engines/router/routerplannertest.cpp +++ b/tests/src/engines/router/routerplannertest.cpp @@ -51,6 +51,7 @@ void QRail::RouterEngine::PlannerTest::runCSAPlannerTest() * https://lc2irail.thesis.bertmarcelis.be/connections/008811189/008891009/departing/2018-08-02T13:00:00+00:00 */ + QDateTime start = QDateTime::currentDateTime(); planner->getConnections( QUrl("http://irail.be/stations/NMBS/008811189"), // From: Vilvoorde @@ -64,7 +65,7 @@ void QRail::RouterEngine::PlannerTest::runCSAPlannerTest() connect(planner, SIGNAL(routesFound(QList)), &loop, SLOT(quit())); loop.exec(); qInfo() << "Routing Vilvoorde -> Brugge took" - << (QDateTime::currentDateTime()).secsTo(start) + << start.msecsTo(QDateTime::currentDateTime()) << "msecs"; } From c8ffb1de9d7ab94393ea7974e0efd4ad17c92c9a Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 15:20:14 +0200 Subject: [PATCH 09/16] Allow verbose output for event delay --- src/fragments/fragmentsfactory.cpp | 18 ++++--- src/include/fragments/fragmentsfactory.h | 2 + tests/rpm/qrail-tests.spec.21080 | 65 ------------------------ tests/src/qrail-tests.cpp | 6 +-- 4 files changed, 16 insertions(+), 75 deletions(-) delete mode 100644 tests/rpm/qrail-tests.spec.21080 diff --git a/src/fragments/fragmentsfactory.cpp b/src/fragments/fragmentsfactory.cpp index af51077..f686127 100644 --- a/src/fragments/fragmentsfactory.cpp +++ b/src/fragments/fragmentsfactory.cpp @@ -41,8 +41,8 @@ QRail::Fragments::Factory::Factory(QObject *parent) : QObject(parent) * INFO: * https://stackoverflow.com/questions/3268073/qobject-cannot-create-children-for-a-parent-that-is-in-a-different-thread */ - connect(this, SIGNAL(getResource(QUrl, QObject *)), this->http(), SLOT(getResource(QUrl, - QObject *))); + connect(this, SIGNAL(getResource(QUrl, QObject *)), + this->http(), SLOT(getResource(QUrl, QObject *))); } /** @@ -219,12 +219,16 @@ void QRail::Fragments::Factory::processHTTPReply(QNetworkReply *reply) { if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 200) { #ifdef VERBOSE_HTTP_STATUS - qDebug() << "Content-Header:" << reply->header(QNetworkRequest::ContentTypeHeader).toString(); - qDebug() << "Content-Length:" << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong() + qDebug() << "Content-Header:" + << reply->header(QNetworkRequest::ContentTypeHeader).toString(); + qDebug() << "Content-Length:" + << reply->header(QNetworkRequest::ContentLengthHeader).toULongLong() << "bytes"; - qDebug() << "HTTP status:" << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() << - reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(); - qDebug() << "Cache:" << reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(); + qDebug() << "HTTP status:" + << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() + << reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString(); + qDebug() << "Cache:" + << reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool(); #endif // Read HTTP reply diff --git a/src/include/fragments/fragmentsfactory.h b/src/include/fragments/fragmentsfactory.h index c11e432..6dca581 100644 --- a/src/include/fragments/fragmentsfactory.h +++ b/src/include/fragments/fragmentsfactory.h @@ -33,6 +33,8 @@ #define BASE_URL "https://graph.irail.be/sncb/connections" +#define VERBOSE_HTTP_STATUS // Show HTTP results + // Factory pattern to generate Linked Connections fragments on the fly namespace QRail { namespace Fragments { diff --git a/tests/rpm/qrail-tests.spec.21080 b/tests/rpm/qrail-tests.spec.21080 deleted file mode 100644 index a8190f2..0000000 --- a/tests/rpm/qrail-tests.spec.21080 +++ /dev/null @@ -1,65 +0,0 @@ -# -# This file is part of QRail. -# -# QRail is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# QRail is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with QRail. If not, see . -# - -Name: qrail-tests - -%{!?qtc_qmake:%define qtc_qmake %qmake} -%{!?qtc_qmake5:%define qtc_qmake5 %qmake5} -%{!?qtc_make:%define qtc_make make} -%{?qtc_builddir:%define _builddir %qtc_builddir} -Summary: QRail tests -Version: 0.0.1 -Release: 1 -Group: Qt/Qt -License: GPLv3 -URL: https://dylanvanassche.be/ -Source0: %{name}-%{version}.tar.bz2 -BuildRequires: pkgconfig(sailfishapp) >= 1.0.2 -BuildRequires: pkgconfig(Qt5Core) -BuildRequires: pkgconfig(Qt5Network) -BuildRequires: pkgconfig(Qt5Sql) -BuildRequires: pkgconfig(Qt5Positioning) -BuildRequires: pkgconfig(Qt5Concurrent) -BuildRequires: pkgconfig(Qt5Quick) -BuildRequires: pkgconfig(Qt5Qml) -BuildRequires: pkgconfig(Qt5Test) -BuildRequires: desktop-file-utils - -%description -QRail unit tests for CI/CD purposes. - -%prep -%setup -q -n %{name}-%{version} - -%build - -%qtc_qmake5 -%qtc_make %{?_smp_mflags} - -%install -rm -rf %{buildroot} -%qmake5_install -desktop-file-install --delete-original \ - --dir %{buildroot}%{_datadir}/applications \ - %{buildroot}%{_datadir}/applications/*.desktop - -%files -%defattr(-,root,root,-) -%{_bindir} -%{_datadir}/%{name} -%{_datadir}/applications/%{name}.desktop -%{_datadir}/icons/hicolor/*/apps/%{name}.png diff --git a/tests/src/qrail-tests.cpp b/tests/src/qrail-tests.cpp index 46f8c11..46df278 100644 --- a/tests/src/qrail-tests.cpp +++ b/tests/src/qrail-tests.cpp @@ -65,12 +65,12 @@ int main(int argc, char *argv[]) lcFragmentResult = QTest::qExec(&testSuiteLCFragment, 0, nullptr); lcPageResult = QTest::qExec(&testSuiteLCPage, 0, nullptr); - // Run QRail::RouterEngine::Planner integration test - routerPlannerResult = QTest::qExec(&testSuiteCSAPlanner, 0, nullptr); - // Run QRail::LiveboardEngine::Factory integration test liveboardFactoryResult = QTest::qExec(&testSuiteLiveboardFactory, 0, nullptr); + // Run QRail::RouterEngine::Planner integration test + routerPlannerResult = QTest::qExec(&testSuiteCSAPlanner, 0, nullptr); + // Run QRail::LiveboardEngine::Factory integration test vehicleFactoryResult = QTest::qExec(&testSuiteVehicleFactory, 0, nullptr); From 0682e124c721e4939f567ac63c58a566d4c6444c Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 15:46:56 +0200 Subject: [PATCH 10/16] More verbose output for fragment dispatching --- src/fragments/fragmentsdispatcher.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragments/fragmentsdispatcher.cpp b/src/fragments/fragmentsdispatcher.cpp index 53242e5..64d1bf4 100644 --- a/src/fragments/fragmentsdispatcher.cpp +++ b/src/fragments/fragmentsdispatcher.cpp @@ -54,6 +54,7 @@ void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) foreach (QObject *caller, callerList) { QCoreApplication::postEvent(caller, event); } + qDebug() << "Dispatched page to" << callerList; // Trigger event processing, without this we might have race conditions where event processing is taking too long qApp->processEvents(); @@ -81,8 +82,7 @@ QList QRail::Fragments::Dispatcher::findAndRemoveTargets(const QDateT foreach (QDateTime timestamp, m_targets.keys()) { if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) && (timestamp.toMSecsSinceEpoch() <= until.toMSecsSinceEpoch())) { - callers.append(m_targets.value(timestamp)); - m_targets.remove(timestamp); + callers.append(m_targets.take(timestamp)); } } return callers; From 6e06bd23253b14ec5a7db2f05cc65fffe81ccf1e Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 17:35:01 +0200 Subject: [PATCH 11/16] WIP fixing dispatching errors in Fragments::Factory --- src/fragments/fragmentsdispatcher.cpp | 30 ++++++++++++++++++--- src/include/fragments/fragmentsdispatcher.h | 6 ++++- src/include/network/networkdispatcher.h | 3 +++ src/network/networkdispatcher.cpp | 6 +++++ 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/fragments/fragmentsdispatcher.cpp b/src/fragments/fragmentsdispatcher.cpp index 64d1bf4..a0bfaeb 100644 --- a/src/fragments/fragmentsdispatcher.cpp +++ b/src/fragments/fragmentsdispatcher.cpp @@ -19,7 +19,11 @@ using namespace QRail; QRail::Fragments::Dispatcher::Dispatcher(QObject *parent) : QObject(parent) { + // Register a custom event type to the Qt event system this->setEventType(static_cast(QEvent::registerEventType())); + + // Init target list + m_targets = QList(); } void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) @@ -48,13 +52,16 @@ void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) */ QDateTime from = page->fragments().first()->departureTime(); QDateTime until = page->fragments().last()->departureTime(); - QList callerList = this->findAndRemoveTargets(from, until); + qDebug() << m_targets; + QList callerList = this->findTargets(from, until); // Post the event to the event queue foreach (QObject *caller, callerList) { QCoreApplication::postEvent(caller, event); } qDebug() << "Dispatched page to" << callerList; + this->removeTargets(from, until); + qDebug() << "Removed targets"; // Trigger event processing, without this we might have race conditions where event processing is taking too long qApp->processEvents(); @@ -72,22 +79,37 @@ void QRail::Fragments::DispatcherEvent::setPage(QRail::Fragments::Page *page) void QRail::Fragments::Dispatcher::addTarget(const QDateTime &departureTime, QObject *caller) { + QMutexLocker locker(targetListLocker); m_targets.insert(departureTime, caller); } -QList QRail::Fragments::Dispatcher::findAndRemoveTargets(const QDateTime &from, - const QDateTime &until) +QList QRail::Fragments::Dispatcher::findTargets(const QDateTime &from, + const QDateTime &until) { + QMutexLocker locker(targetListLocker); QList callers = QList(); foreach (QDateTime timestamp, m_targets.keys()) { if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) && (timestamp.toMSecsSinceEpoch() <= until.toMSecsSinceEpoch())) { - callers.append(m_targets.take(timestamp)); + callers.append(m_targets.value(timestamp)); } } return callers; } +void QRail::Fragments::Dispatcher::removeTarget(const QDateTime &from, + const QDateTime &until) +{ + QMutexLocker locker(targetListLocker); + QList callers = QList(); + foreach (QDateTime timestamp, m_targets.keys()) { + if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) + && (timestamp.toMSecsSinceEpoch() <= until.toMSecsSinceEpoch())) { + callers.append(m_targets.take(timestamp)); + } + } +} + QEvent::Type QRail::Fragments::Dispatcher::eventType() const { return m_eventType; diff --git a/src/include/fragments/fragmentsdispatcher.h b/src/include/fragments/fragmentsdispatcher.h index bcde816..21990bf 100644 --- a/src/include/fragments/fragmentsdispatcher.h +++ b/src/include/fragments/fragmentsdispatcher.h @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include "fragments/fragmentspage.h" @@ -48,10 +50,12 @@ class Dispatcher : public QObject explicit Dispatcher(QObject *parent = nullptr); void dispatchPage(QRail::Fragments::Page *page); void addTarget(const QDateTime &departureTime, QObject *caller); - QList findAndRemoveTargets(const QDateTime &from, const QDateTime &until); + void removeTargets(const QDateTime &from, const QDateTime &until); + QList findTargets(const QDateTime &from, const QDateTime &until); QEvent::Type eventType() const; private: + mutable QMutex targetListLocker; QMap m_targets; QEvent::Type m_eventType; void setEventType(const QEvent::Type &eventType); diff --git a/src/include/network/networkdispatcher.h b/src/include/network/networkdispatcher.h index a3b4822..f4bdac2 100644 --- a/src/include/network/networkdispatcher.h +++ b/src/include/network/networkdispatcher.h @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include namespace QRail { @@ -60,6 +62,7 @@ class Dispatcher : public QObject QEvent::Type eventType() const; private: + QMutex targetListLocker; QMap m_targets; QEvent::Type m_eventType; void setEventType(const QEvent::Type &eventType); diff --git a/src/network/networkdispatcher.cpp b/src/network/networkdispatcher.cpp index 91c6245..b0593db 100644 --- a/src/network/networkdispatcher.cpp +++ b/src/network/networkdispatcher.cpp @@ -21,6 +21,9 @@ QRail::Network::Dispatcher::Dispatcher(QObject *parent) : QObject(parent) { // Register a custom event type to the Qt event system this->setEventType(static_cast(QEvent::registerEventType())); + + // Init target list + m_targets = QList(); } void QRail::Network::Dispatcher::dispatchReply(QNetworkReply *reply) @@ -51,16 +54,19 @@ void QRail::Network::Dispatcher::dispatchReply(QNetworkReply *reply) void QRail::Network::Dispatcher::addTarget(QNetworkReply *reply, QObject *caller) { + QMutexLocker locker(targetListLocker); m_targets.insert(reply, caller); } void QRail::Network::Dispatcher::removeTarget(QNetworkReply *reply) { + QMutexLocker locker(targetListLocker); m_targets.remove(reply); } QObject *QRail::Network::Dispatcher::findTarget(QNetworkReply *reply) { + QMutexLocker locker(targetListLocker); return m_targets.value(reply); } From 30241b6f2fe9fd9e56a2c589949137be4a06f4fa Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 17:54:06 +0200 Subject: [PATCH 12/16] Fixed build --- src/fragments/fragmentsdispatcher.cpp | 15 ++++++--------- src/network/networkdispatcher.cpp | 9 +++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/fragments/fragmentsdispatcher.cpp b/src/fragments/fragmentsdispatcher.cpp index a0bfaeb..d615dba 100644 --- a/src/fragments/fragmentsdispatcher.cpp +++ b/src/fragments/fragmentsdispatcher.cpp @@ -21,9 +21,6 @@ QRail::Fragments::Dispatcher::Dispatcher(QObject *parent) : QObject(parent) { // Register a custom event type to the Qt event system this->setEventType(static_cast(QEvent::registerEventType())); - - // Init target list - m_targets = QList(); } void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) @@ -52,7 +49,7 @@ void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) */ QDateTime from = page->fragments().first()->departureTime(); QDateTime until = page->fragments().last()->departureTime(); - qDebug() << m_targets; + qDebug() << m_targets; // DEBUG QList callerList = this->findTargets(from, until); // Post the event to the event queue @@ -79,14 +76,14 @@ void QRail::Fragments::DispatcherEvent::setPage(QRail::Fragments::Page *page) void QRail::Fragments::Dispatcher::addTarget(const QDateTime &departureTime, QObject *caller) { - QMutexLocker locker(targetListLocker); + QMutexLocker locker(&targetListLocker); m_targets.insert(departureTime, caller); } QList QRail::Fragments::Dispatcher::findTargets(const QDateTime &from, const QDateTime &until) { - QMutexLocker locker(targetListLocker); + QMutexLocker locker(&targetListLocker); QList callers = QList(); foreach (QDateTime timestamp, m_targets.keys()) { if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) @@ -97,10 +94,10 @@ QList QRail::Fragments::Dispatcher::findTargets(const QDateTime &from return callers; } -void QRail::Fragments::Dispatcher::removeTarget(const QDateTime &from, - const QDateTime &until) +void QRail::Fragments::Dispatcher::removeTargets(const QDateTime &from, + const QDateTime &until) { - QMutexLocker locker(targetListLocker); + QMutexLocker locker(&targetListLocker); QList callers = QList(); foreach (QDateTime timestamp, m_targets.keys()) { if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) diff --git a/src/network/networkdispatcher.cpp b/src/network/networkdispatcher.cpp index b0593db..65b181f 100644 --- a/src/network/networkdispatcher.cpp +++ b/src/network/networkdispatcher.cpp @@ -21,9 +21,6 @@ QRail::Network::Dispatcher::Dispatcher(QObject *parent) : QObject(parent) { // Register a custom event type to the Qt event system this->setEventType(static_cast(QEvent::registerEventType())); - - // Init target list - m_targets = QList(); } void QRail::Network::Dispatcher::dispatchReply(QNetworkReply *reply) @@ -54,19 +51,19 @@ void QRail::Network::Dispatcher::dispatchReply(QNetworkReply *reply) void QRail::Network::Dispatcher::addTarget(QNetworkReply *reply, QObject *caller) { - QMutexLocker locker(targetListLocker); + QMutexLocker locker(&targetListLocker); m_targets.insert(reply, caller); } void QRail::Network::Dispatcher::removeTarget(QNetworkReply *reply) { - QMutexLocker locker(targetListLocker); + QMutexLocker locker(&targetListLocker); m_targets.remove(reply); } QObject *QRail::Network::Dispatcher::findTarget(QNetworkReply *reply) { - QMutexLocker locker(targetListLocker); + QMutexLocker locker(&targetListLocker); return m_targets.value(reply); } From 6249678f9448903b8ad1ea25ed2c985bde714a68 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 20:20:26 +0200 Subject: [PATCH 13/16] WIP CSA profile footpaths + bumped version --- qrail.pro | 2 +- rpm/qrail.spec | 2 +- src/engines/router/routerfootpathprofile.cpp | 40 +++++++++++- src/engines/router/routerplanner.cpp | 63 +++++++++++++++++-- src/engines/station/stationfactory.cpp | 56 ++++++++++++----- src/fragments/fragmentsdispatcher.cpp | 8 ++- .../engines/router/routerfootpathprofile.h | 20 ++++-- src/include/engines/router/routerplanner.h | 9 ++- src/include/engines/station/stationfactory.h | 12 ++-- src/network/networkmanager.cpp | 13 ++-- 10 files changed, 182 insertions(+), 43 deletions(-) diff --git a/qrail.pro b/qrail.pro index 1fe9c66..d8ae877 100644 --- a/qrail.pro +++ b/qrail.pro @@ -16,7 +16,7 @@ # TARGET = qrail -VERSION = 0.0.1 +VERSION = 0.0.2 # Uncomment this config if you want to build a static library CONFIG += staticlib diff --git a/rpm/qrail.spec b/rpm/qrail.spec index bb0ef30..6abfb77 100644 --- a/rpm/qrail.spec +++ b/rpm/qrail.spec @@ -22,7 +22,7 @@ Name: qrail %{!?qtc_make:%define qtc_make make} %{?qtc_builddir:%define _builddir %qtc_builddir} Summary: QRail -Version: 0.0.1 +Version: 0.0.2 Release: 1 Group: Qt/Qt License: GPLv3 diff --git a/src/engines/router/routerfootpathprofile.cpp b/src/engines/router/routerfootpathprofile.cpp index 7a87378..85539aa 100644 --- a/src/engines/router/routerfootpathprofile.cpp +++ b/src/engines/router/routerfootpathprofile.cpp @@ -17,7 +17,45 @@ #include "engines/router/routerfootpathprofile.h" using namespace QRail; -RouterEngine::FootpathProfile::FootpathProfile(QObject *parent) : QObject(parent) +RouterEngine::FootpathProfile::FootpathProfile(StationEngine::Station *arrivalStation, + StationEngine::Station *departureStation, + qreal distance, + QObject *parent) : QObject(parent) { + // Use private members to avoid signal fire on construction + m_arrivalStation = arrivalStation; + m_departureStation = departureStation; + m_distance = distance; +} +// Getters & Setters +qreal RouterEngine::FootpathProfile::distance() const +{ + return m_distance; +} + +void RouterEngine::FootpathProfile::setDistance(const qreal &distance) +{ + m_distance = distance; +} + +QRail::StationEngine::Station *RouterEngine::FootpathProfile::departureStation() const +{ + return m_departureStation; +} + +void RouterEngine::FootpathProfile::setDepartureStation(QRail::StationEngine::Station + *departureStation) +{ + m_departureStation = departureStation; +} + +QRail::StationEngine::Station *RouterEngine::FootpathProfile::arrivalStation() const +{ + return m_arrivalStation; +} + +void RouterEngine::FootpathProfile::setArrivalStation(QRail::StationEngine::Station *arrivalStation) +{ + m_arrivalStation = arrivalStation; } diff --git a/src/engines/router/routerplanner.cpp b/src/engines/router/routerplanner.cpp index 97456d2..4154734 100644 --- a/src/engines/router/routerplanner.cpp +++ b/src/engines/router/routerplanner.cpp @@ -112,6 +112,9 @@ void QRail::RouterEngine::Planner::getConnections(const QUrl &departureStation, plannerProcessingMutex.lock(); // Queue requests this->setTArray(QMap()); this->setSArray(QMap>()); + QMap DArray = this->DArray(); + DArray.clear(); + this->setDArray(DArray); this->setDepartureStationURI(departureStation); this->setArrivalStationURI(arrivalStation); this->setDepartureTime(departureTime); @@ -119,6 +122,29 @@ void QRail::RouterEngine::Planner::getConnections(const QUrl &departureStation, this->setMaxTransfers(maxTransfers); this->setRoutes(QList()); this->initUsedPages(); + + /* + * Setup footpaths for the arrival station since CSA profile + * goes from the end to the beginning. + * + * Footpaths give the user the possibility to exit at another station + * and walk to it's destination in case that's faster than the original + * arrival station. + */ + QRail::StationEngine::Station *station = + this->stationFactory()->getStationByURI(this->arrivalStationURI()); + + QList> nearbyStations = + this->stationFactory()->getStationsInTheAreaByPosition(station->position(), + SEARCH_RADIUS, + MAX_RESULTS); + for (qint32 i = 0; i < nearbyStations.length(); i++) { + QPair stationDistancePair = nearbyStations.at(i); + this->DArray().insert(stationDistancePair.first->uri(), stationDistancePair.second); + } + qDebug() << this->DArray(); + + // Jumpstart the page fetching this->fragmentsFactory()->getPage(this->arrivalTime(), this); qApp->processEvents(); qDebug() << "CSA init OK"; @@ -214,14 +240,21 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) *newExitTrainFragment; // Save the connection when we exit the train for a transfer // Calculate T1, the time when walking from the current stop to the destination - if (fragment->arrivalStationURI() == this->arrivalStationURI()) { + if (fragment->arrivalStationURI() == this->arrivalStationURI() + && this->DArray().contains(fragment->arrivalStationURI())) { /* * This connection ends at our destination. - * We can walk now out of the station, our implementation doesn't cover - * the footpath at the end (yet) + * We can walk now out of the station towards our destination. + * The time to arrive is the arrival time in the station + * + the walking time of the footpath to our destination. + * + * WARNING: The D array stores distances, we need to divide + * them by a given WALKING_SPEED before adding them to the + * T1_walkingArrivalTime! */ - T1_walkingArrivalTime = fragment->arrivalTime(); // Due the footpath limitation, we arrive at - // our destination when we arrive with the vehicle. + T1_walkingArrivalTime = fragment->arrivalTime().addSecs( + (this->DArray().value(fragment->arrivalStationURI()) / WALKING_SPEED) + * SECONDS_TO_HOURS_MULTIPLIER); T1_transfers = 0; // Walking, no transfers between arrival and destination. } else { /* @@ -544,7 +577,7 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) * UPDATING THE S ARRAY * ==================================== * Create a new StationStopProfile to update the S array. - * The existing CSAStationStopProfiles shouldn't dominate our + * The existing StationStopProfiles shouldn't dominate our * StationStopProfile. This is automatically the case since the new * departure time is always less or equal than the ones already stored in * the S array (departures are sorted by DESCENDING departure times). @@ -614,6 +647,14 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) this->setSArray(S); } + /* + * Inserting possible footpaths into the S array. + * if (c_deptime, Tc) is non-dominated in profile of S[c_depstop] then: + * for all footpaths f with f_arrstop = c_depstop do: + * incorporate (c_deptime - f_dur, Tc) into profile of S[f_depstop]; + */ + + #ifdef VERBOSE_S_ARRAY qDebug() << "S-ARRAY"; foreach (QUrl k, this->SArray().keys()) { @@ -1205,6 +1246,16 @@ void QRail::RouterEngine::Planner::setTArray(const QMap RouterEngine::Planner::DArray() const +{ + return m_DArray; +} + +void RouterEngine::Planner::setDArray(const QMap &DArray) +{ + m_DArray = DArray; +} + void RouterEngine::Planner::addToUsedPages(Fragments::Page *page) { m_usedPages.append(page); diff --git a/src/engines/station/stationfactory.cpp b/src/engines/station/stationfactory.cpp index c4d7976..05f5845 100644 --- a/src/engines/station/stationfactory.cpp +++ b/src/engines/station/stationfactory.cpp @@ -341,19 +341,21 @@ StationEngine::Station *StationEngine::Factory::getStationByURI(const QUrl &uri) * @note The radius is defined in kilometres, with the given station as the centre of the circle. * Fetches nearby stations from database using the Haversine formula (Google's solution). * In case something goes wrong, a StationEngine::NullStation instance is - * pushed to the QList &nearbyStations. + * pushed to the QList> &nearbyStations. */ -QList StationEngine::Factory::getStationsInTheAreaByPosition( - const QGeoCoordinate &position, - const qreal &radius, - const qint32 &maxResults) +QList> + StationEngine::Factory::getStationsInTheAreaByPosition( + const QGeoCoordinate &position, + const qreal &radius, + const qint32 &maxResults) { /* * Fetch nearby stations from database using the Haversine formula (Google's solution) * INFO: https://stackoverflow.com/questions/2234204/latitude-longitude-find-nearest-latitude-longitude-complex-sql-or-complex-calc */ Q_UNUSED(maxResults); // bypass compiler - QList nearbyStations = QList(); + QList> nearbyStations = + QList>(); QSqlQuery query(this->db()->database()); // SQLite doesn't support trigonometric functions, we have calculate the Haversine formula outside the SQL query. @@ -373,34 +375,54 @@ QList StationEngine::Factory::getStationsInTheA QUrl uri = query.value(0).toUrl(); qreal latitudeStation = query.value(1).toReal(); qreal longitudeStation = query.value(2).toReal(); - qreal latitudeRadianStation = qDegreesToRadians(latitudeStation); qreal longitudeRadianStation = qDegreesToRadians(longitudeStation); + // Don't return stations that are the same as the center of our search radius + if (latitudeRadianStation != latitudeRadianCenter + && longitudeRadianStation != longitudeRadianCenter) { + continue; + } + qreal differenceLatitude = latitudeRadianStation - latitudeRadianCenter; qreal differenceLongitude = longitudeRadianStation - longitudeRadianCenter; // Haversine - qreal computation = qAsin(qSqrt(qSin(differenceLatitude / 2) * qSin(differenceLatitude / 2) + qCos( - latitudeRadianCenter) * qCos(latitudeRadianStation) * qSin(differenceLongitude / 2) * qSin( - differenceLongitude / 2))); + qreal computation = qAsin(qSqrt(qSin(differenceLatitude / 2) + * qSin(differenceLatitude / 2) + + qCos(latitudeRadianCenter) + * qCos(latitudeRadianStation) + * qSin(differenceLongitude / 2) + * qSin(differenceLongitude / 2))); qreal distance = 2 * 6372.8 * computation; // Earth radius in km if (distance < radius) { - QRail::StationEngine::Station *station = this->getStationByURI(uri); - nearbyStations.append(station); - //nearbyStations.append(QPair(nearbyStation, distance)); - //qDebug() << "Found nearby station:" << nearbyStation->name().value(QLocale::Dutch) << "distance:" << distance << "kilometres"; + QPair stationDistancePair; + stationDistancePair.first = this->getStationByURI(uri); + stationDistancePair.second = distance; + + nearbyStations.append(stationDistancePair); + qDebug() << "Found station" << stationDistancePair.first->name().value( + QLocale::Language::Dutch) << "distance" << distance << "km"; } } + std::sort(nearbyStations.begin(), nearbyStations.end(), []( + QPair a, + QPair b) -> bool { + qreal distanceA = a.second; + qreal distanceB = b.second; + return distanceA < distanceB; + }); + return nearbyStations; } -StationEngine::Station *StationEngine::Factory::getNearestStationByPosition( - const QGeoCoordinate &position) +QPair StationEngine::Factory::getNearestStationByPosition( + const QGeoCoordinate &position, + const qreal radius) { // We only need the nearest station, the list is automatically sorted by distance anyway. - return this->getStationsInTheAreaByPosition(position, SEARCH_RADIUS_NEAREST_STATION, 1).first(); + return this->getStationsInTheAreaByPosition(position, radius, 1).first(); } /** diff --git a/src/fragments/fragmentsdispatcher.cpp b/src/fragments/fragmentsdispatcher.cpp index d615dba..ac87956 100644 --- a/src/fragments/fragmentsdispatcher.cpp +++ b/src/fragments/fragmentsdispatcher.cpp @@ -52,6 +52,11 @@ void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) qDebug() << m_targets; // DEBUG QList callerList = this->findTargets(from, until); + // We should have retrieved some callers to dispatch the page to + if (callerList.isEmpty()) { + qCritical() << "No callers found for dispatching page:" << page->uri(); + } + // Post the event to the event queue foreach (QObject *caller, callerList) { QCoreApplication::postEvent(caller, event); @@ -98,11 +103,10 @@ void QRail::Fragments::Dispatcher::removeTargets(const QDateTime &from, const QDateTime &until) { QMutexLocker locker(&targetListLocker); - QList callers = QList(); foreach (QDateTime timestamp, m_targets.keys()) { if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) && (timestamp.toMSecsSinceEpoch() <= until.toMSecsSinceEpoch())) { - callers.append(m_targets.take(timestamp)); + m_targets.remove(timestamp); } } } diff --git a/src/include/engines/router/routerfootpathprofile.h b/src/include/engines/router/routerfootpathprofile.h index e26539b..8fdeabc 100644 --- a/src/include/engines/router/routerfootpathprofile.h +++ b/src/include/engines/router/routerfootpathprofile.h @@ -19,17 +19,29 @@ #include +#include "engines/station/stationstation.h" + namespace QRail { namespace RouterEngine { class FootpathProfile : public QObject { Q_OBJECT public: - explicit FootpathProfile(QObject *parent = nullptr); - -signals: + explicit FootpathProfile(QRail::StationEngine::Station *arrivalStation, + QRail::StationEngine::Station *departureStation, + qreal distance, + QObject *parent = nullptr); + QRail::StationEngine::Station *arrivalStation() const; + void setArrivalStation(QRail::StationEngine::Station *arrivalStation); + QRail::StationEngine::Station *departureStation() const; + void setDepartureStation(QRail::StationEngine::Station *departureStation); + qreal distance() const; + void setDistance(const qreal &distance); -public slots: +private: + QRail::StationEngine::Station *m_arrivalStation; + QRail::StationEngine::Station *m_departureStation; + qreal m_distance; }; } } diff --git a/src/include/engines/router/routerplanner.h b/src/include/engines/router/routerplanner.h index 7ea8408..ffb1dac 100644 --- a/src/include/engines/router/routerplanner.h +++ b/src/include/engines/router/routerplanner.h @@ -36,7 +36,6 @@ #include "engines/router/routerstationstopprofile.h" #include "engines/router/routertrainprofile.h" #include "engines/router/routertransfer.h" -#include "engines/router/routerfootpathprofile.h" #include "engines/station/stationfactory.h" #include "engines/station/stationstation.h" #include "fragments/fragmentsfactory.h" @@ -58,6 +57,10 @@ #define SECONDS_TO_HOURS_MULTIPLIER 3600 // 3600 seconds = 1 hour #define MINIMUM_PROGRESS_INCREMENT 1.0 // 1.0 = 1% +#define SEARCH_RADIUS 3.0 // 3.0 km +#define MAX_RESULTS 5 // 5 results maximum +#define WALKING_SPEED 5.0 // 5.0 km/h + // Singleton pattern namespace QRail { namespace RouterEngine { @@ -99,7 +102,7 @@ class QRAIL_SHARED_EXPORT Planner : public QObject QList m_routes; QMap> m_SArray; QMap m_TArray; - QMap m_DArray; + QMap m_DArray; QList m_usedPages; explicit Planner(QObject *parent = nullptr); static QRail::RouterEngine::Planner *m_instance; @@ -116,6 +119,8 @@ class QRAIL_SHARED_EXPORT Planner : public QObject void setSArray(const QMap> &SArray); QMap TArray() const; void setTArray(const QMap &TArray); + QMap DArray() const; + void setDArray(const QMap &DArray); void addToUsedPages(QRail::Fragments::Page *page); void deleteUsedPages(); void initUsedPages(); diff --git a/src/include/engines/station/stationfactory.h b/src/include/engines/station/stationfactory.h index e8ff30f..5ba0252 100644 --- a/src/include/engines/station/stationfactory.h +++ b/src/include/engines/station/stationfactory.h @@ -27,8 +27,10 @@ #include #include #include +#include #include #include +#include #include "qrail.h" #include "engines/station/stationstation.h" @@ -52,11 +54,13 @@ class QRAIL_SHARED_EXPORT Factory : public QObject public: static Factory *getInstance(); Station *getStationByURI(const QUrl &uri); - QList getStationsInTheAreaByPosition( + QList> getStationsInTheAreaByPosition( + const QGeoCoordinate &position, + const qreal &radius, + const qint32 &maxResults); + QPair getNearestStationByPosition( const QGeoCoordinate &position, - const qreal &radius, - const qint32 &maxResults); - QRail::StationEngine::Station *getNearestStationByPosition(const QGeoCoordinate &position); + const qreal radius); private: QRail::Database::Manager *m_db; diff --git a/src/network/networkmanager.cpp b/src/network/networkmanager.cpp index 647b032..a195582 100644 --- a/src/network/networkmanager.cpp +++ b/src/network/networkmanager.cpp @@ -55,13 +55,16 @@ QRail::Network::Manager::Manager(QObject *parent): QObject(parent) // Connect QNetworkAccessManager signals connect(this->QNAM(), SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility)), this, SIGNAL(networkAccessibleChanged(QNetworkAccessManager::NetworkAccessibility))); - connect(this->QNAM(), SIGNAL(sslErrors(QNetworkReply *, QList)), this, - SIGNAL(sslErrorsReceived(QNetworkReply *, QList))); - connect(this->QNAM(), SIGNAL(finished(QNetworkReply *)), this, - SLOT(requestCompleted(QNetworkReply *))); + connect(this->QNAM(), SIGNAL(sslErrors(QNetworkReply *, QList)), + this, SIGNAL(sslErrorsReceived(QNetworkReply *, QList))); + connect(this->QNAM(), SIGNAL(finished(QNetworkReply *)), + this, SLOT(requestCompleted(QNetworkReply *))); // Create HTTP client information - this->setUserAgent(QString("%1/%2 (%3/%4)").arg("QRail-LC", "0.0.1", "Sailfish OS", "2.2.0.29")); + this->setUserAgent(QString("%1/%2 (%3/%4)").arg("QRail-LC", + "0.0.2", + "Sailfish OS", + "2.2.1.18")); this->setAcceptHeader(QString("application/ld+json")); } From ec51945a02e7bab287d373310ce845cfb6a3286f Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Sun, 23 Sep 2018 20:51:13 +0200 Subject: [PATCH 14/16] Finally fixed dispatching bug --- src/fragments/fragmentsdispatcher.cpp | 12 +++++++++++- src/include/fragments/fragmentsdispatcher.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/fragments/fragmentsdispatcher.cpp b/src/fragments/fragmentsdispatcher.cpp index ac87956..f4ad092 100644 --- a/src/fragments/fragmentsdispatcher.cpp +++ b/src/fragments/fragmentsdispatcher.cpp @@ -91,8 +91,18 @@ QList QRail::Fragments::Dispatcher::findTargets(const QDateTime &from QMutexLocker locker(&targetListLocker); QList callers = QList(); foreach (QDateTime timestamp, m_targets.keys()) { + /* + * If the timestamp is the same or higher or equal than the first fragment departure time + * and it's lower than the last fragment departure time + 1 minute. + * + * WARNING: We need to add 1 minute to this check to avoid a reace condition: + * If the page ends at 19:28:00.000 (departure time of the last fragment) + * and we request the page at 19:28:35.841 then our check needs to valid. + * The reason for this lies in the way the Linked Connection server fragments + * the data and how it's redirecting clients. + */ if ((timestamp.toMSecsSinceEpoch() >= from.toMSecsSinceEpoch()) - && (timestamp.toMSecsSinceEpoch() <= until.toMSecsSinceEpoch())) { + && (timestamp.toMSecsSinceEpoch() < until.toMSecsSinceEpoch() + MINUTES_TO_MSECONDS_MULTIPLIER)) { callers.append(m_targets.value(timestamp)); } } diff --git a/src/include/fragments/fragmentsdispatcher.h b/src/include/fragments/fragmentsdispatcher.h index 21990bf..af6c0d0 100644 --- a/src/include/fragments/fragmentsdispatcher.h +++ b/src/include/fragments/fragmentsdispatcher.h @@ -28,6 +28,8 @@ #include "fragments/fragmentspage.h" +#define MINUTES_TO_MSECONDS_MULTIPLIER 60*1000 // 60 seconds = 60 * 1000 msec + namespace QRail { namespace Fragments { class DispatcherEvent : public QEvent From 308ec4f2d44641b9fc7c94b867c8b6aa277167ca Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Mon, 24 Sep 2018 08:33:09 +0200 Subject: [PATCH 15/16] WIP CSA footpaths, destination footpaths are working --- src/engines/router/routerplanner.cpp | 88 ++++++++++++++++++---- src/engines/station/stationfactory.cpp | 6 -- src/include/engines/router/routerplanner.h | 8 +- 3 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/engines/router/routerplanner.cpp b/src/engines/router/routerplanner.cpp index 4154734..b76d295 100644 --- a/src/engines/router/routerplanner.cpp +++ b/src/engines/router/routerplanner.cpp @@ -112,9 +112,6 @@ void QRail::RouterEngine::Planner::getConnections(const QUrl &departureStation, plannerProcessingMutex.lock(); // Queue requests this->setTArray(QMap()); this->setSArray(QMap>()); - QMap DArray = this->DArray(); - DArray.clear(); - this->setDArray(DArray); this->setDepartureStationURI(departureStation); this->setArrivalStationURI(arrivalStation); this->setDepartureTime(departureTime); @@ -138,11 +135,13 @@ void QRail::RouterEngine::Planner::getConnections(const QUrl &departureStation, this->stationFactory()->getStationsInTheAreaByPosition(station->position(), SEARCH_RADIUS, MAX_RESULTS); + QMap D = QMap(); for (qint32 i = 0; i < nearbyStations.length(); i++) { QPair stationDistancePair = nearbyStations.at(i); - this->DArray().insert(stationDistancePair.first->uri(), stationDistancePair.second); + D.insert(stationDistancePair.first->uri(), stationDistancePair.second); } - qDebug() << this->DArray(); + this->setDArray(D); + qDebug() << "D ARRAY=" << this->DArray(); // Jumpstart the page fetching this->fragmentsFactory()->getPage(this->arrivalTime(), this); @@ -150,6 +149,16 @@ void QRail::RouterEngine::Planner::getConnections(const QUrl &departureStation, qDebug() << "CSA init OK"; } +void RouterEngine::Planner::getConnections(const QGeoCoordinate &departurePosition, + const QGeoCoordinate &arrivalPosition, const QDateTime &departureTime, const qint16 &maxTransfers) +{ + QUrl departureStationURI = this->stationFactory()->getNearestStationByPosition(departurePosition, + SEARCH_RADIUS).first->uri(); + QUrl arrivalStationURI = this->stationFactory()->getNearestStationByPosition(arrivalPosition, + SEARCH_RADIUS).first->uri(); + this->getConnections(departureStationURI, arrivalStationURI, departureTime, maxTransfers); +} + // Processors /** * @file routerplanner.cpp @@ -358,7 +367,7 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) /* * ========================================================================================== * FIND THE EARLIEST ARRIVAL TIME Tmin BETWEEN THE 3 POSSIBILITIES - * T1, T2, T3 + * T1, T2, T3 * ========================================================================================== * * In the CSA paper (march 2017) they describe the JourneyLeg Extraction @@ -532,8 +541,7 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) Tmin_transfers ); QMap T = this->TArray(); - T.insert(fragment->tripURI(), - newTrainProfile); // Key is automatically updated when key already exists + T.insert(fragment->tripURI(), newTrainProfile); this->setTArray(T); } } @@ -547,8 +555,7 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) Tmin_transfers ); QMap T = this->TArray(); - T.insert(fragment->tripURI(), - fasterTrainProfile); // Key is automatically updated when key already exists + T.insert(fragment->tripURI(), fasterTrainProfile); this->setTArray(T); } } else { @@ -559,8 +566,7 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) Tmin_transfers ); QMap T = this->TArray(); - T.insert(fragment->tripURI(), - nonExistingTrainProfile); // Key is automatically updated when key already exists + T.insert(fragment->tripURI(), nonExistingTrainProfile); this->setTArray(T); } @@ -620,8 +626,8 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) QMap> S = this->SArray(); QList SProfiles = S.value( fragment->departureStationURI()); - SProfiles.replace(numberOfPairs - 1, - updatedStationStopProfile); // Replace profile when departure times are equal + // Replace profile when departure times are equal + SProfiles.replace(numberOfPairs - 1, updatedStationStopProfile); S.insert(fragment->departureStationURI(), SProfiles); this->setSArray(S); } @@ -631,7 +637,8 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) QMap> S = this->SArray(); QList SProfiles = S.value( fragment->departureStationURI()); - SProfiles.append(updatedStationStopProfile); // Add profile when we have different departure times + // Add profile when we have different departure times + SProfiles.append(updatedStationStopProfile); S.insert(fragment->departureStationURI(), SProfiles); this->setSArray(S); } @@ -642,6 +649,8 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) QMap> S = this->SArray(); QList stationStopProfileList = QList(); + + // Add new entry if it doesn't exist yet stationStopProfileList.append(updatedStationStopProfile); S.insert(fragment->departureStationURI(), stationStopProfileList); this->setSArray(S); @@ -654,6 +663,55 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) * incorporate (c_deptime - f_dur, Tc) into profile of S[f_depstop]; */ + /*QRail::StationEngine::Station *targetStation = this->stationFactory()->getStationByURI( + fragment->departureStationURI()); + QList> nearbyStations = + this->stationFactory()->getStationsInTheAreaByPosition(targetStation->position(), + SEARCH_RADIUS, MAX_RESULTS); + QMap> S = this->SArray(); + + for (qint32 i = 0; i < nearbyStations.length(); i++) { + QRail::StationEngine::Station *station = nearbyStations.at(i).first; + qreal distance = nearbyStations.at(i).second; + qreal walkingTime = (distance / WALKING_SPEED) // Convert km / km/h to hours + * SECONDS_TO_HOURS_MULTIPLIER; // Convert hours to seconds + + QRail::RouterEngine::StationStopProfile *footpathStationStopProfile = + new QRail::RouterEngine::StationStopProfile( + fragment->departureTime(), + Tmin_earliestArrivalTime, + fragment, + this->TArray().value(fragment->tripURI())->arrivalConnection(), + Tmin_transfers + ); + + if (this->SArray().contains(station->uri())) { + qint16 numberOfPairs = this->SArray().value(fragment->departureStationURI()).size(); + QRail::RouterEngine::StationStopProfile *existingStationStopProfile = this->SArray().value( + fragment->departureStationURI()).at(numberOfPairs - 1); + QList SProfiles = S.value( + fragment->departureStationURI()); + if (fragment->arrivalTime().addSecs(walkingTime) == existingStationStopProfile->arrivalTime()) { + // Walking is faster than the existing route, replacing + SProfiles.replace(numberOfPairs - 1, footpathStationStopProfile); + S.insert(station->uri(), SProfiles); + this->setSArray(S); + } else { + SProfiles.append(footpathStationStopProfile); + S.insert(station->uri(), SProfiles); + this->setSArray(S); + } + } else { + // New entry + QList stationStopProfileList = + QList(); + + // Add new entry if it doesn't exist yet + stationStopProfileList.append(footpathStationStopProfile); + S.insert(station->uri(), QList()); + this->setSArray(S); + } + }*/ #ifdef VERBOSE_S_ARRAY qDebug() << "S-ARRAY"; diff --git a/src/engines/station/stationfactory.cpp b/src/engines/station/stationfactory.cpp index 05f5845..ebd6f43 100644 --- a/src/engines/station/stationfactory.cpp +++ b/src/engines/station/stationfactory.cpp @@ -378,12 +378,6 @@ QList> qreal latitudeRadianStation = qDegreesToRadians(latitudeStation); qreal longitudeRadianStation = qDegreesToRadians(longitudeStation); - // Don't return stations that are the same as the center of our search radius - if (latitudeRadianStation != latitudeRadianCenter - && longitudeRadianStation != longitudeRadianCenter) { - continue; - } - qreal differenceLatitude = latitudeRadianStation - latitudeRadianCenter; qreal differenceLongitude = longitudeRadianStation - longitudeRadianCenter; diff --git a/src/include/engines/router/routerplanner.h b/src/include/engines/router/routerplanner.h index ffb1dac..c091000 100644 --- a/src/include/engines/router/routerplanner.h +++ b/src/include/engines/router/routerplanner.h @@ -27,6 +27,7 @@ #include #include #include +#include #include // C++ header needed for std:sort function #include "engines/alerts/alertsmessage.h" @@ -69,7 +70,12 @@ class QRAIL_SHARED_EXPORT Planner : public QObject Q_OBJECT public: static Planner *getInstance(); - void getConnections(const QUrl &departureStation, const QUrl &arrivalStation, + void getConnections(const QUrl &departureStation, + const QUrl &arrivalStation, + const QDateTime &departureTime, + const qint16 &maxTransfers); + void getConnections(const QGeoCoordinate &departurePosition, + const QGeoCoordinate &arrivalPosition, const QDateTime &departureTime, const qint16 &maxTransfers); QDateTime calculateArrivalTime(const QDateTime &departureTime); From eca01a7cd9988f5f8c69964e86c97220dc5c4cc3 Mon Sep 17 00:00:00 2001 From: Dylan Van Assche Date: Mon, 24 Sep 2018 18:07:32 +0200 Subject: [PATCH 16/16] Prepare push to develop to fix build --- qrail.pri | 4 +- src/engines/router/routerfootpathprofile.cpp | 61 ------------------- src/engines/router/routerplanner.cpp | 56 ++--------------- src/engines/station/stationfactory.cpp | 3 - src/fragments/fragmentsdispatcher.cpp | 3 - src/fragments/fragmentsfactory.cpp | 2 - .../engines/router/routerfootpathprofile.h | 49 --------------- src/include/fragments/fragmentsfactory.h | 2 +- src/network/networkdispatcher.cpp | 7 +-- 9 files changed, 10 insertions(+), 177 deletions(-) delete mode 100644 src/engines/router/routerfootpathprofile.cpp delete mode 100644 src/include/engines/router/routerfootpathprofile.h diff --git a/qrail.pri b/qrail.pri index edb884f..6eceb18 100644 --- a/qrail.pri +++ b/qrail.pri @@ -32,7 +32,6 @@ SOURCES += \ $$PWD/src/engines/router/routerroutelegend.cpp \ $$PWD/src/engines/router/routerstationstopprofile.cpp \ $$PWD/src/engines/router/routertrainprofile.cpp \ - $$PWD/src/engines/router/routerfootpathprofile.cpp \ $$PWD/src/engines/liveboard/liveboardfactory.cpp \ $$PWD/src/engines/liveboard/liveboardboard.cpp \ $$PWD/src/engines/station/stationstation.cpp \ @@ -75,8 +74,7 @@ HEADERS += \ $$PWD/src/include/fragments/fragmentsfactory.h \ $$PWD/src/include/fragments/fragmentsdispatcher.h \ $$PWD/qtcsv/include/qtcsv/stringdata.h \ - $$PWD/src/include/qrail.h \ - $$PWD/src/include/engines/router/routerfootpathprofile.h + $$PWD/src/include/qrail.h DISTFILES += \ $$PWD/rpm/qrail.changes diff --git a/src/engines/router/routerfootpathprofile.cpp b/src/engines/router/routerfootpathprofile.cpp deleted file mode 100644 index 85539aa..0000000 --- a/src/engines/router/routerfootpathprofile.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is part of QRail. - * - * QRail is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * QRail is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with QRail. If not, see . - */ -#include "engines/router/routerfootpathprofile.h" -using namespace QRail; - -RouterEngine::FootpathProfile::FootpathProfile(StationEngine::Station *arrivalStation, - StationEngine::Station *departureStation, - qreal distance, - QObject *parent) : QObject(parent) -{ - // Use private members to avoid signal fire on construction - m_arrivalStation = arrivalStation; - m_departureStation = departureStation; - m_distance = distance; -} - -// Getters & Setters -qreal RouterEngine::FootpathProfile::distance() const -{ - return m_distance; -} - -void RouterEngine::FootpathProfile::setDistance(const qreal &distance) -{ - m_distance = distance; -} - -QRail::StationEngine::Station *RouterEngine::FootpathProfile::departureStation() const -{ - return m_departureStation; -} - -void RouterEngine::FootpathProfile::setDepartureStation(QRail::StationEngine::Station - *departureStation) -{ - m_departureStation = departureStation; -} - -QRail::StationEngine::Station *RouterEngine::FootpathProfile::arrivalStation() const -{ - return m_arrivalStation; -} - -void RouterEngine::FootpathProfile::setArrivalStation(QRail::StationEngine::Station *arrivalStation) -{ - m_arrivalStation = arrivalStation; -} diff --git a/src/engines/router/routerplanner.cpp b/src/engines/router/routerplanner.cpp index b76d295..3458a5d 100644 --- a/src/engines/router/routerplanner.cpp +++ b/src/engines/router/routerplanner.cpp @@ -316,9 +316,11 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) * between vehicles */ qint16 position = this->SArray().value(fragment->arrivalStationURI()).size() - 1; + QRail::RouterEngine::StationStopProfile *stopProfile = this->SArray().value( fragment->arrivalStationURI()).at(position); + // Needs extension for footpath support while ((((stopProfile->departureTime().toMSecsSinceEpoch() - INTRA_STOP_FOOTPATH_TIME * MILISECONDS_TO_SECONDS_MULTIPLIER) < fragment->arrivalTime().toMSecsSinceEpoch()) || stopProfile->transfers() >= this->maxTransfers()) && position > 0) { @@ -603,7 +605,6 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) qint16 numberOfPairs = this->SArray().value(fragment->departureStationURI()).size(); QRail::RouterEngine::StationStopProfile *existingStationStopProfile = this->SArray().value( fragment->departureStationURI()).at(numberOfPairs - 1); - if (updatedStationStopProfile->arrivalTime() < existingStationStopProfile->arrivalTime()) { // Replace existing StationStopProfile at the back when departure times are equal if (updatedStationStopProfile->departureTime() == existingStationStopProfile->departureTime()) { @@ -661,58 +662,11 @@ void QRail::RouterEngine::Planner::parsePage(QRail::Fragments::Page *page) * if (c_deptime, Tc) is non-dominated in profile of S[c_depstop] then: * for all footpaths f with f_arrstop = c_depstop do: * incorporate (c_deptime - f_dur, Tc) into profile of S[f_depstop]; + * + * WARNING: We can't guarantee any longer that the non-domination as mentioned earlier is guaranteed! + * We need to run a check before actually executing the profile insertion. */ - /*QRail::StationEngine::Station *targetStation = this->stationFactory()->getStationByURI( - fragment->departureStationURI()); - QList> nearbyStations = - this->stationFactory()->getStationsInTheAreaByPosition(targetStation->position(), - SEARCH_RADIUS, MAX_RESULTS); - QMap> S = this->SArray(); - - for (qint32 i = 0; i < nearbyStations.length(); i++) { - QRail::StationEngine::Station *station = nearbyStations.at(i).first; - qreal distance = nearbyStations.at(i).second; - qreal walkingTime = (distance / WALKING_SPEED) // Convert km / km/h to hours - * SECONDS_TO_HOURS_MULTIPLIER; // Convert hours to seconds - - QRail::RouterEngine::StationStopProfile *footpathStationStopProfile = - new QRail::RouterEngine::StationStopProfile( - fragment->departureTime(), - Tmin_earliestArrivalTime, - fragment, - this->TArray().value(fragment->tripURI())->arrivalConnection(), - Tmin_transfers - ); - - if (this->SArray().contains(station->uri())) { - qint16 numberOfPairs = this->SArray().value(fragment->departureStationURI()).size(); - QRail::RouterEngine::StationStopProfile *existingStationStopProfile = this->SArray().value( - fragment->departureStationURI()).at(numberOfPairs - 1); - QList SProfiles = S.value( - fragment->departureStationURI()); - if (fragment->arrivalTime().addSecs(walkingTime) == existingStationStopProfile->arrivalTime()) { - // Walking is faster than the existing route, replacing - SProfiles.replace(numberOfPairs - 1, footpathStationStopProfile); - S.insert(station->uri(), SProfiles); - this->setSArray(S); - } else { - SProfiles.append(footpathStationStopProfile); - S.insert(station->uri(), SProfiles); - this->setSArray(S); - } - } else { - // New entry - QList stationStopProfileList = - QList(); - - // Add new entry if it doesn't exist yet - stationStopProfileList.append(footpathStationStopProfile); - S.insert(station->uri(), QList()); - this->setSArray(S); - } - }*/ - #ifdef VERBOSE_S_ARRAY qDebug() << "S-ARRAY"; foreach (QUrl k, this->SArray().keys()) { diff --git a/src/engines/station/stationfactory.cpp b/src/engines/station/stationfactory.cpp index ebd6f43..29a2c5d 100644 --- a/src/engines/station/stationfactory.cpp +++ b/src/engines/station/stationfactory.cpp @@ -393,10 +393,7 @@ QList> QPair stationDistancePair; stationDistancePair.first = this->getStationByURI(uri); stationDistancePair.second = distance; - nearbyStations.append(stationDistancePair); - qDebug() << "Found station" << stationDistancePair.first->name().value( - QLocale::Language::Dutch) << "distance" << distance << "km"; } } diff --git a/src/fragments/fragmentsdispatcher.cpp b/src/fragments/fragmentsdispatcher.cpp index f4ad092..ea85837 100644 --- a/src/fragments/fragmentsdispatcher.cpp +++ b/src/fragments/fragmentsdispatcher.cpp @@ -49,7 +49,6 @@ void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) */ QDateTime from = page->fragments().first()->departureTime(); QDateTime until = page->fragments().last()->departureTime(); - qDebug() << m_targets; // DEBUG QList callerList = this->findTargets(from, until); // We should have retrieved some callers to dispatch the page to @@ -61,9 +60,7 @@ void QRail::Fragments::Dispatcher::dispatchPage(QRail::Fragments::Page *page) foreach (QObject *caller, callerList) { QCoreApplication::postEvent(caller, event); } - qDebug() << "Dispatched page to" << callerList; this->removeTargets(from, until); - qDebug() << "Removed targets"; // Trigger event processing, without this we might have race conditions where event processing is taking too long qApp->processEvents(); diff --git a/src/fragments/fragmentsfactory.cpp b/src/fragments/fragmentsfactory.cpp index f686127..724103b 100644 --- a/src/fragments/fragmentsfactory.cpp +++ b/src/fragments/fragmentsfactory.cpp @@ -121,9 +121,7 @@ void QRail::Fragments::Factory::getPage(const QDateTime &departureTime, QObject void QRail::Fragments::Factory::customEvent(QEvent *event) { - qDebug() << "Received event in factory:" << event; if (event->type() == this->http()->dispatcher()->eventType()) { - qDebug() << "Network event!"; event->accept(); QRail::Network::DispatcherEvent *networkEvent = reinterpret_cast (event); diff --git a/src/include/engines/router/routerfootpathprofile.h b/src/include/engines/router/routerfootpathprofile.h deleted file mode 100644 index 8fdeabc..0000000 --- a/src/include/engines/router/routerfootpathprofile.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of QRail. - * - * QRail is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * QRail is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with QRail. If not, see . - */ -#ifndef ROUTERFOOTPATHPROFILE_H -#define ROUTERFOOTPATHPROFILE_H - -#include - -#include "engines/station/stationstation.h" - -namespace QRail { -namespace RouterEngine { -class FootpathProfile : public QObject -{ - Q_OBJECT -public: - explicit FootpathProfile(QRail::StationEngine::Station *arrivalStation, - QRail::StationEngine::Station *departureStation, - qreal distance, - QObject *parent = nullptr); - QRail::StationEngine::Station *arrivalStation() const; - void setArrivalStation(QRail::StationEngine::Station *arrivalStation); - QRail::StationEngine::Station *departureStation() const; - void setDepartureStation(QRail::StationEngine::Station *departureStation); - qreal distance() const; - void setDistance(const qreal &distance); - -private: - QRail::StationEngine::Station *m_arrivalStation; - QRail::StationEngine::Station *m_departureStation; - qreal m_distance; -}; -} -} - -#endif // ROUTERFOOTPATHPROFILE_H diff --git a/src/include/fragments/fragmentsfactory.h b/src/include/fragments/fragmentsfactory.h index 6dca581..04981c6 100644 --- a/src/include/fragments/fragmentsfactory.h +++ b/src/include/fragments/fragmentsfactory.h @@ -33,7 +33,7 @@ #define BASE_URL "https://graph.irail.be/sncb/connections" -#define VERBOSE_HTTP_STATUS // Show HTTP results +//#define VERBOSE_HTTP_STATUS // Show HTTP results // Factory pattern to generate Linked Connections fragments on the fly namespace QRail { diff --git a/src/network/networkdispatcher.cpp b/src/network/networkdispatcher.cpp index 65b181f..94930b7 100644 --- a/src/network/networkdispatcher.cpp +++ b/src/network/networkdispatcher.cpp @@ -27,9 +27,9 @@ void QRail::Network::Dispatcher::dispatchReply(QNetworkReply *reply) { /* * WARNING: - * QEvent must be allocated on the heap since the event queue will - * take ownership of the QEvent object. - * Accessing it after calling 'postEvents()' isn't safe! + * QEvent must be allocated on the heap since the event queue will + * take ownership of the QEvent object. + * Accessing it after calling 'postEvents()' isn't safe! * INFO: https://doc.qt.io/qt-5/qcoreapplication.html#postEvent */ @@ -39,7 +39,6 @@ void QRail::Network::Dispatcher::dispatchReply(QNetworkReply *reply) // Retrieve the caller of the reply QObject *caller = this->findTarget(reply); - qDebug() << "Reply dispatched to target:" << caller; // Post the event to the event queue and remove the reply from the targets list QCoreApplication::postEvent(caller, event);