Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev-2.x' into otp2_journey_request
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesj committed Sep 15, 2022
2 parents 56b8200 + 0c9bf26 commit c35043c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private GraphQLObjectType createGraphQLType() {
"This is a performance limit and should therefore be set high. " +
"Use filters to limit what is presented to the client."
)
.type(Scalars.GraphQLFloat)
.dataFetcher(env -> preferences.street().maxDirectDurationDefaultValue().toSeconds())
.type(Scalars.GraphQLInt)
.dataFetcher(env -> preferences.street().maxDirectDuration().defaultValueSeconds())
.build()
)
.field(
Expand Down Expand Up @@ -315,7 +315,7 @@ private GraphQLObjectType createGraphQLType() {
.name("boardSlackDefault")
.description(TransportModeSlack.boardSlackDescription("boardSlackList"))
.type(Scalars.GraphQLInt)
.dataFetcher(e -> preferences.transit().boardSlack().defaultValue().toSeconds())
.dataFetcher(e -> preferences.transit().boardSlack().defaultValueSeconds())
.build()
)
.field(
Expand All @@ -333,7 +333,7 @@ private GraphQLObjectType createGraphQLType() {
.name("alightSlackDefault")
.description(TransportModeSlack.alightSlackDescription("alightSlackList"))
.type(Scalars.GraphQLInt)
.dataFetcher(e -> preferences.transit().alightSlack().defaultValue().toSeconds())
.dataFetcher(e -> preferences.transit().alightSlack().defaultValueSeconds())
.build()
)
.field(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public static GraphQLFieldDefinition create(
.name("boardSlackDefault")
.description(TransportModeSlack.boardSlackDescription("boardSlackList"))
.type(Scalars.GraphQLInt)
.defaultValue(preferences.transit().boardSlack().defaultValue().toSeconds())
.defaultValue(preferences.transit().boardSlack().defaultValueSeconds())
.build()
)
.argument(
Expand All @@ -377,7 +377,7 @@ public static GraphQLFieldDefinition create(
.name("alightSlackDefault")
.description(TransportModeSlack.alightSlackDescription("alightSlackList"))
.type(Scalars.GraphQLInt)
.defaultValue(preferences.transit().alightSlack().defaultValue().toSeconds())
.defaultValue(preferences.transit().alightSlack().defaultValueSeconds())
.build()
)
.argument(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public TravelTimeResource(
routingRequest
.preferences()
.street()
.maxAccessEgressDuration(routingRequest.journey().access().mode())
.maxAccessEgressDuration()
.valueOf(routingRequest.journey().access().mode())
);

if (time != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,8 @@ protected RouteRequest buildRequest(MultivaluedMap<String, String> queryParamete
if (minTransferTime != null) {
int alightAndBoardSlack =
(
(int) transitPref.boardSlack().defaultValue().toSeconds() +
(int) transitPref.alightSlack().defaultValue().toSeconds()
transitPref.boardSlack().defaultValueSeconds() +
transitPref.alightSlack().defaultValueSeconds()
);
if (alightAndBoardSlack > minTransferTime) {
throw new IllegalArgumentException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static Collection<NearbyStop> streetSearch(
NearbyStopFinder nearbyStopFinder = new NearbyStopFinder(
rctx.graph,
transitService,
nearbyRequest.preferences().street().maxAccessEgressDuration(streetMode),
nearbyRequest.preferences().street().maxAccessEgressDuration().valueOf(streetMode),
true
);
List<NearbyStop> nearbyStopList = nearbyStopFinder.findNearbyStopsViaStreets(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private static double calculateDistanceMaxLimit(RouteRequest request) {
double distanceLimit;
StreetMode mode = request.journey().direct().mode();

double durationLimit = preferences.street().maxDirectDuration(mode).toSeconds();
double durationLimit = preferences.street().maxDirectDuration().valueOf(mode).toSeconds();

if (mode.includesDriving()) {
distanceLimit = durationLimit * preferences.car().speed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public Duration defaultValue() {
return defaultValue;
}

/**
* Utility method to get {@link #defaultValue} as an number in unit seconds. Equivalent to
* {@code (int) defaultValue.toSeconds()}. The downcast is safe since we only allow days, hours,
* and so on in the duration.
*/
public int defaultValueSeconds() {
return (int) defaultValue.toSeconds();
}

public Duration valueOf(E type) {
return valueForEnum[type.ordinal()];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,16 @@ public void setElevatorHopCost(int elevatorHopCost) {
this.elevatorHopCost = elevatorHopCost;
}

/** @see #maxAccessEgressDuration(StreetMode) */
public Duration maxAccessEgressDurationDefaultValue() {
return maxAccessEgressDuration.defaultValue();
}

/**
* This is the maximum duration for access/egress per street mode for street searches. This is a
* performance limit and should therefore be set high. Results close to the limit are not
* guaranteed to be optimal. Use* itinerary-filters to limit what is presented to the client.
* guaranteed to be optimal. Use itinerary-filters to limit what is presented to the client.
* <p>
* The duration can be set per mode, because some street modes searches are much more resource
* intensive than others.
* intensive than others. A default value is applied if the mode specific value do not exist.
*/
public Duration maxAccessEgressDuration(StreetMode mode) {
return maxAccessEgressDuration.valueOf(mode);
public DurationForEnum<StreetMode> maxAccessEgressDuration() {
return maxAccessEgressDuration;
}

public void initMaxAccessEgressDuration(Duration defaultValue, Map<StreetMode, Duration> values) {
Expand All @@ -101,14 +96,10 @@ public void initMaxAccessEgressDuration(Duration defaultValue, Map<StreetMode, D
* optimal. Use itinerary-filters to limit what is presented to the client.
* <p>
* The duration can be set per mode, because some street modes searches are much more resource
* intensive than others.
* intensive than others. A default value is applied if the mode specific value do not exist.
*/
public Duration maxDirectDurationDefaultValue() {
return maxDirectDuration.defaultValue();
}

public Duration maxDirectDuration(StreetMode mode) {
return maxDirectDuration.valueOf(mode);
public DurationForEnum<StreetMode> maxDirectDuration() {
return maxDirectDuration;
}

public void initMaxDirectDuration(Duration defaultValue, Map<StreetMode, Duration> valuePerMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public List<GraphPath> getPaths(RoutingContext routingContext) {

AStarBuilder aStar = AStarBuilder
.oneToOneMaxDuration(
preferences.street().maxDirectDuration(options.journey().direct().mode())
preferences.street().maxDirectDuration().valueOf(options.journey().direct().mode())
)
// FORCING the dominance function to weight only
.setDominanceFunction(new DominanceFunction.MinimumWeight())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static RouteRequest mapRoutingRequest(NodeAdapter c) {
.initMaxAccessEgressDuration(
c.asDuration(
"maxAccessEgressDuration",
preferences.street().maxAccessEgressDurationDefaultValue()
preferences.street().maxAccessEgressDuration().defaultValue()
),
c.asEnumMap("maxAccessEgressDurationForMode", StreetMode.class, NodeAdapter::asDuration)
);
Expand Down Expand Up @@ -172,7 +172,7 @@ public static RouteRequest mapRoutingRequest(NodeAdapter c) {
.initMaxDirectDuration(
c.asDuration(
"maxDirectStreetDuration",
preferences.street().maxDirectDurationDefaultValue()
preferences.street().maxDirectDuration().defaultValue()
),
c.asEnumMap("maxDirectStreetDurationForMode", StreetMode.class, NodeAdapter::asDuration)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void testToString() {
@Test
void defaultValue() {
assertEquals(DEFAULT, subject.defaultValue());
assertEquals(DEFAULT.toSeconds(), subject.defaultValueSeconds());
}

@Test
Expand Down

0 comments on commit c35043c

Please sign in to comment.