Commit 94bda46c authored by Volker Krause's avatar Volker Krause
Browse files

Add initial support for individual transport queries for EFA

parent 4e832485
Pipeline #90570 passed with stage
in 2 minutes and 12 seconds
......@@ -172,6 +172,34 @@ bool EfaBackend::queryStopover(const StopoverRequest &request, StopoverReply *re
return true;
}
struct {
IndividualTransport::Mode mode;
IndividualTransport::Qualifier qualifier;
int itMot;
} static constexpr const itMotMap[] = {
{ IndividualTransport::Walk, IndividualTransport::None, 100 },
{ IndividualTransport::Bike, IndividualTransport::Park, 101 },
{ IndividualTransport::Bike, IndividualTransport::None, 102 },
{ IndividualTransport::Car, IndividualTransport::Rent, 103 }, // ### 103 is "Kiss & Ride", unclear which of this two this practically maps to...
{ IndividualTransport::Car, IndividualTransport::Dropoff, 103 },
{ IndividualTransport::Car, IndividualTransport::Park, 104 },
// TODO 105 Taxi
// TODO 106 and 107 exist as well but no idea yet what they mean...
};
static void addItModeOptions(QUrlQuery &query, const QString &paramName, const std::vector<IndividualTransport> &modes)
{
for (const auto &mode : modes) {
const auto it = std::find_if(std::begin(itMotMap), std::end(itMotMap), [mode](const auto &m) {
return m.mode == mode.mode() && m.qualifier == mode.qualifier();
});
if (it != std::end(itMotMap)) {
query.addQueryItem(paramName, QString::number((*it).itMot));;
break;
}
}
}
bool EfaBackend::queryJourney(const JourneyRequest &request, JourneyReply *reply, QNetworkAccessManager *nam) const
{
if ((request.modes() & JourneySection::PublicTransport) == 0) {
......@@ -216,6 +244,10 @@ 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("itOptionsActive"), QStringLiteral("1"));
addItModeOptions(query, QStringLiteral("trITDepMOT"), request.accessModes());
addItModeOptions(query, QStringLiteral("trITArrMOT"), request.egressModes());
query.addQueryItem(QStringLiteral("calcNumberOfTrips"), QString::number(std::max(1, request.maximumResults())));
query.addQueryItem(QStringLiteral("calcCO2"), QStringLiteral("1"));
......
......@@ -8,6 +8,7 @@
#include "logging.h"
#include "scopedxmlstreamreader.h"
#include <KPublicTransport/IndividualTransport>
#include <KPublicTransport/Path>
using namespace KPublicTransport;
......@@ -62,10 +63,24 @@ Line::Mode EfaParser::motTypeToLineMode(int mot)
case 18: return Line::Train; // "Rail shuttle"
case 19: return Line::Bus; // "Peoples bus" / "Bürgerbus"
}
qCDebug(Log) << "Unknown means ot transport: " << mot;
qCDebug(Log) << "Unknown means of transport: " << mot;
return Line::Unknown;
}
IndividualTransport EfaParser::motTypeToIndividualTransportMode(int mot)
{
switch (mot) {
case 100: return { IndividualTransport::Walk, IndividualTransport::None };
case 101: return { IndividualTransport::Bike, IndividualTransport::Park };
case 102: return { IndividualTransport::Bike, IndividualTransport::None };
case 103:
case 104:
return { IndividualTransport::Car, IndividualTransport::None }; // TODO
}
qCDebug(Log) << "Unknown means of individual transport: " << mot;
return IndividualTransport::Walk;
}
QPolygonF EfaParser::parsePathCoordinatesElement(ScopedXmlStreamReader &reader)
{
QPolygonF poly;
......
......@@ -22,6 +22,7 @@ class QPolygonF;
namespace KPublicTransport {
class IndividualTransport;
class Journey;
class JourneySection;
class Location;
......@@ -61,11 +62,13 @@ public:
EfaRequestContext requestContext() const;
protected:
/** convert "means of transport" type id to Line::Mode
/** Convert "means of transport" type id to Line::Mode
* so far this seems to be identical in all installations, if that eventually changes
* this needs a similar configuration as Hafas uses.
*/
static Line::Mode motTypeToLineMode(int mot);
/** Same as the above, for individual transport modes. */
static IndividualTransport motTypeToIndividualTransportMode(int mot);
/** Parse path encoded as a space separated string of coordinate pairs. */
static QPolygonF parsePathCoordinatesElement(ScopedXmlStreamReader &reader);
......
......@@ -318,8 +318,6 @@ std::vector<JourneySection> EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamR
parseTripArrival(reader.subReader(), section);
}
} else if (reader.name() == QLatin1String("itdMeansOfTransport")) {
Line line;
line.setName(reader.attributes().value(QLatin1String("shortname")).toString());
const auto type = reader.attributes().value(QLatin1String("type")).toInt();
for (const auto &m : journey_section_types) {
if (m.type == type) {
......@@ -327,19 +325,26 @@ std::vector<JourneySection> EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamR
break;
}
}
const auto prodName = reader.attributes().value(QLatin1String("productName"));
if (prodName == QLatin1String("Fussweg")) {
section.setMode(JourneySection::Walking);
} else {
line.setModeString(prodName.toString());
}
line.setMode(motTypeToLineMode(reader.attributes().value(QLatin1String("motType")).toInt()));
Route route;
route.setDirection(reader.attributes().value(QLatin1String("destination")).toString());
route.setLine(line);
section.setRoute(route);
if (section.mode() == JourneySection::Invalid) {
if (type < 90) {
Line line;
line.setName(reader.attributes().value(QLatin1String("shortname")).toString());
const auto prodName = reader.attributes().value(QLatin1String("productName"));
if (prodName == QLatin1String("Fussweg")) {
section.setMode(JourneySection::Walking);
} else {
line.setModeString(prodName.toString());
}
line.setMode(motTypeToLineMode(reader.attributes().value(QLatin1String("motType")).toInt()));
Route route;
route.setDirection(reader.attributes().value(QLatin1String("destination")).toString());
route.setLine(line);
section.setRoute(route);
section.setMode(JourneySection::PublicTransport);
} else if (type > 100) {
const auto itMode = motTypeToIndividualTransportMode(type);
section.setIndividualTransport(itMode);
section.setMode(JourneySection::IndividualTransport);
}
} else if (reader.name() == QLatin1String("infoLink")) {
section.addNotes(parseInfoLink(reader.subReader()));
......
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