Skip to content

Commit

Permalink
Merge pull request #352 from HSLdevcom/DT-4483
Browse files Browse the repository at this point in the history
DT-4483
  • Loading branch information
optionsome authored Mar 22, 2021
2 parents 5a84980 + 516f332 commit 4edabc8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 13 deletions.
16 changes: 14 additions & 2 deletions src/main/java/org/opentripplanner/index/IndexGraphQLSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -2329,16 +2329,22 @@ public IndexGraphQLSchema(GraphIndex index) {
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("bikesAvailable")
.description("Number of bikes currently available on the rental station. The total capacity of this bike rental station is the sum of fields `bikesAvailable` and `spacesAvailable`.")
.description("Number of bikes currently available on the rental station.")
.type(Scalars.GraphQLInt)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).bikesAvailable)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("spacesAvailable")
.description("Number of free spaces currently available on the rental station. The total capacity of this bike rental station is the sum of fields `bikesAvailable` and `spacesAvailable`. \n Note that this value being 0 does not necessarily indicate that bikes cannot be returned to this station, as it might be possible to leave the bike in the vicinity of the rental station, even if the bike racks don't have any spaces available (see field `allowDropoff`).")
.description("Number of free spaces currently available on the rental station. \n Note that this value being 0 does not necessarily indicate that bikes cannot be returned to this station, as it might be possible to leave the bike in the vicinity of the rental station, even if the bike racks don't have any spaces available (see field `allowDropoff`).")
.type(Scalars.GraphQLInt)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).spacesAvailable)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("capacity")
.description("Nominal capacity (number of racks) of the rental station.")
.type(Scalars.GraphQLInt)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).capacity)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("state")
.description("A description of the current state of this bike rental station, e.g. \"Station on\"")
Expand All @@ -2357,6 +2363,12 @@ public IndexGraphQLSchema(GraphIndex index) {
.type(Scalars.GraphQLBoolean)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).allowDropoff)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("allowOverloading")
.description("If true, bikes can be returned even if spacesAvailable is zero or bikes > capacity.")
.type(Scalars.GraphQLBoolean)
.dataFetcher(environment -> ((BikeRentalStation) environment.getSource()).allowOverloading)
.build())
.field(GraphQLFieldDefinition.newFieldDefinition()
.name("isFloatingBike")
.description("If true, this is a free floating bike.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ public class BikeRentalStation implements Serializable, Cloneable {
@JsonSerialize
public int spacesAvailable = Integer.MAX_VALUE;
@JsonSerialize
public int capacity = 0; // default, means nominal capacity not defined
@JsonSerialize
public boolean allowDropoff = true;
@JsonSerialize
public boolean allowOverloading = false;
@JsonSerialize
public boolean isFloatingBike = false;
@JsonSerialize
public boolean isCarStation = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ protected State traverseRent(State state) {
*/
if (noBikeRentalNetworkAllowed(options.allowedBikeRentalNetworks))
return null;

BikeRentalStationVertex dropoff = (BikeRentalStationVertex) tov;
if (options.useBikeRentalAvailabilityInformation && dropoff.getBikesAvailable() == 0)
return null;

StateEditor editor = state.edit(this);
editor.incrementWeight(options.arriveBy ? options.bikeRentalDropoffCost : options.bikeRentalPickupCost);
editor.incrementTimeInSeconds(options.arriveBy ? options.bikeRentalDropoffTime : options.bikeRentalPickupTime);
Expand Down Expand Up @@ -92,7 +92,7 @@ protected State traverseDropoff(State state) {
return null;

BikeRentalStationVertex pickup = (BikeRentalStationVertex) tov;
if (options.useBikeRentalAvailabilityInformation && pickup.getSpacesAvailable() == 0)
if (options.useBikeRentalAvailabilityInformation && pickup.getSpacesAvailable() == 0 && !pickup.getAllowOverloading())
return null;

StateEditor editor = state.edit(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class BikeRentalStationVertex extends Vertex {

private int spacesAvailable;

private boolean allowOverloading;

private String id;

/** Some car rental systems and flex transit systems work exactly like bike rental, but with cars. */
Expand All @@ -36,6 +38,7 @@ public BikeRentalStationVertex(Graph g, BikeRentalStation station) {
this.setId(station.id);
this.setBikesAvailable(station.bikesAvailable);
this.setSpacesAvailable(station.spacesAvailable);
this.setAllowOverloading(station.allowOverloading);
this.isCarStation = station.isCarStation;
this.station = station;
}
Expand All @@ -48,6 +51,10 @@ public int getSpacesAvailable() {
return spacesAvailable;
}

public boolean getAllowOverloading() {
return allowOverloading;
}

public void setBikesAvailable(int bikes) {
this.bikesAvailable = bikes;
}
Expand All @@ -56,6 +63,10 @@ public void setSpacesAvailable(int spaces) {
this.spacesAvailable = spaces;
}

public void setAllowOverloading(boolean allowOverloading) {
this.allowOverloading = allowOverloading;
}

public String getId() {
return id;
}
Expand All @@ -81,5 +92,6 @@ public void setStation(BikeRentalStation station) {
this.station = station;
this.bikesAvailable = station.bikesAvailable;
this.spacesAvailable = station.spacesAvailable;
this.allowOverloading = station.allowOverloading;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ protected void configurePolling (Graph graph, JsonNode config) throws Exception
// Each updater can be assigned a unique network ID in the configuration to prevent returning bikes at
// stations for another network. TODO shouldn't we give each updater a unique network ID by default?
String networkName = config.path("network").asText();
boolean allowOverloading = config.path("allowOverloading").asText().equals("true");

BikeRentalDataSource source = null;
if (sourceType != null) {
if (sourceType.equals("jcdecaux")) {
Expand Down Expand Up @@ -94,7 +96,7 @@ protected void configurePolling (Graph graph, JsonNode config) throws Exception
} else if (sourceType.equals("gbfs")) {
source = new GbfsBikeRentalDataSource(networkName);
} else if (sourceType.equals("smoove")) {
source = new SmooveBikeRentalDataSource(networkName);
source = new SmooveBikeRentalDataSource(networkName, allowOverloading);
} else if (sourceType.equals("bicimad")) {
source = new BicimadBikeRentalDataSource();
} else if (sourceType.equals("samocat")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@ public class SmooveBikeRentalDataSource extends GenericJsonBikeRentalDataSource
private static final Logger log = LoggerFactory.getLogger(SmooveBikeRentalDataSource.class);

private String networkName;
private boolean allowOverloading = false;

public SmooveBikeRentalDataSource(String networkName) {
public SmooveBikeRentalDataSource(String networkName, boolean allowOverloading) {
super("result");
this.networkName = defaultIfEmpty(networkName, "smoove");
this.allowOverloading = allowOverloading;
}

private String defaultIfEmpty(String value, String defaultValue) {
if (value == null || value.isEmpty())
return defaultValue;

return value;
}

/**
* <pre>
* {
Expand All @@ -63,22 +65,24 @@ private String defaultIfEmpty(String value, String defaultValue) {
* </pre>
*/
public BikeRentalStation makeStation(JsonNode node) {
// TODO: final winter maintenance value not known yet
BikeRentalStation station = new BikeRentalStation();
station.id = node.path("name").asText().split("\\s", 2)[0];
station.name = new NonLocalizedString(node.path("name").asText().split("\\s", 2)[1]);
station.state = node.path("style").asText();
station.networks = new HashSet<String>();
station.networks.add(this.networkName);
station.allowOverloading = this.allowOverloading;
try {
station.y = Double.parseDouble(node.path("coordinates").asText().split(",")[0].trim());
station.x = Double.parseDouble(node.path("coordinates").asText().split(",")[1].trim());
if (station.state.equals("Station on")) {
station.bikesAvailable = node.path("avl_bikes").asInt();
station.spacesAvailable = node.path("free_slots").asInt();
station.capacity = node.path("total_slots").asInt();
} else {
station.bikesAvailable = 0;
station.spacesAvailable = 0;
station.capacity = node.path("total_slots").asInt();
}
return station;
} catch (NumberFormatException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testKeolisRennes() {
}

public void testSmoove() {
SmooveBikeRentalDataSource source = new SmooveBikeRentalDataSource(null);
SmooveBikeRentalDataSource source = new SmooveBikeRentalDataSource(null, false);
source.setUrl("file:src/test/resources/bike/smoove.json");
assertTrue(source.update());
List<BikeRentalStation> rentalStations = source.getStations();
Expand Down Expand Up @@ -73,7 +73,7 @@ public void testSmoove() {
// Ignores mismatch with total_slots

// Test giving network name to data source
SmooveBikeRentalDataSource sourceWithCustomNetwork = new SmooveBikeRentalDataSource("Helsinki");
SmooveBikeRentalDataSource sourceWithCustomNetwork = new SmooveBikeRentalDataSource("Helsinki", true);
sourceWithCustomNetwork.setUrl("file:src/test/resources/bike/smoove.json");
assertTrue(sourceWithCustomNetwork.update());
List<BikeRentalStation> rentalStationsWithCustomNetwork = sourceWithCustomNetwork.getStations();
Expand Down

0 comments on commit 4edabc8

Please sign in to comment.