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

Deduplicate EFA location parsing and add IFOPT support

parent 4ae36e2a
......@@ -12,6 +12,7 @@
"scheduledPlatform": "",
"stopPoint": {
"identifier": {
"ifopt": "de:09564:1391:11:2",
"testid": "3001391"
},
"latitude": 49.49388122558594,
......@@ -37,6 +38,7 @@
"scheduledPlatform": "",
"stopPoint": {
"identifier": {
"ifopt": "de:09564:1391:3:6",
"testid": "3001391"
},
"latitude": 49.493858337402344,
......
[
{
"identifier": {
"ifopt": "de:09162:6",
"testid": "1000006"
},
"latitude": 48.14030838012695,
......@@ -9,6 +10,7 @@
},
{
"identifier": {
"ifopt": "de:09162:7000",
"testid": "1007000"
},
"latitude": 48.14115905761719,
......
......@@ -9,6 +9,7 @@
},
{
"identifier": {
"ifopt": "de:08111:6115",
"testid": "5006115"
},
"latitude": 48.784881591796875,
......@@ -18,6 +19,7 @@
},
{
"identifier": {
"ifopt": "de:08111:6118",
"testid": "5006118"
},
"latitude": 48.783390045166016,
......@@ -27,6 +29,7 @@
},
{
"identifier": {
"ifopt": "de:08111:6112",
"testid": "5006112"
},
"latitude": 48.78316116333008,
......
[
{
"identifier": {
"ifopt": "de:09564:1391",
"testid": "3001391"
},
"latitude": 49.49382019042969,
......@@ -10,6 +11,7 @@
},
{
"identifier": {
"ifopt": "de:09564:1396",
"testid": "3001396"
},
"latitude": 49.492881774902344,
......@@ -19,6 +21,7 @@
},
{
"identifier": {
"ifopt": "de:09564:1400",
"testid": "3001400"
},
"latitude": 49.493621826171875,
......
......@@ -10,6 +10,7 @@
"expectedDepartureTime": "2020-04-27T22:07:00",
"from": {
"identifier": {
"ifopt": "de:09564:510:11:U2",
"testid": "3000510"
},
"latitude": 49.44636917114258,
......
......@@ -10,6 +10,7 @@
"expectedDepartureTime": "2019-11-11T21:36:00",
"from": {
"identifier": {
"ifopt": "de:09564:1391:11:2",
"testid": "3001391"
},
"latitude": 49.493961334228516,
......@@ -62,6 +63,7 @@
"scheduledDepartureTime": "2019-11-11T21:36:00",
"to": {
"identifier": {
"ifopt": "de:09564:510:11:U2",
"testid": "3000510"
},
"latitude": 49.44636917114258,
......@@ -79,6 +81,7 @@
"expectedDepartureTime": "2019-11-11T22:00:00",
"from": {
"identifier": {
"ifopt": "de:09564:510:11:U1_2",
"testid": "3000510"
},
"latitude": 49.44636917114258,
......@@ -93,6 +96,7 @@
"scheduledPlatform": "1",
"stopPoint": {
"identifier": {
"ifopt": "de:09564:561:11:1",
"testid": "3000561"
},
"latitude": 49.429298400878906,
......@@ -107,6 +111,7 @@
"scheduledPlatform": "1",
"stopPoint": {
"identifier": {
"ifopt": "de:09564:1701:11:1",
"testid": "3001701"
},
"latitude": 49.424530029296875,
......@@ -158,6 +163,7 @@
"scheduledDepartureTime": "2019-11-11T22:00:00",
"to": {
"identifier": {
"ifopt": "de:09564:1502:11:2",
"testid": "3001502"
},
"latitude": 49.41585922241211,
......
......@@ -7,6 +7,7 @@
#include "efaxmlparser.h"
#include "logging.h"
#include "scopedxmlstreamreader.h"
#include "ifopt/ifoptutil.h"
#include <KPublicTransport/Journey>
#include <KPublicTransport/Location>
......@@ -18,32 +19,48 @@
using namespace KPublicTransport;
Location EfaXmlParser::parseItdOdvAssignedStop(const ScopedXmlStreamReader &reader) const
void EfaXmlParser::parseLocationCommon(Location &loc, const ScopedXmlStreamReader &reader) const
{
Location loc;
if (reader.attributes().hasAttribute(QLatin1String("x")) && reader.attributes().hasAttribute(QLatin1String("y"))) {
loc.setLatitude(reader.attributes().value(QLatin1String("y")).toDouble());
loc.setLongitude(reader.attributes().value(QLatin1String("x")).toDouble());
}
loc.setIdentifier(m_locationIdentifierType, reader.attributes().value(QLatin1String("stopID")).toString());
loc.setName(reader.attributes().value(QLatin1String("nameWithPlace")).toString());
loc.setLocality(reader.attributes().value(QLatin1String("place")).toString());
return loc;
}
Location EfaXmlParser::parseOdvNameElem(ScopedXmlStreamReader &reader) const
{
Location loc;
if (reader.attributes().hasAttribute(QLatin1String("x")) && reader.attributes().hasAttribute(QLatin1String("y"))) {
loc.setLatitude(reader.attributes().value(QLatin1String("y")).toDouble());
loc.setLongitude(reader.attributes().value(QLatin1String("x")).toDouble());
// can be already set on loc, so don't reset it if missing here
const auto locality = reader.attributes().value(QLatin1String("place")).toString();
if (!locality.isEmpty()) {
loc.setLocality(locality);
}
const auto id = reader.attributes().value(QLatin1String("stopID")).toString();
if (!id.isEmpty()) {
loc.setIdentifier(m_locationIdentifierType, id);
} else {
loc.setIdentifier(m_locationIdentifierType, reader.attributes().value(QLatin1String("stateless")).toString());
}
// check if IFOPT identifiers are present, in decreasing level of detail
for (const auto &attr : {QLatin1String("pointGid"), QLatin1String("areaGid"), QLatin1String("gid")}) {
const auto id = reader.attributes().value(attr);
if (IfoptUtil::isValid(id)) {
loc.setIdentifier(QStringLiteral("ifopt"), id.toString());
break;
}
}
}
Location EfaXmlParser::parseItdOdvAssignedStop(const ScopedXmlStreamReader &reader) const
{
Location loc;
parseLocationCommon(loc, reader);
loc.setName(reader.attributes().value(QLatin1String("nameWithPlace")).toString());
return loc;
}
Location EfaXmlParser::parseOdvNameElem(ScopedXmlStreamReader &reader) const
{
Location loc;
parseLocationCommon(loc, reader);
loc.setName(reader.readElementText(QXmlStreamReader::SkipChildElements));
return loc;
}
......@@ -111,12 +128,8 @@ Stopover EfaXmlParser::parseDmDeparture(ScopedXmlStreamReader &&reader) const
stop = stopIt.value();
}
parseLocationCommon(stop, reader);
stop.setName(reader.attributes().value(QLatin1String("stopName")).toString());
if (reader.attributes().hasAttribute(QLatin1String("x")) && reader.attributes().hasAttribute(QLatin1String("y"))) {
stop.setLatitude(reader.attributes().value(QLatin1String("y")).toFloat());
stop.setLongitude(reader.attributes().value(QLatin1String("x")).toFloat());
}
stop.setIdentifier(m_locationIdentifierType, stopId);
dep.setStopPoint(stop);
const auto occupancy = reader.attributes().value(QLatin1String("occupancy"));
......@@ -170,11 +183,8 @@ std::vector<Stopover> EfaXmlParser::parseDmResponse(const QByteArray &data) cons
void EfaXmlParser::parseTripDeparture(ScopedXmlStreamReader &&reader, JourneySection &section) const
{
Location loc;
parseLocationCommon(loc, reader);
loc.setName(reader.attributes().value(QLatin1String("name")).toString());
loc.setLatitude(reader.attributes().value(QLatin1String("y")).toFloat());
loc.setLongitude(reader.attributes().value(QLatin1String("x")).toFloat());
loc.setIdentifier(m_locationIdentifierType, reader.attributes().value(QLatin1String("stopID")).toString());
loc.setLocality(reader.attributes().value(QLatin1String("place")).toString());
section.setFrom(loc);
// ### are those the correct ones? there's also just "platform"
......@@ -193,11 +203,8 @@ void EfaXmlParser::parseTripDeparture(ScopedXmlStreamReader &&reader, JourneySec
void EfaXmlParser::parseTripArrival(ScopedXmlStreamReader &&reader, JourneySection &section) const
{
Location loc;
parseLocationCommon(loc, reader);
loc.setName(reader.attributes().value(QLatin1String("name")).toString());
loc.setLatitude(reader.attributes().value(QLatin1String("y")).toFloat());
loc.setLongitude(reader.attributes().value(QLatin1String("x")).toFloat());
loc.setIdentifier(m_locationIdentifierType, reader.attributes().value(QLatin1String("stopID")).toString());
loc.setLocality(reader.attributes().value(QLatin1String("place")).toString());
section.setTo(loc);
// ### are those the correct ones? there's also just "platform"
......@@ -216,11 +223,8 @@ void EfaXmlParser::parseTripArrival(ScopedXmlStreamReader &&reader, JourneySecti
Stopover EfaXmlParser::parsePartialTripIntermediateStop(ScopedXmlStreamReader &&reader) const
{
Location loc;
parseLocationCommon(loc, reader);
loc.setName(reader.attributes().value(QLatin1String("name")).toString());
loc.setLatitude(reader.attributes().value(QLatin1String("y")).toFloat());
loc.setLongitude(reader.attributes().value(QLatin1String("x")).toFloat());
loc.setIdentifier(m_locationIdentifierType, reader.attributes().value(QLatin1String("stopID")).toString());
loc.setLocality(reader.attributes().value(QLatin1String("place")).toString());
Stopover stop;
stop.setStopPoint(loc);
......
......@@ -26,6 +26,7 @@ public:
std::vector<Journey> parseTripResponse(const QByteArray &data) const override;
private:
void parseLocationCommon(Location &loc, const ScopedXmlStreamReader &reader) const;
Location parseItdOdvAssignedStop(const ScopedXmlStreamReader &reader) const;
Location parseOdvNameElem(ScopedXmlStreamReader &reader) const;
......
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