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

Distinct coach from bus when reading in GTFS data and in GTFS GraphQL API #6171

Merged
merged 8 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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 @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.List;
import org.opentripplanner.framework.application.OTPFeature;
miklcct marked this conversation as resolved.
Show resolved Hide resolved
import org.opentripplanner.transit.model.basic.TransitMode;

public enum ApiRequestMode {
Expand All @@ -12,7 +13,8 @@ public enum ApiRequestMode {
TRAM(TransitMode.TRAM),
SUBWAY(TransitMode.SUBWAY),
RAIL(TransitMode.RAIL),
BUS(TransitMode.BUS, TransitMode.COACH),
BUS(TransitMode.BUS),
COACH(TransitMode.COACH),
miklcct marked this conversation as resolved.
Show resolved Hide resolved
FERRY(TransitMode.FERRY),
CABLE_CAR(TransitMode.CABLE_CAR),
GONDOLA(TransitMode.GONDOLA),
Expand Down Expand Up @@ -40,6 +42,10 @@ public enum ApiRequestMode {
}

public Collection<TransitMode> getTransitModes() {
if (this == BUS && OTPFeature.GtfsCoach.isOff()) {
return List.of(TransitMode.BUS, TransitMode.COACH);
}

return transitModes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ public enum OTPFeature {
"Should there be a transfer leg when transferring on the very same stop. Note that for in-seat/interlined transfers no transfer leg will be generated."
),
FloatingBike(true, false, "Enable floating bike routing."),
GtfsCoach(
false,
false,
"""
When parsing GTFS data, treat GTFS route type 200 to 299 as coach routes instead of bus routes.
When using the GTFS GraphQL API, do not return coach routes when only BUS is specified as a mode.
miklcct marked this conversation as resolved.
Show resolved Hide resolved
"""
),
GtfsGraphQlApi(true, false, "Enable the [GTFS GraphQL API](apis/GTFS-GraphQL-API.md)."),
GtfsGraphQlApiRentalStationFuzzyMatching(
false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opentripplanner.gtfs.mapping;

import org.opentripplanner.framework.application.OTPFeature;
miklcct marked this conversation as resolved.
Show resolved Hide resolved
import org.opentripplanner.transit.model.basic.TransitMode;

public class TransitModeMapper {
Expand All @@ -19,7 +20,7 @@ public static TransitMode mapMode(int routeType) {
if (routeType >= 100 && routeType < 200) { // Railway Service
return TransitMode.RAIL;
} else if (routeType >= 200 && routeType < 300) { //Coach Service
return TransitMode.BUS;
return OTPFeature.GtfsCoach.isOn() ? TransitMode.COACH : TransitMode.BUS;
} else if (routeType >= 300 && routeType < 500) { //Suburban Railway Service and Urban Railway service
if (routeType >= 401 && routeType <= 402) {
return TransitMode.SUBWAY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.opentripplanner.apis.gtfs.TestRoutingService;
import org.opentripplanner.apis.gtfs.generated.GraphQLTypes;
import org.opentripplanner.ext.fares.impl.DefaultFareService;
import org.opentripplanner.framework.application.OTPFeature;
import org.opentripplanner.model.plan.PlanTestConstants;
import org.opentripplanner.routing.api.request.RouteRequest;
import org.opentripplanner.routing.api.request.preference.TimeSlopeSafetyTriangle;
Expand Down Expand Up @@ -144,9 +145,36 @@ static Stream<Arguments> transportModesCases() {
);
}

static Stream<Arguments> transportModesCasesWithCoach() {
return Stream.of(
of(
List.of(mode("BUS")),
"[TransitFilterRequest{select: [SelectRequest{transportModes: [BUS]}]}]"
),
of(
List.of(mode("BUS"), mode("COACH")),
"[TransitFilterRequest{select: [SelectRequest{transportModes: [BUS, COACH]}]}]"
),
of(
List.of(mode("BUS"), mode("MONORAIL")),
"[TransitFilterRequest{select: [SelectRequest{transportModes: [BUS, MONORAIL]}]}]"
)
);
}

@ParameterizedTest
@MethodSource("transportModesCases")
void modes(List<Map<String, Object>> modes, String expectedFilters) {
OTPFeature.GtfsCoach.testOff(() -> testModes(modes, expectedFilters));
}

@ParameterizedTest
@MethodSource("transportModesCasesWithCoach")
void modesWithCoach(List<Map<String, Object>> modes, String expectedFilters) {
OTPFeature.GtfsCoach.testOn(() -> testModes(modes, expectedFilters));
miklcct marked this conversation as resolved.
Show resolved Hide resolved
}

private void testModes(List<Map<String, Object>> modes, String expectedFilters) {
Map<String, Object> arguments = Map.of("transportModes", modes);

var routeRequest = LegacyRouteRequestMapper.toRouteRequest(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.opentripplanner.gtfs.mapping;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opentripplanner.transit.model.basic.TransitMode.BUS;
import static org.opentripplanner.transit.model.basic.TransitMode.CARPOOL;
import static org.opentripplanner.transit.model.basic.TransitMode.COACH;
import static org.opentripplanner.transit.model.basic.TransitMode.TAXI;

import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
miklcct marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.opentripplanner.framework.application.OTPFeature;
miklcct marked this conversation as resolved.
Show resolved Hide resolved
import org.opentripplanner.transit.model.basic.TransitMode;

class TransitModeMapperTest {
Expand All @@ -29,4 +33,16 @@ static Stream<Arguments> testCases() {
void map(int mode, TransitMode expectedMode) {
assertEquals(expectedMode, TransitModeMapper.mapMode(mode));
}

@Test
void testCoachFeatureFlag() {
OTPFeature.GtfsCoach.testOff(() -> {
assertEquals(BUS, TransitModeMapper.mapMode(200));
assertEquals(BUS, TransitModeMapper.mapMode(299));
});
OTPFeature.GtfsCoach.testOn(() -> {
assertEquals(COACH, TransitModeMapper.mapMode(200));
assertEquals(COACH, TransitModeMapper.mapMode(299));
});
}
}
1 change: 1 addition & 0 deletions doc/user/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Here is a list of all features which can be toggled on/off and their default val
| `DebugUi` | Enable the debug GraphQL client and web UI and located at the root of the web server as well as the debug map tiles it uses. Be aware that the map tiles are not a stable API and can change without notice. Use the [vector tiles feature if](sandbox/MapboxVectorTilesApi.md) you want a stable map tiles API. | ✓️ | |
| `ExtraTransferLegOnSameStop` | Should there be a transfer leg when transferring on the very same stop. Note that for in-seat/interlined transfers no transfer leg will be generated. | | |
| `FloatingBike` | Enable floating bike routing. | ✓️ | |
| `GtfsCoach` | When parsing GTFS data, treat GTFS route type 200 to 299 as coach routes instead of bus routes. When using the GTFS GraphQL API, do not return coach routes when only BUS is specified as a mode. | | |
| `GtfsGraphQlApi` | Enable the [GTFS GraphQL API](apis/GTFS-GraphQL-API.md). | ✓️ | |
| `GtfsGraphQlApiRentalStationFuzzyMatching` | Does vehicleRentalStation query also allow ids that are not feed scoped. | | |
| `MinimumTransferTimeIsDefinitive` | If the minimum transfer time is a lower bound (default) or the definitive time for the transfer. Set this to `true` if you want to set a transfer time lower than what OTP derives from OSM data. | | |
Expand Down
Loading