From 3a1f3deb111b44c5320a0dc44cf61d9521453e5f Mon Sep 17 00:00:00 2001 From: sharhio Date: Thu, 7 Nov 2024 11:59:50 +0200 Subject: [PATCH 1/2] filter data from an updater --- .../SmooveBikeRentalDataSourceTest.java | 7 +- .../SmooveBikeRentalDataSourceParameters.java | 9 +- .../VehicleRentalServiceDirectoryFetcher.java | 4 +- .../sources/VehicleRentalSourceFactory.java | 25 ++++- .../updater/AllowedRentalType.java | 7 ++ .../GbfsVehicleRentalDataSource.java | 93 +++++++++++-------- ...GbfsVehicleRentalDataSourceParameters.java | 9 +- .../VehicleRentalDataSourceParameters.java | 3 + .../VehicleRentalUpdaterTest.java | 6 ++ .../GbfsVehicleRentalDataSourceTest.java | 10 +- 10 files changed, 123 insertions(+), 50 deletions(-) create mode 100644 application/src/main/java/org/opentripplanner/updater/AllowedRentalType.java diff --git a/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java b/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java index 761971bc56f..c9a327bea13 100644 --- a/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java +++ b/application/src/ext-test/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceTest.java @@ -7,6 +7,7 @@ import java.util.List; import org.junit.jupiter.api.Test; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.spi.HttpHeaders; class SmooveBikeRentalDataSourceTest { @@ -18,7 +19,8 @@ void makeStation() { "file:src/ext-test/resources/smoovebikerental/smoove.json", null, true, - HttpHeaders.empty() + HttpHeaders.empty(), + AllowedRentalType.ALL ) ); assertTrue(source.update()); @@ -84,7 +86,8 @@ void makeStationWithoutOverloading() { "file:src/ext-test/resources/smoovebikerental/smoove.json", null, false, - HttpHeaders.empty() + HttpHeaders.empty(), + AllowedRentalType.ALL ) ); assertTrue(source.update()); diff --git a/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java b/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java index 5aa834554c7..d509fa97b75 100644 --- a/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java +++ b/application/src/ext/java/org/opentripplanner/ext/smoovebikerental/SmooveBikeRentalDataSourceParameters.java @@ -1,6 +1,7 @@ package org.opentripplanner.ext.smoovebikerental; import javax.annotation.Nullable; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.spi.HttpHeaders; import org.opentripplanner.updater.vehicle_rental.VehicleRentalSourceType; import org.opentripplanner.updater.vehicle_rental.datasources.params.VehicleRentalDataSourceParameters; @@ -12,7 +13,8 @@ public record SmooveBikeRentalDataSourceParameters( String url, String network, boolean overloadingAllowed, - HttpHeaders httpHeaders + HttpHeaders httpHeaders, + AllowedRentalType allowedRentalType ) implements VehicleRentalDataSourceParameters { /** @@ -29,4 +31,9 @@ public String getNetwork(String defaultValue) { public VehicleRentalSourceType sourceType() { return VehicleRentalSourceType.SMOOVE; } + + @Override + public AllowedRentalType allowedRentalType() { + return allowedRentalType; + } } diff --git a/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java b/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java index 03b0acd59cd..8cd0ac0ebc5 100644 --- a/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java +++ b/application/src/ext/java/org/opentripplanner/ext/vehiclerentalservicedirectory/VehicleRentalServiceDirectoryFetcher.java @@ -110,7 +110,9 @@ private static List buildListOfNetworksFr networkName, networkParams.geofencingZones(), // overloadingAllowed - not part of GBFS, not supported here - false + false, + // allowedRentalType not supported + null ) ); } else { diff --git a/application/src/main/java/org/opentripplanner/standalone/config/routerconfig/updaters/sources/VehicleRentalSourceFactory.java b/application/src/main/java/org/opentripplanner/standalone/config/routerconfig/updaters/sources/VehicleRentalSourceFactory.java index aa548977c7e..5906b7ffc33 100644 --- a/application/src/main/java/org/opentripplanner/standalone/config/routerconfig/updaters/sources/VehicleRentalSourceFactory.java +++ b/application/src/main/java/org/opentripplanner/standalone/config/routerconfig/updaters/sources/VehicleRentalSourceFactory.java @@ -4,10 +4,12 @@ import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_1; import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_2; import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_3; +import static org.opentripplanner.standalone.config.framework.json.OtpVersion.V2_7; import org.opentripplanner.ext.smoovebikerental.SmooveBikeRentalDataSourceParameters; import org.opentripplanner.standalone.config.framework.json.NodeAdapter; import org.opentripplanner.standalone.config.routerconfig.updaters.HttpHeadersConfig; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.spi.HttpHeaders; import org.opentripplanner.updater.vehicle_rental.VehicleRentalSourceType; import org.opentripplanner.updater.vehicle_rental.datasources.params.GbfsVehicleRentalDataSourceParameters; @@ -43,13 +45,15 @@ public VehicleRentalDataSourceParameters create() { headers(), network(), geofencingZones(), - overloadingAllowed() + overloadingAllowed(), + allowedRentalType() ); case SMOOVE -> new SmooveBikeRentalDataSourceParameters( url(), network(), overloadingAllowed(), - headers() + headers(), + allowedRentalType() ); }; } @@ -121,4 +125,21 @@ private boolean geofencingZones() { ) .asBoolean(false); } + + private AllowedRentalType allowedRentalType() { + return c + .of("allowedRentalType") + .since(V2_7) + .summary("The type of rental data to include.") + .description( + """ + The type of rental data to include. This can be one of the following: + + - `ALL`: Include all data types. + - `STATIONS`: Include station data only. + - `VEHICLES`: Include floating vehicle data only. + """ + ) + .asEnum(AllowedRentalType.ALL); + } } diff --git a/application/src/main/java/org/opentripplanner/updater/AllowedRentalType.java b/application/src/main/java/org/opentripplanner/updater/AllowedRentalType.java new file mode 100644 index 00000000000..dff4cdcedae --- /dev/null +++ b/application/src/main/java/org/opentripplanner/updater/AllowedRentalType.java @@ -0,0 +1,7 @@ +package org.opentripplanner.updater; + +public enum AllowedRentalType { + STATIONS, + VEHICLES, + ALL, +} diff --git a/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSource.java b/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSource.java index c441efb974a..aa766b5eb48 100644 --- a/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSource.java +++ b/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSource.java @@ -22,6 +22,7 @@ import org.opentripplanner.service.vehiclerental.model.RentalVehicleType; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.service.vehiclerental.model.VehicleRentalSystem; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.vehicle_rental.datasources.params.GbfsVehicleRentalDataSourceParameters; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -76,60 +77,72 @@ public List getUpdates() { List stations = new LinkedList<>(); - // Both station information and status are required for all systems using stations - GBFSStationInformation stationInformation = loader.getFeed(GBFSStationInformation.class); - GBFSStationStatus stationStatus = loader.getFeed(GBFSStationStatus.class); - if (stationInformation != null && stationStatus != null) { - // Index all the station status entries on their station ID. - Map statusLookup = stationStatus - .getData() - .getStations() - .stream() - .collect(Collectors.toMap(GBFSStation::getStationId, Function.identity())); - GbfsStationStatusMapper stationStatusMapper = new GbfsStationStatusMapper( - statusLookup, - vehicleTypes - ); - GbfsStationInformationMapper stationInformationMapper = new GbfsStationInformationMapper( - system, - vehicleTypes, - params.allowKeepingRentedVehicleAtDestination(), - params.overloadingAllowed() - ); - - // Iterate over all known stations, and if we have any status information add it to those station objects. - stations.addAll( - stationInformation + if ( + params.allowedRentalType() == null || + params.allowedRentalType() == AllowedRentalType.ALL || + params.allowedRentalType() == AllowedRentalType.STATIONS + ) { + // Both station information and status are required for all systems using stations + GBFSStationInformation stationInformation = loader.getFeed(GBFSStationInformation.class); + GBFSStationStatus stationStatus = loader.getFeed(GBFSStationStatus.class); + if (stationInformation != null && stationStatus != null) { + // Index all the station status entries on their station ID. + Map statusLookup = stationStatus .getData() .getStations() .stream() - .map(stationInformationMapper::mapStationInformation) - .filter(Objects::nonNull) - .peek(stationStatusMapper::fillStationStatus) - .toList() - ); - } - - // Append the floating bike stations. - if (OTPFeature.FloatingBike.isOn()) { - GBFSFreeBikeStatus freeBikeStatus = loader.getFeed(GBFSFreeBikeStatus.class); - if (freeBikeStatus != null) { - GbfsFreeVehicleStatusMapper freeVehicleStatusMapper = new GbfsFreeVehicleStatusMapper( - system, + .collect(Collectors.toMap(GBFSStation::getStationId, Function.identity())); + GbfsStationStatusMapper stationStatusMapper = new GbfsStationStatusMapper( + statusLookup, vehicleTypes ); + GbfsStationInformationMapper stationInformationMapper = new GbfsStationInformationMapper( + system, + vehicleTypes, + params.allowKeepingRentedVehicleAtDestination(), + params.overloadingAllowed() + ); + + // Iterate over all known stations, and if we have any status information add it to those station objects. stations.addAll( - freeBikeStatus + stationInformation .getData() - .getBikes() + .getStations() .stream() - .map(freeVehicleStatusMapper::mapFreeVehicleStatus) + .map(stationInformationMapper::mapStationInformation) .filter(Objects::nonNull) + .peek(stationStatusMapper::fillStationStatus) .toList() ); } } + if ( + params.allowedRentalType() == null || + params.allowedRentalType() == AllowedRentalType.ALL || + params.allowedRentalType() == AllowedRentalType.VEHICLES + ) { + // Append the floating bike stations. + if (OTPFeature.FloatingBike.isOn()) { + GBFSFreeBikeStatus freeBikeStatus = loader.getFeed(GBFSFreeBikeStatus.class); + if (freeBikeStatus != null) { + GbfsFreeVehicleStatusMapper freeVehicleStatusMapper = new GbfsFreeVehicleStatusMapper( + system, + vehicleTypes + ); + stations.addAll( + freeBikeStatus + .getData() + .getBikes() + .stream() + .map(freeVehicleStatusMapper::mapFreeVehicleStatus) + .filter(Objects::nonNull) + .toList() + ); + } + } + } + if (params.geofencingZones()) { var zones = loader.getFeed(GBFSGeofencingZones.class); if (zones != null) { diff --git a/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/GbfsVehicleRentalDataSourceParameters.java b/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/GbfsVehicleRentalDataSourceParameters.java index 7d7a6c75a5d..473da63da7f 100644 --- a/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/GbfsVehicleRentalDataSourceParameters.java +++ b/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/GbfsVehicleRentalDataSourceParameters.java @@ -1,5 +1,6 @@ package org.opentripplanner.updater.vehicle_rental.datasources.params; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.spi.HttpHeaders; import org.opentripplanner.updater.vehicle_rental.VehicleRentalSourceType; @@ -10,11 +11,17 @@ public record GbfsVehicleRentalDataSourceParameters( HttpHeaders httpHeaders, String network, boolean geofencingZones, - boolean overloadingAllowed + boolean overloadingAllowed, + AllowedRentalType allowedRentalType ) implements VehicleRentalDataSourceParameters { @Override public VehicleRentalSourceType sourceType() { return VehicleRentalSourceType.GBFS; } + + @Override + public AllowedRentalType allowedRentalType() { + return allowedRentalType; + } } diff --git a/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/VehicleRentalDataSourceParameters.java b/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/VehicleRentalDataSourceParameters.java index cdff994ab18..b035ca71fbd 100644 --- a/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/VehicleRentalDataSourceParameters.java +++ b/application/src/main/java/org/opentripplanner/updater/vehicle_rental/datasources/params/VehicleRentalDataSourceParameters.java @@ -1,6 +1,7 @@ package org.opentripplanner.updater.vehicle_rental.datasources.params; import javax.annotation.Nullable; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.spi.HttpHeaders; import org.opentripplanner.updater.vehicle_rental.VehicleRentalSourceType; @@ -13,4 +14,6 @@ public interface VehicleRentalDataSourceParameters { VehicleRentalSourceType sourceType(); HttpHeaders httpHeaders(); + + AllowedRentalType allowedRentalType(); } diff --git a/application/src/test/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdaterTest.java b/application/src/test/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdaterTest.java index 2ca93a10f28..b1ca4173dac 100644 --- a/application/src/test/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdaterTest.java +++ b/application/src/test/java/org/opentripplanner/updater/vehicle_rental/VehicleRentalUpdaterTest.java @@ -15,6 +15,7 @@ import org.opentripplanner.service.vehiclerental.internal.DefaultVehicleRentalService; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; import org.opentripplanner.transit.service.TimetableRepository; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.DefaultRealTimeUpdateContext; import org.opentripplanner.updater.GraphUpdaterManager; import org.opentripplanner.updater.GraphWriterRunnable; @@ -103,5 +104,10 @@ public VehicleRentalSourceType sourceType() { public HttpHeaders httpHeaders() { return HttpHeaders.empty(); } + + @Override + public AllowedRentalType allowedRentalType() { + return AllowedRentalType.ALL; + } } } diff --git a/application/src/test/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSourceTest.java b/application/src/test/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSourceTest.java index 7b062bcc17c..bf557282b7d 100644 --- a/application/src/test/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSourceTest.java +++ b/application/src/test/java/org/opentripplanner/updater/vehicle_rental/datasources/GbfsVehicleRentalDataSourceTest.java @@ -14,6 +14,7 @@ import org.opentripplanner.service.vehiclerental.model.GeofencingZone; import org.opentripplanner.service.vehiclerental.model.RentalVehicleType; import org.opentripplanner.service.vehiclerental.model.VehicleRentalPlace; +import org.opentripplanner.updater.AllowedRentalType; import org.opentripplanner.updater.spi.HttpHeaders; import org.opentripplanner.updater.vehicle_rental.datasources.params.GbfsVehicleRentalDataSourceParameters; @@ -32,7 +33,8 @@ void makeStationFromV22() { HttpHeaders.empty(), null, false, - false + false, + AllowedRentalType.ALL ), new OtpHttpClientFactory() ); @@ -123,7 +125,8 @@ void geofencing() { HttpHeaders.empty(), null, true, - false + false, + AllowedRentalType.ALL ), new OtpHttpClientFactory() ); @@ -165,7 +168,8 @@ void makeStationFromV10() { HttpHeaders.empty(), network, false, - true + true, + AllowedRentalType.ALL ), new OtpHttpClientFactory() ); From 55e7913f5e8e9340ea56237ace241c64cc0681d3 Mon Sep 17 00:00:00 2001 From: sharhio Date: Thu, 7 Nov 2024 13:58:46 +0200 Subject: [PATCH 2/2] Updater config documentation --- doc/user/UpdaterConfig.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/user/UpdaterConfig.md b/doc/user/UpdaterConfig.md index cc5e1d75901..6638c1e95b4 100644 --- a/doc/user/UpdaterConfig.md +++ b/doc/user/UpdaterConfig.md @@ -317,6 +317,7 @@ GBFS form factors: |---------------------------------------------------------------------------------------|:---------------:|---------------------------------------------------------------------------------|:----------:|---------------|:-----:| | type = "vehicle-rental" | `enum` | The type of the updater. | *Required* | | 1.5 | | [allowKeepingRentedVehicleAtDestination](#u_1_allowKeepingRentedVehicleAtDestination) | `boolean` | If a vehicle should be allowed to be kept at the end of a station-based rental. | *Optional* | `false` | 2.1 | +| [allowedRentalType](#u_1_allowedRentalType) | `enum` | The type of rental data to include. | *Optional* | `"all"` | 2.7 | | frequency | `duration` | How often the data should be updated. | *Optional* | `"PT1M"` | 1.5 | | [geofencingZones](#u_1_geofencingZones) | `boolean` | Compute rental restrictions based on GBFS 2.2 geofencing zones. | *Optional* | `false` | 2.3 | | language | `string` | TODO | *Optional* | | 2.1 | @@ -346,6 +347,21 @@ For this to be possible three things need to be configured: - If keeping the vehicle at the destination should be discouraged, then `keepingRentedVehicleAtDestinationCost` (default: 0) may also be set in the routing defaults. +

allowedRentalType

+ +**Since version:** `2.7` ∙ **Type:** `enum` ∙ **Cardinality:** `Optional` ∙ **Default value:** `"all"` +**Path:** /updaters/[1] +**Enum values:** `stations` | `vehicles` | `all` + +The type of rental data to include. + +The type of rental data to include. This can be one of the following: + +- `ALL`: Include all data types. +- `STATIONS`: Include station data only. +- `VEHICLES`: Include floating vehicle data only. + +

geofencingZones

**Since version:** `2.3` ∙ **Type:** `boolean` ∙ **Cardinality:** `Optional` ∙ **Default value:** `false`