Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add currentFuelPercent and currentRangeMeters to RentalVehichle in the GTFS GraphQL API #6272

Open
wants to merge 36 commits into
base: dev-2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7fb3810
add currentFuelPercent to VehicleRentalVehicle and gtfs graphql API
JustCris654 Nov 5, 2024
b61c9f3
add currentRangeMeters to VehicleRentalVehicle and gtfs graphql API
JustCris654 Nov 22, 2024
1fa55b0
fix comment typo
JustCris654 Nov 22, 2024
4686f7c
use Distance class for currentRangeMeters
JustCris654 Dec 2, 2024
e93c828
add greater and less than methods for Distance
JustCris654 Dec 2, 2024
49c4682
Distance class tests
JustCris654 Dec 2, 2024
54292e2
represent currentRangeMeters with integer type
JustCris654 Dec 3, 2024
851c8b5
format RentalVehicleImpl file
JustCris654 Dec 3, 2024
d26799f
proper naming for static variables
JustCris654 Dec 3, 2024
e0bd36a
use Ratio scalar for currentFuelPercent
JustCris654 Dec 4, 2024
e9a572d
rename currentRangeMeters to currentRange
JustCris654 Dec 4, 2024
498d547
move conversion of Distance to-from meters to the api and gbfs mapping
JustCris654 Dec 4, 2024
eda75c8
remove unused code Distance class
JustCris654 Dec 4, 2024
3e7bf5b
group range and percent in fuel type
JustCris654 Dec 9, 2024
7d15f00
log warn if fuelPercent is invalid
JustCris654 Dec 9, 2024
9b9b585
check currentRangeMeters validity in free rental vehicle
JustCris654 Dec 11, 2024
c90bdd4
Ratio class
JustCris654 Dec 11, 2024
346449b
Ratio class for fuel percent validation
JustCris654 Dec 17, 2024
6edf98b
Ratio class and test format
JustCris654 Dec 17, 2024
0b1920d
fix check when range is required
JustCris654 Dec 17, 2024
54b0bc0
format GbfsFreeVehicleStatusMapper
JustCris654 Dec 17, 2024
f3e0a71
add range to scooter in GbfsFreeVehicleStatusMapperTest
JustCris654 Dec 17, 2024
26d8d7d
general fixes Ratio.java and Distance.java
JustCris654 Jan 7, 2025
4788055
RentalvehicleFuel properties docs comments
JustCris654 Jan 8, 2025
ff8411a
javadoc comment for Ratio class
JustCris654 Jan 9, 2025
6778169
check getCurrentFuelPercent null value and drop NPE
JustCris654 Jan 9, 2025
62e671f
Example on factory method with validation error handler passed in as …
t2gran Jan 9, 2025
f7d6b36
Cleanup Ratio implementation
t2gran Jan 9, 2025
4312caf
throttle invalid current fuel percent log
JustCris654 Jan 16, 2025
cd38992
Merge remote-tracking branch 'otp_master/pr-6272' into rentalVehicle_…
JustCris654 Jan 16, 2025
17a9d79
use Ratio refactor in tests
JustCris654 Jan 16, 2025
c941f62
Merge branch 'dev-2.x' into rentalVehicle_new_gbfs_fields
JustCris654 Jan 16, 2025
742bcd0
change distance value from meters to millimeters
JustCris654 Jan 21, 2025
c5a998d
factory method implementation for Distance
JustCris654 Jan 22, 2025
9e30029
expose Ratio and Distance from RentalVehicleFuel class
JustCris654 Jan 22, 2025
c00e615
Merge branch 'dev-2.x' into rentalVehicle_new_gbfs_fields
JustCris654 Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Set;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.opentripplanner.ext.fares.model.Distance;
import org.opentripplanner.transit.model.basic.Distance;
import org.opentripplanner.ext.fares.model.FareDistance;
import org.opentripplanner.ext.fares.model.FareDistance.LinearDistance;
import org.opentripplanner.ext.fares.model.FareLegRule;
Expand Down Expand Up @@ -331,15 +331,22 @@ class DistanceFares {
List<FareLegRule> distanceRules = List.of(
FareLegRule
.of(DISTANCE_ID, tenKmProduct)
.withFareDistance(new LinearDistance(Distance.ofKilometers(7), Distance.ofKilometers(10)))
.withFareDistance(new LinearDistance(
Distance.ofKilometersBoxed(7d, ignore -> {}).orElse(null),
Distance.ofKilometersBoxed(10d, ignore -> {}).orElse(null)))
.build(),
FareLegRule
.of(DISTANCE_ID, threeKmProduct)
.withFareDistance(new LinearDistance(Distance.ofKilometers(3), Distance.ofKilometers(6)))
.withFareDistance(new LinearDistance(
Distance.ofKilometersBoxed(3d, ignore -> {}).orElse(null),
Distance.ofKilometersBoxed(6d, ignore -> {}).orElse(null)))
.build(),
FareLegRule
.of(DISTANCE_ID, twoKmProduct)
.withFareDistance(new LinearDistance(Distance.ofMeters(0), Distance.ofMeters(2000)))
.withFareDistance(new LinearDistance(
Distance.ofMetersBoxed(0d, ignore -> {}).orElse(null),
Distance.ofMetersBoxed(2000d, ignore -> {}).orElse(null))
)
.build()
);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.opentripplanner.ext.fares.model;

import org.opentripplanner.transit.model.basic.Distance;

/** Represents a distance metric used in distance-based fare computation*/
public sealed interface FareDistance {
/** Represents the number of stops as a distance metric in fare computation */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.opentripplanner.apis.gtfs.datafetchers.QueryTypeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RealTimeEstimateImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RentalPlaceTypeResolver;
import org.opentripplanner.apis.gtfs.datafetchers.RentalVehicleFuelImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RentalVehicleImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RentalVehicleTypeImpl;
import org.opentripplanner.apis.gtfs.datafetchers.RideHailingEstimateImpl;
Expand Down Expand Up @@ -199,6 +200,7 @@ protected static GraphQLSchema buildSchema() {
.type(typeWiring.build(RealTimeEstimateImpl.class))
.type(typeWiring.build(EstimatedTimeImpl.class))
.type(typeWiring.build(EntranceImpl.class))
.type(typeWiring.build(RentalVehicleFuelImpl.class))
.build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
return schemaGenerator.makeExecutableSchema(typeRegistry, runtimeWiring);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.opentripplanner.apis.gtfs.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel;

public class RentalVehicleFuelImpl implements GraphQLDataFetchers.GraphQLRentalVehicleFuel {

@Override
public DataFetcher<Double> percent() {
return environment ->
getSource(environment).getPercent() != null
? getSource(environment).getPercent().asDouble()
: null;
}

@Override
public DataFetcher<Integer> range() {
return environment ->
getSource(environment).getRange() != null
? getSource(environment).getRange().toMeters()
: null;
}

private RentalVehicleFuel getSource(DataFetchingEnvironment environment) {
return environment.getSource();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.apis.gtfs.generated.GraphQLDataFetchers;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleType;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalStationUris;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem;
Expand All @@ -16,6 +17,11 @@ public DataFetcher<Boolean> allowPickupNow() {
return environment -> getSource(environment).allowPickupNow();
}

@Override
public DataFetcher<RentalVehicleFuel> fuel() {
return environment -> getSource(environment).getFuel();
}

@Override
public DataFetcher<Relay.ResolvedGlobalId> id() {
return environment ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.opentripplanner.service.vehicleparking.model.VehicleParkingSpaces;
import org.opentripplanner.service.vehicleparking.model.VehicleParkingState;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleEntityCounts;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleType;
import org.opentripplanner.service.vehiclerental.model.RentalVehicleTypeCount;
import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace;
Expand Down Expand Up @@ -908,6 +909,8 @@ public interface GraphQLRentalPlace extends TypeResolver {}
public interface GraphQLRentalVehicle {
public DataFetcher<Boolean> allowPickupNow();

public DataFetcher<RentalVehicleFuel> fuel();

public DataFetcher<graphql.relay.Relay.ResolvedGlobalId> id();

public DataFetcher<Double> lat();
Expand Down Expand Up @@ -935,6 +938,13 @@ public interface GraphQLRentalVehicleEntityCounts {
public DataFetcher<Integer> total();
}

/** Rental vehicle fuel represent the current status of the battery or fuel of a rental vehicle */
public interface GraphQLRentalVehicleFuel {
public DataFetcher<Double> percent();

public DataFetcher<Integer> range();
}

public interface GraphQLRentalVehicleType {
public DataFetcher<org.opentripplanner.apis.gtfs.generated.GraphQLTypes.GraphQLFormFactor> formFactor();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ config:
CallRealTime: org.opentripplanner.apis.gtfs.model.CallRealTime#CallRealTime
RentalPlace: org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace#VehicleRentalPlace
CallSchedule: org.opentripplanner.apis.gtfs.model.CallSchedule#CallSchedule
RentalVehicleFuel: org.opentripplanner.service.vehiclerental.model.RentalVehicleFuel#RentalVehicleFuel

Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static GraphQLObjectType create(
.name("currentRangeMeters")
.type(Scalars.GraphQLFloat)
.dataFetcher(environment ->
((VehicleRentalVehicle) environment.getSource()).currentRangeMeters
((VehicleRentalVehicle) environment.getSource()).getFuel().getRange()
)
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@

import java.util.Collection;
import java.util.Objects;
import org.opentripplanner.ext.fares.model.Distance;
import org.opentripplanner.ext.fares.model.FareDistance;
import org.opentripplanner.ext.fares.model.FareLegRule;
import org.opentripplanner.graph_builder.issue.api.DataImportIssueStore;
import org.opentripplanner.transit.model.basic.Distance;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class FareLegRuleMapper {

private static final Logger LOG = LoggerFactory.getLogger(FareLegRuleMapper.class);

private final FareProductMapper fareProductMapper;
private final DataImportIssueStore issueStore;

Expand Down Expand Up @@ -75,8 +79,28 @@ private static FareDistance createFareDistance(
fareLegRule.getMaxDistance().intValue()
);
case 1 -> new FareDistance.LinearDistance(
Distance.ofMeters(fareLegRule.getMinDistance()),
Distance.ofMeters(fareLegRule.getMaxDistance())
Distance
.ofMetersBoxed(
fareLegRule.getMinDistance(),
error ->
LOG.warn(
"Fare leg rule min distance not valid: {} - {}",
fareLegRule.getMinDistance(),
error
)
)
.orElse(null),
Distance
.ofMetersBoxed(
fareLegRule.getMaxDistance(),
error ->
LOG.warn(
"Fare leg rule max distance not valid: {} - {}",
fareLegRule.getMaxDistance(),
error
)
)
.orElse(null)
);
default -> null;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.opentripplanner.service.vehiclerental.model;

import javax.annotation.Nullable;
import org.opentripplanner.transit.model.basic.Distance;
import org.opentripplanner.transit.model.basic.Ratio;

/**
* Contains information about the current battery or fuel status.
* See the <a href="https://github.com/MobilityData/gbfs/blob/v3.0/gbfs.md#vehicle_statusjson">GBFS
* vehicle_status specification</a> for more details.
*/
public class RentalVehicleFuel {

/**
* Current fuel percentage, expressed from 0 to 1.
*/
@Nullable
public final Ratio percent;

/**
* Distance that the vehicle can travel with the current fuel.
*/
@Nullable
public final Distance range;

public RentalVehicleFuel(@Nullable Ratio fuelPercent, @Nullable Distance range) {
this.percent = fuelPercent;
this.range = range;
}

@Nullable
public Ratio getPercent() {
return this.percent;
}

@Nullable
public Distance getRange() {
return range;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class VehicleRentalVehicle implements VehicleRentalPlace {
public boolean isReserved = false;
public boolean isDisabled = false;
public Instant lastReported;
public Double currentRangeMeters;
public VehicleRentalStation station;
public String pricingPlanId;
public RentalVehicleFuel fuel;

@Override
public FeedScopedId getId() {
Expand Down Expand Up @@ -133,4 +133,8 @@ public VehicleRentalStationUris getRentalUris() {
public VehicleRentalSystem getVehicleRentalSystem() {
return system;
}

public RentalVehicleFuel getFuel() {
return fuel;
}
}
Loading
Loading