Skip to content

Commit

Permalink
Merge branch 'coach_gtfs_import' into aubin-test
Browse files Browse the repository at this point in the history
  • Loading branch information
miklcct committed Oct 17, 2024
2 parents ec3f2c2 + 5cee140 commit c8259df
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 2 deletions.
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;
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),
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.
"""
),
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;
import org.opentripplanner.transit.model.basic.TransitMode;

public class TransitModeMapper {
Expand All @@ -20,7 +21,7 @@ public static TransitMode mapMode(int routeType) {
// 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));
}

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
Expand Up @@ -4,9 +4,11 @@
import static org.opentripplanner.transit.model.basic.TransitMode.*;

import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
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;
import org.opentripplanner.transit.model.basic.TransitMode;

class TransitModeMapperTest {
Expand Down Expand Up @@ -71,4 +73,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

0 comments on commit c8259df

Please sign in to comment.