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

Add support for remaining range of rental vehicles

Provided by GBFS feeds in particular for battery powered vehicles.
parent 45a4eebb
Pipeline #79021 passed with stage
in 18 seconds
......@@ -34,6 +34,7 @@ class RentalVehiclePrivate : public QSharedData
{
public:
RentalVehicle::VehicleType type = RentalVehicle::Unknown;
int remainingRange = -1;
KPublicTransport::RentalVehicleNetwork network;
};
}
......@@ -215,13 +216,17 @@ RentalVehicleStation RentalVehicleStation::fromJson(const QJsonObject &obj)
KPUBLICTRANSPORT_MAKE_GADGET(RentalVehicle)
KPUBLICTRANSPORT_MAKE_PROPERTY(RentalVehicle, RentalVehicle::VehicleType, type, setType)
KPUBLICTRANSPORT_MAKE_PROPERTY(RentalVehicle, int, remainingRange, setRemainingRange)
KPUBLICTRANSPORT_MAKE_PROPERTY(RentalVehicle, RentalVehicleNetwork, network, setNetwork)
QJsonObject RentalVehicle::toJson(const RentalVehicle &vehicle)
{
auto obj = Json::toJson(vehicle);
if (vehicle.d->remainingRange < 0) {
obj.remove(QLatin1String("remainingRange"));
}
if (vehicle.network().isValid()) {
obj.insert(QStringLiteral("network"), RentalVehicleNetwork::toJson(vehicle.network()));
obj.insert(QLatin1String("network"), RentalVehicleNetwork::toJson(vehicle.network()));
}
return obj;
}
......
......@@ -47,6 +47,11 @@ public:
/** Sharing network operator. */
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::RentalVehicleNetwork, network, setNetwork)
/** Remaining range of the vehicle in meters.
* Negative if unknown.
*/
KPUBLICTRANSPORT_PROPERTY(int, remainingRange, setRemainingRange)
public:
/** Serializes one object to JSON. */
static QJsonObject toJson(const RentalVehicle &vehicle);
......
......@@ -195,7 +195,7 @@ static void appendResults(const GBFSService &service, const LocationRequest &req
const auto stationId = bike.value(QLatin1String("bike_id")).toString();
loc.setIdentifier(service.systemId, stationId);
// TODO remaining range, deep rental links
// TODO deep rental links
RentalVehicle vehicle;
vehicle.setNetwork(network);
......@@ -205,8 +205,13 @@ static void appendResults(const GBFSService &service, const LocationRequest &req
}
const auto vehicleType = vehicleTypes.vehicleType(vehicleTypeId);
vehicle.setType(gbfs2kptVehicleType(vehicleType));
loc.setData(vehicle);
const auto range = bike.value(QLatin1String("current_range_meters")).toInt();
if (range > 0) { // there's too many reporting 0 for unknown that we can assume 0 means actually empty...
vehicle.setRemainingRange(range);
}
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