Search in sources :

Example 16 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getTripsForRoute.

/**
 * Return all trips in any pattern on the given route.
 */
@GET
@Path("/routes/{routeId}/trips")
public Response getTripsForRoute(@PathParam("routeId") String routeIdString) {
    AgencyAndId routeId = GtfsLibrary.convertIdFromString(routeIdString);
    Route route = index.routeForId.get(routeId);
    if (route != null) {
        List<Trip> trips = Lists.newArrayList();
        Collection<TripPattern> patterns = index.patternsForRoute.get(route);
        for (TripPattern pattern : patterns) {
            trips.addAll(pattern.getTrips());
        }
        return Response.status(Status.OK).entity(TripShort.list(trips)).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 17 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getStopsForTrip.

@GET
@Path("/trips/{tripId}/stops")
public Response getStopsForTrip(@PathParam("tripId") String tripIdString) {
    AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
    Trip trip = index.tripForId.get(tripId);
    if (trip != null) {
        TripPattern pattern = index.patternForTrip.get(trip);
        Collection<Stop> stops = pattern.getStops();
        return Response.status(Status.OK).entity(StopShort.list(stops)).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 18 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getGeometryForTrip.

/**
 * Return geometry for the trip as a packed coordinate sequence
 */
@GET
@Path("/trips/{tripId}/geometry")
public Response getGeometryForTrip(@PathParam("tripId") String tripIdString) {
    AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
    Trip trip = index.tripForId.get(tripId);
    if (trip != null) {
        TripPattern tripPattern = index.patternForTrip.get(trip);
        return getGeometryForPattern(tripPattern.code);
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 19 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class IndexAPI method getTrip.

// Not implemented, results would be too voluminous.
// @Path("/trips")
@GET
@Path("/trips/{tripId}")
public Response getTrip(@PathParam("tripId") String tripIdString) {
    AgencyAndId tripId = GtfsLibrary.convertIdFromString(tripIdString);
    Trip trip = index.tripForId.get(tripId);
    if (trip != null) {
        return Response.status(Status.OK).entity(trip).build();
    } else {
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 20 with Trip

use of org.onebusaway.gtfs.model.Trip in project OpenTripPlanner by opentripplanner.

the class GraphIndexTest method testPatternsCoherent.

/**
 * Check that bidirectional relationships between TripPatterns and Trips, Routes, and Stops are coherent.
 */
public void testPatternsCoherent() {
    for (Trip trip : graph.index.tripForId.values()) {
        TripPattern pattern = graph.index.patternForTrip.get(trip);
        assertTrue(pattern.getTrips().contains(trip));
    }
    /* This one depends on a feed where each TripPattern appears on only one route. */
    for (Route route : graph.index.routeForId.values()) {
        for (TripPattern pattern : graph.index.patternsForRoute.get(route)) {
            assertEquals(pattern.route, route);
        }
    }
    for (Stop stop : graph.index.stopForId.values()) {
        for (TripPattern pattern : graph.index.patternsForStop.get(stop)) {
            assertTrue(pattern.stopPattern.containsStop(stop.getId().toString()));
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10