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

Rename reference to departure in vehicle layout queries to stopover

With the new data sources for this, we are no longer limited to vehicle
layout data for departures, but can also get them for arrivals.
parent 1abf3a0a
Pipeline #51353 passed with stage
in 1 minute and 6 seconds
......@@ -89,7 +89,7 @@ private Q_SLOTS:
QVERIFY(!platformJson.isEmpty());
QCOMPARE(platformJson, platformRef);
const auto departureJson = Stopover::toJson(parser.departure);
const auto departureJson = Stopover::toJson(parser.stopover);
const auto departureRef = QJsonDocument::fromJson(readFile(departureFileName)).object();
if (departureJson != departureRef) {
qDebug().noquote() << QJsonDocument(departureJson).toJson();
......
......@@ -86,7 +86,7 @@ private Q_SLOTS:
QVERIFY(!platformJson.isEmpty());
QCOMPARE(platformJson, platformRef);
const auto departureJson = Stopover::toJson(parser.departure);
const auto departureJson = Stopover::toJson(parser.stopover);
const auto departureRef = QJsonDocument::fromJson(readFile(departureFileName)).object();
if (departureJson != departureRef) {
qDebug().noquote() << QJsonDocument(departureJson).toJson();
......
......@@ -37,7 +37,7 @@ bool DeutscheBahnBackend::queryVehicleLayout(const VehicleLayoutRequest &request
{
// unlike the rest of the DB API, this only works in Germany, so do our own geo filtering here.
const auto germanyBBox = QPolygonF({ {5.56384, 55.0492}, {6.131, 47.2565}, {15.4307, 47.4737}, {14.6794, 54.7568} });
if (!germanyBBox.containsPoint({request.departure().stopPoint().longitude(), request.departure().stopPoint().latitude()}, Qt::WindingFill)) {
if (!germanyBBox.containsPoint({request.stopover().stopPoint().longitude(), request.stopover().stopPoint().latitude()}, Qt::WindingFill)) {
qDebug() << "request outside of bounding box";
return false;
}
......@@ -45,8 +45,8 @@ bool DeutscheBahnBackend::queryVehicleLayout(const VehicleLayoutRequest &request
// we need two parameters for the online API: the train number (numeric only), and the departure time
// note: data is only available withing the upcoming 24h
// checking this early is useful as the error response from the online service is extremely verbose...
auto dt = request.departure().scheduledDepartureTime();
const auto trainNum = extractTrainNumber(request.departure().route().line());
auto dt = request.stopover().scheduledDepartureTime();
const auto trainNum = extractTrainNumber(request.stopover().route().line());
if (!dt.isValid() || trainNum.isEmpty()) {
return false;
}
......@@ -74,8 +74,8 @@ bool DeutscheBahnBackend::queryVehicleLayout(const VehicleLayoutRequest &request
if (netReply->error() == QNetworkReply::NoError) {
DeutscheBahnVehicleLayoutParser p;
if (p.parse(data)) {
Cache::addVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey(), {p.vehicle, p.platform, p.departure}, {}, std::chrono::minutes(2));
addResult(reply, p.vehicle, p.platform, p.departure);
Cache::addVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey(), {p.vehicle, p.platform, p.stopover}, {}, std::chrono::minutes(2));
addResult(reply, p.vehicle, p.platform, p.stopover);
} else {
addError(reply, p.error, p.errorMessage);
if (p.error == Reply::NotFoundError) {
......
......@@ -61,11 +61,11 @@ bool DeutscheBahnVehicleLayoutParser::parse(const QByteArray &data)
line.setName(vehicle.name());
Route route;
route.setLine(line);
departure.setRoute(route);
departure.setStopPoint(stop);
departure.setScheduledArrivalTime(QDateTime::fromString(halt.value(QLatin1String("ankunftszeit")).toString(), Qt::ISODate));
departure.setScheduledDepartureTime(QDateTime::fromString(halt.value(QLatin1String("abfahrtszeit")).toString(), Qt::ISODate));
departure.setScheduledPlatform(platform.name());
stopover.setRoute(route);
stopover.setStopPoint(stop);
stopover.setScheduledArrivalTime(QDateTime::fromString(halt.value(QLatin1String("ankunftszeit")).toString(), Qt::ISODate));
stopover.setScheduledDepartureTime(QDateTime::fromString(halt.value(QLatin1String("abfahrtszeit")).toString(), Qt::ISODate));
stopover.setScheduledPlatform(platform.name());
fillMissingPositions();
return true;
......
......@@ -24,7 +24,7 @@ public:
Vehicle vehicle;
Platform platform;
Stopover departure;
Stopover stopover;
Reply::Error error = Reply::NoError;
QString errorMessage;
......
......@@ -21,7 +21,7 @@ using namespace KPublicTransport;
bool OebbBackend::queryVehicleLayout(const VehicleLayoutRequest &request, VehicleLayoutReply *reply, QNetworkAccessManager *nam) const
{
const auto ibnr = request.departure().stopPoint().identifier(QLatin1String("ibnr"));
const auto ibnr = request.stopover().stopPoint().identifier(QLatin1String("ibnr"));
if (ibnr.size() != 7) {
return false;
}
......@@ -29,9 +29,9 @@ bool OebbBackend::queryVehicleLayout(const VehicleLayoutRequest &request, Vehicl
QUrl url;
url.setScheme(QStringLiteral("https"));
url.setHost(QStringLiteral("live.oebb.at"));
url.setPath(QLatin1String("/backend/api/train/") + request.departure().route().line().name()
url.setPath(QLatin1String("/backend/api/train/") + request.stopover().route().line().name()
+ QLatin1String("/stationEva/") + ibnr
+ QLatin1String("/departure/") + request.departure().scheduledDepartureTime().toString(QStringLiteral("dd.MM.yyyy")));
+ QLatin1String("/departure/") + request.stopover().scheduledDepartureTime().toString(QStringLiteral("dd.MM.yyyy")));
QNetworkRequest netReq(url);
logRequest(request, netReq);
......@@ -44,8 +44,8 @@ bool OebbBackend::queryVehicleLayout(const VehicleLayoutRequest &request, Vehicl
if (netReply->error() == QNetworkReply::NoError) {
OebbVehicleLayoutParser p;
if (p.parse(data)) {
Cache::addVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey(), {p.vehicle, p.platform, p.departure}, {}, std::chrono::minutes(2));
addResult(reply, p.vehicle, p.platform, p.departure);
Cache::addVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey(), {p.vehicle, p.platform, p.stopover}, {}, std::chrono::minutes(2));
addResult(reply, p.vehicle, p.platform, p.stopover);
} else {
Cache::addNegativeVehicleLayoutCacheEntry(backendId(), reply->request().cacheKey());
addError(reply, Reply::NotFoundError, {});
......
......@@ -136,12 +136,12 @@ bool OebbVehicleLayoutParser::parse(const QByteArray &data)
line.setName(obj.value(QLatin1String("trainName")).toString());
Route route;
route.setLine(line);
departure.setRoute(route);
departure.setStopPoint(stop);
departure.setScheduledArrivalTime(QDateTime::fromString(obj.value(QLatin1String("scheduledArrival")).toString(), Qt::ISODate));
departure.setScheduledDepartureTime(QDateTime::fromString(obj.value(QLatin1String("scheduledDeparture")).toString(), Qt::ISODate));
departure.setScheduledPlatform(platform.name());
return !platform.sections().empty() || !vehicle.sections().empty()
|| departure.scheduledArrivalTime().isValid() || departure.scheduledDepartureTime().isValid();
stopover.setRoute(route);
stopover.setStopPoint(stop);
stopover.setScheduledArrivalTime(QDateTime::fromString(obj.value(QLatin1String("scheduledArrival")).toString(), Qt::ISODate));
stopover.setScheduledDepartureTime(QDateTime::fromString(obj.value(QLatin1String("scheduledDeparture")).toString(), Qt::ISODate));
stopover.setScheduledPlatform(platform.name());
return !platform.isEmpty() || !vehicle.isEmpty()
|| stopover.scheduledArrivalTime().isValid() || stopover.scheduledDepartureTime().isValid();
}
......@@ -23,7 +23,7 @@ public:
Vehicle vehicle;
Platform platform;
Stopover departure;
Stopover stopover;
};
}
......
......@@ -63,6 +63,11 @@ KPUBLICTRANSPORT_MAKE_GADGET(Platform)
KPUBLICTRANSPORT_MAKE_PROPERTY(Platform, QString, name, setName)
KPUBLICTRANSPORT_MAKE_PROPERTY(Platform, int, length, setLength)
bool Platform::isEmpty() const
{
return d->name.isEmpty() && d->length <= 0.0 && d->sections.empty();
}
const std::vector<PlatformSection>& Platform::sections() const
{
return d->sections;
......
......@@ -45,7 +45,7 @@ class KPUBLICTRANSPORT_EXPORT Platform
{
KPUBLICTRANSPORT_GADGET(Platform)
// TODO how does this work with the Czech way of identying tracks/platforms?
// TODO how does this work with the Czech way of identifying tracks/platforms?
/** Human readable identifier of this platform.
* Typically a number.
*/
......@@ -61,6 +61,9 @@ class KPUBLICTRANSPORT_EXPORT Platform
Q_PROPERTY(QVariantList sections READ sectionsVariant)
public:
/** Returns @c true if this object contains no information beyond default values. */
bool isEmpty() const;
/** The platform sections. */
const std::vector<PlatformSection>& sections() const;
/** Moves the platform sections out of this object. */
......
......@@ -107,6 +107,11 @@ KPUBLICTRANSPORT_MAKE_GADGET(Vehicle)
KPUBLICTRANSPORT_MAKE_PROPERTY(Vehicle, QString, name, setName)
KPUBLICTRANSPORT_MAKE_PROPERTY(Vehicle, Vehicle::Direction, direction, setDirection)
bool Vehicle::isEmpty() const
{
return d->name.isEmpty() && d->sections.empty() && d->direction == Vehicle::UnknownDirection;
}
const std::vector<VehicleSection>& Vehicle::sections() const
{
return d->sections;
......
......@@ -153,6 +153,9 @@ class KPUBLICTRANSPORT_EXPORT Vehicle
Q_PROPERTY(float platformPositionEnd READ platformPositionEnd STORED false)
public:
/** Returns @c true if this object contains no information beyond the default values. */
bool isEmpty() const;
/** The vehicle sections. */
const std::vector<VehicleSection>& sections() const;
/** Moves the vehicle sections out of this object. */
......
......@@ -717,7 +717,7 @@ VehicleLayoutReply* Manager::queryVehicleLayout(const VehicleLayoutRequest &req)
if (d->shouldSkipBackend(backend.get(), req)) {
continue;
}
if (req.departure().stopPoint().hasCoordinate() && backend->isLocationExcluded(req.departure().stopPoint())) {
if (req.stopover().stopPoint().hasCoordinate() && backend->isLocationExcluded(req.stopover().stopPoint())) {
qCDebug(Log) << "Skipping backend based on location filter:" << backend->backendId();
continue;
}
......
......@@ -26,7 +26,7 @@ public:
Vehicle m_vehicle;
VehicleLayoutRequest m_request;
Platform m_platform;
Stopover m_departure;
Stopover m_stopover;
Q_DECLARE_PUBLIC(VehicleLayoutQueryModel)
};
......@@ -47,7 +47,7 @@ void VehicleLayoutQueryModelPrivate::doQuery()
q->beginResetModel();
m_vehicle = reply->vehicle();
m_platform = reply->platform();
m_departure = reply->departure();
m_stopover = reply->stopover();
q->endResetModel();
emit q->contentChanged();
});
......@@ -57,7 +57,7 @@ void VehicleLayoutQueryModelPrivate::doClearResults()
{
m_vehicle = {};
m_platform = {};
m_departure = {};
m_stopover = {};
Q_Q(VehicleLayoutQueryModel);
emit q->contentChanged();
}
......@@ -95,10 +95,15 @@ Platform VehicleLayoutQueryModel::platform() const
return d->m_platform;
}
Stopover VehicleLayoutQueryModel::departure() const
Stopover VehicleLayoutQueryModel::stopover() const
{
Q_D(const VehicleLayoutQueryModel);
return d->m_departure;
return d->m_stopover;
}
Stopover VehicleLayoutQueryModel::departure() const
{
return stopover();
}
int VehicleLayoutQueryModel::rowCount(const QModelIndex &parent) const
......
......@@ -30,7 +30,9 @@ class KPUBLICTRANSPORT_EXPORT VehicleLayoutQueryModel : public AbstractQueryMode
/** The platform this vehicle is departing from. */
Q_PROPERTY(KPublicTransport::Platform platform READ platform NOTIFY contentChanged)
/** The departure this vehicle layout belongs to. */
Q_PROPERTY(KPublicTransport::Stopover departure READ departure NOTIFY contentChanged)
Q_PROPERTY(KPublicTransport::Stopover stopover READ stopover NOTIFY contentChanged)
/** @deprecated use stopover. */
Q_PROPERTY(KPublicTransport::Stopover departure READ stopover NOTIFY contentChanged)
public:
explicit VehicleLayoutQueryModel(QObject *parent = nullptr);
......@@ -41,7 +43,8 @@ public:
Vehicle vehicle() const;
Platform platform() const;
Stopover departure() const;
Stopover stopover() const;
[[deprecated("use stopover()")]] Stopover departure() const;
enum Roles {
VehicleSectionRole = Qt::UserRole
......
......@@ -27,7 +27,7 @@ public:
VehicleLayoutRequest request;
Vehicle vehicle;
Platform platform;
Stopover departure;
Stopover stopover;
};
}
......@@ -58,10 +58,15 @@ Platform VehicleLayoutReply::platform() const
return d->platform;
}
Stopover VehicleLayoutReply::departure() const
Stopover VehicleLayoutReply::stopover() const
{
Q_D(const VehicleLayoutReply);
return d->departure;
return d->stopover;
}
Stopover VehicleLayoutReply::departure() const
{
return stopover();
}
static bool isOneSidedCar(VehicleSection::Type type)
......@@ -69,12 +74,12 @@ static bool isOneSidedCar(VehicleSection::Type type)
return type == VehicleSection::PowerCar || type == VehicleSection::ControlCar;
}
void VehicleLayoutReply::addResult(const Vehicle &vehicle, const Platform &platform, const Stopover &departure)
void VehicleLayoutReply::addResult(const Vehicle &vehicle, const Platform &platform, const Stopover &stopover)
{
Q_D(VehicleLayoutReply);
d->vehicle = Vehicle::merge(d->vehicle, vehicle);
d->platform = Platform::merge(d->platform, platform);
d->departure = Stopover::merge(d->departure, departure);
d->stopover = Stopover::merge(d->stopover, stopover);
if (!d->vehicle.sections().empty()) {
// normalize section order
......
......@@ -32,8 +32,9 @@ public:
Vehicle vehicle() const;
/** Platform layout information found by this query. */
Platform platform() const;
/** Departure information the layout is valid for. */
Stopover departure() const;
/** Stopover information the layout is valid for. */
Stopover stopover() const;
[[deprecated("use stopover()")]] Stopover departure() const;
private:
friend class Manager;
......@@ -41,7 +42,7 @@ private:
explicit VehicleLayoutReply(const VehicleLayoutRequest &req, QObject *parent = nullptr);
friend class AbstractBackend;
Q_DECL_HIDDEN void addResult(const Vehicle &vehicle, const Platform &platform, const Stopover &departure);
Q_DECL_HIDDEN void addResult(const Vehicle &vehicle, const Platform &platform, const Stopover &stopover);
using Reply::addError;
Q_DECL_HIDDEN void addError(const AbstractBackend *backend, Reply::Error error, const QString &errorMsg);
......
......@@ -15,37 +15,37 @@
using namespace KPublicTransport;
enum { DepartureCacheTimeResolution = 60 }; // in seconds
enum { StopoverCacheTimeResolution = 60 }; // in seconds
namespace KPublicTransport {
class VehicleLayoutRequestPrivate : public QSharedData
{
public:
Stopover departure;
Stopover stopover;
QStringList backendIds;
};
}
KPUBLICTRANSPORT_MAKE_GADGET(VehicleLayoutRequest)
KPUBLICTRANSPORT_MAKE_PROPERTY(VehicleLayoutRequest, Stopover, departure, setDeparture)
KPUBLICTRANSPORT_MAKE_PROPERTY(VehicleLayoutRequest, Stopover, stopover, setStopover)
VehicleLayoutRequest::VehicleLayoutRequest(const Stopover &dep)
VehicleLayoutRequest::VehicleLayoutRequest(const Stopover &stopover)
: d(new VehicleLayoutRequestPrivate)
{
d->departure = dep;
d->stopover = stopover;
}
bool VehicleLayoutRequest::isValid() const
{
return d->departure.scheduledDepartureTime().isValid() && !d->departure.route().line().name().isEmpty();
return d->stopover.scheduledDepartureTime().isValid() && !d->stopover.route().line().name().isEmpty();
}
QString VehicleLayoutRequest::cacheKey() const
{
return QString::number(d->departure.scheduledDepartureTime().toSecsSinceEpoch() / DepartureCacheTimeResolution) + QLatin1Char('_')
+ LocationUtil::cacheKey(d->departure.stopPoint());
return QString::number(d->stopover.scheduledDepartureTime().toSecsSinceEpoch() / StopoverCacheTimeResolution) + QLatin1Char('_')
+ LocationUtil::cacheKey(d->stopover.stopPoint());
}
QJsonObject VehicleLayoutRequest::toJson(const VehicleLayoutRequest &req)
......@@ -64,4 +64,14 @@ void VehicleLayoutRequest::setBackendIds(const QStringList &backendIds)
d->backendIds = backendIds;
}
Stopover VehicleLayoutRequest::departure() const
{
return stopover();
}
void VehicleLayoutRequest::setDeparture(const Stopover &departure)
{
setStopover(departure);
}
#include "moc_vehiclelayoutrequest.cpp"
......@@ -26,14 +26,14 @@ class KPUBLICTRANSPORT_EXPORT VehicleLayoutRequest
{
KPUBLICTRANSPORT_GADGET(VehicleLayoutRequest)
// TODO properties for manual setup
// TODO should this really be exposed? we need the location for the geo filter though, if available
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Stopover, departure, setDeparture)
/** The stopover vehicle and platform layout information are requested for. */
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Stopover, stopover, setStopover)
/** @deprecated use stopover .*/
Q_PROPERTY(KPublicTransport::Stopover departure READ departure WRITE setDeparture)
public:
/** Creates a vehicle layout request for the given departure. */
explicit VehicleLayoutRequest(const Stopover &dep);
/** Creates a vehicle layout request for the given stopover. */
explicit VehicleLayoutRequest(const Stopover &stopover);
/** Returns @c true if this is a valid request, that is it has enough parameters set to perform a query. */
bool isValid() const;
......@@ -51,6 +51,9 @@ public:
*/
void setBackendIds(const QStringList &backendIds);
[[deprecated("use stopover()")]] Stopover departure() const;
[[deprecated("use setStopover()")]] void setDeparture(const Stopover &departure);
///@cond internal
static QJsonObject toJson(const VehicleLayoutRequest &req);
///@endcond
......
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