Commit 43d676e2 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to specify maximum amount of needed journey results

Also, add a similar option for whether intermediate stop data is needed.
This allows some backends to reduce the requested data.
parent 9b2d18ee
Pipeline #49998 passed with stage
in 22 seconds
......@@ -194,7 +194,7 @@ bool EfaBackend::queryJourney(const JourneyRequest &request, JourneyReply *reply
query.addQueryItem(QStringLiteral("itdTime"), dt.time().toString(QStringLiteral("hhmm")));
query.addQueryItem(QStringLiteral("itdTripDateTimeDepArr"), request.dateTimeMode() == JourneyRequest::Departure ? QStringLiteral("dep") : QStringLiteral("arr"));
query.addQueryItem(QStringLiteral("calcNumberOfTrips"), QStringLiteral("12")); // TODO
query.addQueryItem(QStringLiteral("calcNumberOfTrips"), QString::number(std::max(1, request.maximumResults())));
query.addQueryItem(QStringLiteral("calcCO2"), QStringLiteral("1"));
// saves several 100kb due to not encoding that path coordinates (which we don't even need) as XML
......
......@@ -103,8 +103,9 @@ bool HafasMgateBackend::queryJourney(const JourneyRequest &request, JourneyReply
req.insert(QStringLiteral("extChgTime"), -1);
req.insert(QStringLiteral("getEco"), false);
req.insert(QStringLiteral("getIST"), false);
req.insert(QStringLiteral("getPasslist"), true); // ???
req.insert(QStringLiteral("getPasslist"), request.includeIntermediateStops());
req.insert(QStringLiteral("getPolyline"), false);
req.insert(QStringLiteral("numF"), request.maximumResults());
QDateTime dt = request.dateTime();
if (timeZone().isValid()) {
......
......@@ -137,6 +137,7 @@ bool OpenTripPlannerGraphQLBackend::queryJourney(const JourneyRequest &req, Jour
gqlReq.setVariable(QStringLiteral("time"), dt.toString(QStringLiteral("hh:mm:ss")));
gqlReq.setVariable(QStringLiteral("dateTime"), dt.toString(Qt::ISODate));
gqlReq.setVariable(QStringLiteral("arriveBy"), req.dateTimeMode() == JourneyRequest::Arrival);
gqlReq.setVariable(QStringLiteral("maxResults"), req.maximumResults());
QJsonArray modes;
QJsonObject walkMode;
......
......@@ -8,7 +8,8 @@ query journeys(
$toLon: Float!,
$date: String!,
$time: String!,
$arriveBy: Boolean!
$arriveBy: Boolean!,
$maxResults: Int!
) {
plan (
from: { lat: $fromLat, lon: $fromLon }
......@@ -16,7 +17,7 @@ query journeys(
date: $date
time: $time
arriveBy: $arriveBy
numItineraries: 3
numItineraries: $maxResults
) {
itineraries {
legs {
......
......@@ -7,14 +7,15 @@ query journeys(
$toLat: Float!,
$toLon: Float!,
$dateTime: DateTime!,
$arriveBy: Boolean!
$arriveBy: Boolean!,
$maxResults: Int!
) {
plan: trip (
from: { coordinates: { latitude: $fromLat, longitude: $fromLon } }
to: { coordinates: { latitude: $toLat, longitude: $toLon } }
dateTime: $dateTime
arriveBy: $arriveBy
numTripPatterns: 3
numTripPatterns: $maxResults
) {
itineraries: tripPatterns {
legs {
......
......@@ -9,7 +9,8 @@ query journeys(
$date: String!,
$time: String!,
$arriveBy: Boolean!,
$modes: [TransportMode]!
$modes: [TransportMode]!,
$maxResults: Int!
) {
plan (
from: { lat: $fromLat, lon: $fromLon }
......@@ -17,7 +18,7 @@ query journeys(
date: $date
time: $time
arriveBy: $arriveBy
numItineraries: 3
numItineraries: $maxResults
transportModes: $modes
) {
itineraries {
......
......@@ -28,11 +28,13 @@ public:
Location from;
Location to;
QDateTime dateTime;
JourneyRequest::DateTimeMode dateTimeMode = JourneyRequest::Departure;
std::vector<RequestContext> contexts;
QStringList backendIds;
bool downloadAssets = false;
JourneyRequest::DateTimeMode dateTimeMode = JourneyRequest::Departure;
JourneySection::Modes modes = JourneySection::PublicTransport | JourneySection::RentedVehicle;
int maximumResults = 12;
bool downloadAssets = false;
bool includeIntermediateStops = true;
};
}
......@@ -42,6 +44,8 @@ KPUBLICTRANSPORT_MAKE_PROPERTY(JourneyRequest, Location, to, setTo)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneyRequest, JourneyRequest::DateTimeMode, dateTimeMode, setDateTimeMode)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneyRequest, bool, downloadAssets, setDownloadAssets)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneyRequest, JourneySection::Modes, modes, setModes)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneyRequest, int, maximumResults, setMaximumResults)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneyRequest, bool, includeIntermediateStops, setIncludeIntermediateStops)
JourneyRequest::JourneyRequest(const Location &from, const Location &to)
: d(new JourneyRequestPrivate)
......
......@@ -47,6 +47,16 @@ class KPUBLICTRANSPORT_EXPORT JourneyRequest
* values for tranfers/waits/etc are ignored.
*/
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::JourneySection::Modes, modes, setModes)
/** The maximum amount of expected results.
* @note This is only an optimization hint for backends, not a guarantee
* that all results comply with this constraint.
*/
KPUBLICTRANSPORT_PROPERTY(int, maximumResults, setMaximumResults)
/** Retrieve intermediate stops for the queried journeys as well.
* @note This is only an optimization hint for backends, not a guarantee
* that all results will contain this information.
*/
KPUBLICTRANSPORT_PROPERTY(bool, includeIntermediateStops, setIncludeIntermediateStops)
public:
enum DateTimeMode {
......
......@@ -379,6 +379,18 @@ Kirigami.ApplicationWindow {
text: "Retal Vehicles"
}
}
RowLayout {
QQC2.Label { text: "Results:" }
QQC2.TextField {
id: maxResults
text: "10"
}
QQC2.CheckBox {
id: intermediateStops
checked: true
text: "Intermediate stops"
}
}
QQC2.ComboBox {
id: fromSelector
......@@ -453,6 +465,8 @@ Kirigami.ApplicationWindow {
journeyModel.request.downloadAssets = true
journeyModel.request.modes = (ptMode.checked ? JourneySection.PublicTransport : JourneySection.Invalid)
| (rentalMode.checked ? JourneySection.RentedVehicle : JourneySection.Invalid);
journeyModel.request.maximumResults = maxResults.text;
journeyModel.request.includeIntermediateStops = intermediateStops.checked;
}
}
QQC2.Button {
......@@ -474,6 +488,8 @@ Kirigami.ApplicationWindow {
journeyModel.request.downloadAssets = true
journeyModel.request.modes = (ptMode.checked ? JourneySection.PublicTransport : JourneySection.Invalid)
| (rentalMode.checked ? JourneySection.RentedVehicle : JourneySection.Invalid);
journeyModel.request.maximumResults = maxResults.text;
journeyModel.request.includeIntermediateStops = intermediateStops.checked;
}
}
QQC2.Button {
......@@ -495,6 +511,8 @@ Kirigami.ApplicationWindow {
journeyModel.request.downloadAssets = true
journeyModel.request.modes = (ptMode.checked ? JourneySection.PublicTransport : JourneySection.Invalid)
| (rentalMode.checked ? JourneySection.RentedVehicle : JourneySection.Invalid);
journeyModel.request.maximumResults = maxResults.text;
journeyModel.request.includeIntermediateStops = intermediateStops.checked;
}
}
QQC2.Button {
......
......@@ -173,6 +173,7 @@ private Q_SLOTS:
LocationRequest req;
req.setBackendIds({backend});
req.setCoordinate(loc2.latitude(), loc2.longitude());
req.setMaximumResults(1);
auto reply = m_ptMgr.queryLocation(req);
QSignalSpy spy(reply, &LocationReply::finished);
QVERIFY(spy.wait(TIMEOUT));
......@@ -245,6 +246,7 @@ private Q_SLOTS:
req.setBackendIds({backend});
req.setFrom(loc1);
req.setTo(loc2);
req.setMaximumResults(1);
auto reply = m_ptMgr.queryJourney(req);
QSignalSpy spy(reply, &JourneyReply::finished);
QVERIFY(spy.wait(TIMEOUT));
......
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