Skip to content

Commit

Permalink
Merge pull request #2942 from entur/otp2_support_for_paging_results
Browse files Browse the repository at this point in the history
SW_3 - Otp2 support for paging results
  • Loading branch information
t2gran committed Feb 5, 2020
2 parents afe6da4 + 9c4eaa3 commit 7511cfc
Show file tree
Hide file tree
Showing 18 changed files with 412 additions and 105 deletions.
8 changes: 8 additions & 0 deletions docs/Basic-Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ If you have extracted a smaller PBF file from a larger region, be sure to put on

## Start up OTP

**TODO OTP2**

THIS SECTION NEEDS CLEANUP - THERE IS STILL A FEW PR HANGING AND WE WILL NOT
UPDATE THIS SECTION BEFORE ALL OF THEM ARE MERGED - THIS SHOULD BE FIXED AT
LATEST AT THE TIME OF THE OTP 2 BETA/RELEASE CANDIDATE.

INCLUDE IMAGE FROM [ISSUE #2904](https://github.com/opentripplanner/OpenTripPlanner/issues/2904) HERE. THIS IMAGE IS THE BEST DOC ON PARAMETERS TOGETER WITH THE `--help` OPTION RIGHT NOW.

As a Java program, OTP must be run within a Java virtual machine (JVM), which is provided as part of the Java runtime (JRE) or Java development kit (JDK). Run `java -version` to check that you have version 11 or newer of the JVM installed. If you do not, you will need to install a recent OpenJDK or Oracle Java package for your operating system.

GTFS and OSM data sets are often very large, and OTP is relatively memory-hungry. You will need at least 1GB of memory when working with the Portland TriMet data set, and several gigabytes for larger inputs. A typical command to start OTP looks like `java -Xmx1G -jar otp.shaded.jar <options>`. The `-Xmx` parameter sets the limit on how much memory OTP is allowed to consume. If you have sufficient memory in your computer,
Expand Down
1 change: 1 addition & 0 deletions docs/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Limit the transit service period(#2925).
- Removed unwanted cost added for wait time between access and transit with RangeRaptor (#2927)
- Dynamic search parameters, calculate raptor search-window when needed. (#2931)
- Support for next/previous paging trip search results (#2941)

## Ported over from the 1.x
- Add application/x-protobuf to accepted protobuf content-types (#2839)
Expand Down
23 changes: 23 additions & 0 deletions docs/OTP2-MigrationGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@ These properties changed names from:
- `htmlAnnotations` to `dataImportReport`
- `maxHtmlAnnotationsPerFile` to `maxDataImportIssuesPerFile`

## Command line
TODO OTP2

## REST API

A lot of the parameters in the REST API is ignored/deprecated look at the `RoutingRequest` class
for documentation.

In OTP1 most client provided a way to page the results by looking at the trips returned and passing
in something like the `last-depature-time` + 1 minute to the next request, to get trips to add to
the already fetched results. In OTP2 the recommended way to do this is to use the new `TripPlan`
`metadata` returned by the rout call.

### RoutingRequest changes
See JavaDoc on the RoutingRequest for full documentation of deprecated fields and doc on new fields. Her is a short list of new filed:

- `searchWindow` Limit the departure window or arrival window for the routing search.

### Response changes

- `metadata` is added to `TripPlan`. The `TripSearchMetadata` has three fields:
- `searchWindowUsed`
- `nextDateTime`
- `prevDateTime`


Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
package org.opentripplanner.ext.transmodelapi;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import graphql.schema.DataFetchingEnvironment;
import org.apache.commons.lang3.StringUtils;
import org.opentripplanner.api.common.Message;
import org.opentripplanner.api.common.ParameterException;
import org.opentripplanner.api.model.TripPlan;
import org.opentripplanner.api.model.error.PlannerError;
import org.opentripplanner.api.parameter.QualifiedModeSet;
import org.opentripplanner.api.resource.DebugOutput;
import org.opentripplanner.common.model.GenericLocation;
import org.opentripplanner.ext.transmodelapi.mapping.TransmodelMappingUtil;
import org.opentripplanner.ext.transmodelapi.model.PlanResponse;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.routing.RoutingResponse;
import org.opentripplanner.routing.algorithm.RoutingWorker;
import org.opentripplanner.routing.algorithm.mapping.TripPlanMapper;
import org.opentripplanner.routing.core.OptimizeType;
Expand All @@ -26,7 +24,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -51,34 +48,30 @@ public TransmodelGraphQLPlanner(TransmodelMappingUtil mappingUtil) {
this.mappingUtil = mappingUtil;
}

public Map<String, Object> plan(DataFetchingEnvironment environment) {
public PlanResponse plan(DataFetchingEnvironment environment) {
Router router = environment.getContext();
RoutingRequest request = createRequest(environment);

TripPlan plan;
List<Message> messages = new ArrayList<>();
DebugOutput debugOutput = new DebugOutput();
PlanResponse response = new PlanResponse();

try {
RoutingWorker worker = new RoutingWorker(request);
plan = worker.route(router);
RoutingResponse res = worker.route(router);
response.plan = res.getTripPlan();
response.metadata = res.getMetadata();
}
catch (Exception e) {
plan = TripPlanMapper.mapTripPlan(request, Collections.emptyList());
response.plan = TripPlanMapper.mapTripPlan(request, Collections.emptyList());
PlannerError error = new PlannerError(e);
if (!PlannerError.isPlanningError(e.getClass()))
LOG.warn("Error while planning path: ", e);
messages.add(error.message);
response.messages.add(error.message);
} finally {
if (request.rctx != null) {
debugOutput = request.rctx.debugOutput;
response.debugOutput = request.rctx.debugOutput;
}
}
return ImmutableMap.<String, Object>builder()
.put("plan", plan)
.put("messages", messages)
.put("debugOutput", debugOutput)
.build();
return response;
}

private static <T> void call(Map<String, T> m, String name, Consumer<T> consumer) {
Expand Down Expand Up @@ -131,11 +124,12 @@ private GenericLocation toGenericLocation(Map<String, Object> m) {
lon = (Double) coordinates.get("longitude");
}

String placeRef = (String) m.get("place"); // TODO OTP2 mappingUtil.preparePlaceRef((String) m.get("place"));
String placeRef = (String) m.get("place");
FeedScopedId stopId = placeRef == null ? null : mappingUtil.fromIdString(placeRef);
String name = (String) m.get("name");
name = name == null ? "" : name;

return new GenericLocation(name, mappingUtil.fromIdString(placeRef), lat, lon);
return new GenericLocation(name, stopId, lat, lon);
}

private RoutingRequest createRequest(DataFetchingEnvironment environment) {
Expand All @@ -154,6 +148,7 @@ private RoutingRequest createRequest(DataFetchingEnvironment environment) {
} else {
request.setDateTime(new Date());
}
callWith.argument("searchWindow", request::setSearchWindowSeconds);
callWith.argument("wheelchair", request::setWheelchairAccessible);
callWith.argument("numTripPatterns", request::setNumItineraries);
callWith.argument("maximumWalkDistance", request::setMaxWalkDistance);
Expand Down

0 comments on commit 7511cfc

Please sign in to comment.