Commit 0b0cb95f authored by Volker Krause's avatar Volker Krause
Browse files

Distinguish between dock-based and floating rental bikes

Both GBFS and OTP provide that distinction (at least somewhat), and now we
can actually represent that.
parent 29e331a2
......@@ -33,23 +33,33 @@ void OpenTripPlannerParser::setKnownRentalVehicleNetworks(const QHash<QString, R
m_rentalVehicleNetworks = networks;
}
RentalVehicleStation OpenTripPlannerParser::parseRentalVehicleStation(const QJsonObject &obj) const
QVariant OpenTripPlannerParser::parseRentalVehicleData(const QJsonObject &obj) const
{
RentalVehicleStation s;
RentalVehicleNetwork network;
// TODO id
const auto networks = obj.value(QLatin1String("networks")).toArray();
if (!networks.empty()) {
const auto it = m_rentalVehicleNetworks.find(networks.at(0).toString());
if (it != m_rentalVehicleNetworks.end()) {
s.setNetwork(it.value());
network = it.value();
} else {
RentalVehicleNetwork n;
n.setName(networks.at(0).toString());
s.setNetwork(n);
network.setName(networks.at(0).toString());
}
}
s.setCapacity(obj.value(QLatin1String("spacesAvailable")).toInt(-1));
s.setAvailableVehicles(obj.value(QLatin1String("bikesAvailable")).toInt(-1));
const auto capacity = obj.value(QLatin1String("spacesAvailable")).toInt(-1);
const auto available = obj.value(QLatin1String("bikesAvailable")).toInt(-1);
if (capacity == 0 && available == 1) { // heuristic for distinguishing floating vehicles and docks
RentalVehicle v;
v.setNetwork(network);
v.setType(static_cast<RentalVehicle::VehicleType>(static_cast<int>(network.vehicleTypes())));
return v;
}
RentalVehicleStation s;
s.setNetwork(network);
s.setCapacity(capacity);
s.setAvailableVehicles(available);
return s;
}
......@@ -79,9 +89,9 @@ bool OpenTripPlannerParser::parseLocationFragment(const QJsonObject &obj, Locati
const auto bss = obj.value(QLatin1String("bikeRentalStation")).toObject();
if (!bss.isEmpty()) {
loc.setType(Location::RentedVehicleStation);
loc.setRentalVehicleStation(parseRentalVehicleStation(bss));
return loc.rentalVehicleStation().network().isValid();
loc.setData(parseRentalVehicleData(bss));
loc.setType(loc.data().userType() == qMetaTypeId<RentalVehicle>() ? Location::RentedVehicle : Location::RentedVehicleStation);
return loc.rentalVehicleStation().network().isValid() || loc.rentalVehicle().network().isValid();
}
return true;
......
......@@ -48,7 +48,7 @@ public:
std::vector<Journey> parseJourneys(const QJsonObject &obj) const;
private:
RentalVehicleStation parseRentalVehicleStation(const QJsonObject &obj) const;
QVariant parseRentalVehicleData(const QJsonObject &obj) const;
/// @return @c false for Location objects that should be discarded entirely
bool parseLocationFragment(const QJsonObject &obj, Location &loc) const;
Location parseLocation(const QJsonObject &obj) const;
......
......@@ -116,12 +116,17 @@ static void appendResults(const GBFSService &service, const LocationRequest &req
}
Location loc;
loc.setName(network.name()); // TODO how can we pass the entire network for floating vehicles?
loc.setType(Location::RentedVehicleStation); // TODO do we need a better type for floating vehicles?
loc.setName(network.name());
loc.setType(Location::RentedVehicle);
loc.setCoordinate(lat, lon);
const auto stationId = bike.value(QLatin1String("bike_id")).toString();
loc.setIdentifier(service.systemId, stationId);
// TODO vehicle type, remaining range, deep rental links
RentalVehicle vehicle;
vehicle.setNetwork(network);
loc.setData(vehicle);
context->result.push_back(loc);
}
......
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