Commit 71e5720e authored by Volker Krause's avatar Volker Krause
Browse files

Correctly filter OTP results for discarded sharing networks

parent d60da229
Pipeline #79023 passed with stage
in 19 seconds
{"stopsByRadius":{"edges":[{"node":{"stop":{},"bikeRentalStation":{"id":"QmlrZVJlbnRhbFN0YXRpb246dGF4aS0x","name":"Taxi-Stellplatz","lat":48.59376,"lon":8.86348,"networks":["taxi"],"bikesAvailable":1,"spacesAvailable":0}}},{"node":{"stop":{},"bikeRentalStation":{"id":"QmlrZVJlbnRhbFN0YXRpb246N2JkNmQ5Y2ItNTA5Yi00Mzc4LTgzZGItY2ViYjQ0ZWUxZjZm","name":"Bhf. Herrenberg / Kalkofenstraße","lat":48.59449,"lon":8.86208,"networks":["regiorad"],"bikesAvailable":11,"spacesAvailable":99}}},{"node":{"stop":{},"bikeRentalStation":{"id":"QmlrZVJlbnRhbFN0YXRpb246ODAxMDM","name":"Bahnhof P+R-Anlage Süd","lat":48.59338317,"lon":8.86229217,"networks":["car-sharing"],"bikesAvailable":-1,"spacesAvailable":0}}},{"node":{"stop":{},"bikeRentalStation":{"id":"QmlrZVJlbnRhbFN0YXRpb246ODAxMDQ","name":"Hasenplatz","lat":48.59450726,"lon":8.87147538,"networks":["car-sharing"],"bikesAvailable":-1,"spacesAvailable":0}}},{"node":{"stop":{},"bikeRentalStation":{"id":"QmlrZVJlbnRhbFN0YXRpb246ZmFyZQ","name":"E-Lastenrad FaRe","lat":48.5961618,"lon":8.8701961,"networks":["cargo-bike"],"bikesAvailable":1,"spacesAvailable":0}}}]}}
[
{
"identifier": {
"gtfs": "QmlrZVJlbnRhbFN0YXRpb246N2JkNmQ5Y2ItNTA5Yi00Mzc4LTgzZGItY2ViYjQ0ZWUxZjZm"
},
"latitude": 48.59449005126953,
"longitude": 8.862079620361328,
"name": "Bhf. Herrenberg / Kalkofenstraße",
"rentalVehicleStation": {
"availableVehicles": 11,
"capacity": 99,
"network": {
"name": "RegioRad",
"vehicleTypes": "Bicycle"
}
},
"type": "RentedVehicleStation"
},
{
"identifier": {
"gtfs": "QmlrZVJlbnRhbFN0YXRpb246ZmFyZQ"
},
"latitude": 48.596160888671875,
"longitude": 8.870196342468262,
"name": "E-Lastenrad FaRe",
"rentalVehicle": {
"network": {
"name": "cargo-bike",
"vehicleTypes": "Unknown"
},
"type": "Unknown"
},
"type": "RentedVehicle"
}
]
......@@ -23,6 +23,8 @@
using namespace KPublicTransport;
using RentalVehicleNetworkMap = QHash<QString, RentalVehicleNetwork>;
class OtpParserTest : public QObject
{
Q_OBJECT
......@@ -47,18 +49,34 @@ private Q_SLOTS:
{
QTest::addColumn<QString>("inFileName");
QTest::addColumn<QString>("refFileName");
QTest::addColumn<RentalVehicleNetworkMap>("networks");
QTest::newRow("fi-digitransit-location")
<< s(SOURCE_DIR "/data/otp/fi-digitransit-location-by-coordinate.in.json")
<< s(SOURCE_DIR "/data/otp/fi-digitransit-location-by-coordinate.out.json");
<< s(SOURCE_DIR "/data/otp/fi-digitransit-location-by-coordinate.out.json")
<< RentalVehicleNetworkMap();
RentalVehicleNetworkMap networks;
networks.insert(s("car-sharing"), {});
networks.insert(s("taxi"), {});
RentalVehicleNetwork n;
n.setName(s("RegioRad"));
n.setVehicleTypes(RentalVehicle::Bicycle);
networks.insert(s("regiorad"), n);
QTest::newRow("de-stadtnavi-rental-vehicle-locations")
<< s(SOURCE_DIR "/data/otp/de-stadtnavi-rental-vehicle-locations.in.json")
<< s(SOURCE_DIR "/data/otp/de-stadtnavi-rental-vehicle-locations.out.json")
<< networks;
}
void testParseLocationByCoordinate()
{
QFETCH(QString, inFileName);
QFETCH(QString, refFileName);
QFETCH(RentalVehicleNetworkMap, networks);
OpenTripPlannerParser p(s("gtfs"));
p.setKnownRentalVehicleNetworks(networks);
const auto res = p.parseLocationsByCoordinate(QJsonDocument::fromJson(readFile(inFileName)).object());
const auto jsonRes = Location::toJson(res);
......
......@@ -134,7 +134,10 @@ std::vector<Location> OpenTripPlannerParser::parseLocationsByCoordinate(const QJ
const auto stopArray = obj.value(QLatin1String("stopsByRadius")).toObject().value(QLatin1String("edges")).toArray();
locs.reserve(stopArray.size());
for (const auto &stop : stopArray) {
locs.push_back(parseLocation(stop.toObject().value(QLatin1String("node")).toObject()));
auto l = parseLocation(stop.toObject().value(QLatin1String("node")).toObject());
if (!l.isEmpty()) {
locs.push_back(std::move(l));
}
}
// deduplicate elements, which we get due to searching for stops rather than stations
......@@ -154,7 +157,10 @@ std::vector<Location> OpenTripPlannerParser::parseLocationsByName(const QJsonObj
const auto stationArray = obj.value(QLatin1String("stations")).toArray();
locs.reserve(stationArray.size());
for (const auto &station : stationArray) {
locs.push_back(parseLocation(station.toObject()));
auto l = parseLocation(station.toObject());
if (!l.isEmpty()) {
locs.push_back(std::move(l));
}
}
return locs;
}
......
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