Search in sources :

Example 11 with Agency

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

the class IndexAPI method getAgencyRoutes.

/**
 * Return all routes for the specific agency.
 */
@GET
@Path("/agencies/{feedId}/{agencyId}/routes")
public Response getAgencyRoutes(@PathParam("feedId") String feedId, @PathParam("agencyId") String agencyId) {
    Collection<Route> routes = index.routeForId.values();
    Agency agency = index.agenciesForFeedId.get(feedId).get(agencyId);
    if (agency == null)
        return Response.status(Status.NOT_FOUND).entity(MSG_404).build();
    Collection<Route> agencyRoutes = new ArrayList<>();
    for (Route route : routes) {
        if (route.getAgency() == agency) {
            agencyRoutes.add(route);
        }
    }
    routes = agencyRoutes;
    if (detail) {
        return Response.status(Status.OK).entity(routes).build();
    } else {
        return Response.status(Status.OK).entity(RouteShort.list(routes)).build();
    }
}
Also used : Agency(org.onebusaway.gtfs.model.Agency) ArrayList(java.util.ArrayList) Route(org.onebusaway.gtfs.model.Route) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 12 with Agency

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

the class GraphIndexTest method testIdLookup.

public void testIdLookup() {
    /* Graph vertices */
    for (Vertex vertex : graph.index.vertexForId.values()) {
        if (vertex instanceof TransitStop) {
            Stop stop = ((TransitStop) vertex).getStop();
            Vertex index_vertex = graph.index.stopVertexForStop.get(stop);
            assertEquals(index_vertex, vertex);
        }
    }
    /* Agencies */
    String feedId = graph.getFeedIds().iterator().next();
    Agency agency;
    agency = graph.index.agenciesForFeedId.get(feedId).get("azerty");
    assertNull(agency);
    agency = graph.index.agenciesForFeedId.get(feedId).get("agency");
    assertEquals(agency.getId(), "agency");
    assertEquals(agency.getName(), "Fake Agency");
    /* Stops */
    graph.index.stopForId.get(new AgencyAndId("X", "Y"));
/* Trips */
// graph.index.tripForId;
// graph.index.routeForId;
// graph.index.serviceForId;
// graph.index.patternForId;
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) Agency(org.onebusaway.gtfs.model.Agency) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop)

Example 13 with Agency

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

the class OnBoardDepartServiceImplTest method testOnBoardAtStation.

@Test
public final void testOnBoardAtStation() {
    TransitStop station0 = mock(TransitStop.class);
    TransitStop station1 = mock(TransitStop.class);
    TransitStop station2 = mock(TransitStop.class);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex dwell = mock(PatternArriveVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
    ArrayList<Edge> hops = new ArrayList<Edge>(2);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    Agency agency = new Agency();
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
    StopTime stopDepartTime = new StopTime();
    StopTime stopDwellTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopDwell = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(new AgencyAndId("Station", "0"));
    stopDwell.setId(new AgencyAndId("Station", "1"));
    stopArrive.setId(new AgencyAndId("Station", "2"));
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopDwellTime.setArrivalTime(20);
    stopDwellTime.setStop(stopDwell);
    stopDwellTime.setDepartureTime(40);
    stopArriveTime.setArrivalTime(60);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopDwellTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    when(dwell.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop0 = new PatternHop(depart, dwell, stopDepart, stopDwell, 0);
    PatternHop patternHop1 = new PatternHop(dwell, arrive, stopDwell, stopArrive, 1);
    hops.add(patternHop0);
    hops.add(patternHop1);
    when(graph.getEdges()).thenReturn(hops);
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(dwell.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(graph.getVertex("Station_0")).thenReturn(station0);
    when(graph.getVertex("Station_1")).thenReturn(station1);
    when(graph.getVertex("Station_2")).thenReturn(station2);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(0);
    assertEquals(station0, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(20);
    assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(30);
    assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(40);
    assertEquals(station1, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(60);
    assertEquals(station2, onBoardDepartServiceImpl.setupDepartOnBoard(routingContext));
}
Also used : TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Edge(org.opentripplanner.routing.graph.Edge) Test(org.junit.Test)

Example 14 with Agency

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

the class OnBoardDepartServiceImplTest method testOnBoardDepartureAtArrivalTime.

@Test
public final void testOnBoardDepartureAtArrivalTime() {
    Coordinate[] coordinates = new Coordinate[2];
    coordinates[0] = new Coordinate(0.0, 0.0);
    coordinates[1] = new Coordinate(0.0, 1.0);
    TransitStop station0 = mock(TransitStop.class);
    TransitStop station1 = mock(TransitStop.class);
    PatternDepartVertex depart = mock(PatternDepartVertex.class);
    PatternArriveVertex arrive = mock(PatternArriveVertex.class);
    Graph graph = mock(Graph.class);
    RoutingRequest routingRequest = mock(RoutingRequest.class);
    ServiceDay serviceDay = mock(ServiceDay.class);
    // You're probably not supposed to do this to mocks (access their fields directly)
    // But I know of no other way to do this since the mock object has only action-free stub methods.
    routingRequest.modes = new TraverseModeSet("WALK,TRANSIT");
    when(graph.getTimeZone()).thenReturn(TimeZone.getTimeZone("GMT"));
    when(station0.getX()).thenReturn(coordinates[0].x);
    when(station0.getY()).thenReturn(coordinates[0].y);
    when(station1.getX()).thenReturn(coordinates[1].x);
    when(station1.getY()).thenReturn(coordinates[1].y);
    RoutingContext routingContext = new RoutingContext(routingRequest, graph, null, arrive);
    AgencyAndId agencyAndId = new AgencyAndId("Agency", "ID");
    Agency agency = new Agency();
    Route route = new Route();
    ArrayList<StopTime> stopTimes = new ArrayList<StopTime>(2);
    StopTime stopDepartTime = new StopTime();
    StopTime stopArriveTime = new StopTime();
    Stop stopDepart = new Stop();
    Stop stopArrive = new Stop();
    Trip trip = new Trip();
    routingContext.serviceDays = new ArrayList<ServiceDay>(Collections.singletonList(serviceDay));
    agency.setId(agencyAndId.getAgencyId());
    route.setId(agencyAndId);
    route.setAgency(agency);
    stopDepart.setId(new AgencyAndId("Station", "0"));
    stopArrive.setId(new AgencyAndId("Station", "1"));
    stopDepartTime.setStop(stopDepart);
    stopDepartTime.setDepartureTime(0);
    stopArriveTime.setArrivalTime(10);
    stopArriveTime.setStop(stopArrive);
    stopTimes.add(stopDepartTime);
    stopTimes.add(stopArriveTime);
    trip.setId(agencyAndId);
    trip.setRoute(route);
    TripTimes tripTimes = new TripTimes(trip, stopTimes, new Deduplicator());
    StopPattern stopPattern = new StopPattern(stopTimes);
    TripPattern tripPattern = new TripPattern(route, stopPattern);
    TripPattern.generateUniqueIds(Arrays.asList(tripPattern));
    when(depart.getTripPattern()).thenReturn(tripPattern);
    PatternHop patternHop = new PatternHop(depart, arrive, stopDepart, stopArrive, 0);
    when(graph.getEdges()).thenReturn(Collections.<Edge>singletonList(patternHop));
    when(depart.getCoordinate()).thenReturn(new Coordinate(0, 0));
    when(arrive.getCoordinate()).thenReturn(new Coordinate(0, 0));
    routingRequest.from = new GenericLocation();
    routingRequest.startingTransitTripId = agencyAndId;
    when(serviceDay.secondsSinceMidnight(anyInt())).thenReturn(10);
    when(graph.getVertex("Station_0")).thenReturn(station0);
    when(graph.getVertex("Station_1")).thenReturn(station1);
    tripPattern.add(tripTimes);
    graph.index = new GraphIndex(graph);
    Vertex vertex = onBoardDepartServiceImpl.setupDepartOnBoard(routingContext);
    assertEquals(coordinates[1].x, vertex.getX(), 0.0);
    assertEquals(coordinates[1].y, vertex.getY(), 0.0);
}
Also used : Vertex(org.opentripplanner.routing.graph.Vertex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) ServiceDay(org.opentripplanner.routing.core.ServiceDay) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) Deduplicator(org.opentripplanner.routing.trippattern.Deduplicator) RoutingContext(org.opentripplanner.routing.core.RoutingContext) GraphIndex(org.opentripplanner.routing.graph.GraphIndex) PatternDepartVertex(org.opentripplanner.routing.vertextype.PatternDepartVertex) TripTimes(org.opentripplanner.routing.trippattern.TripTimes) GenericLocation(org.opentripplanner.common.model.GenericLocation) RoutingRequest(org.opentripplanner.routing.core.RoutingRequest) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) TraverseModeSet(org.opentripplanner.routing.core.TraverseModeSet) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) Graph(org.opentripplanner.routing.graph.Graph) Coordinate(com.vividsolutions.jts.geom.Coordinate) PatternHop(org.opentripplanner.routing.edgetype.PatternHop) PatternArriveVertex(org.opentripplanner.routing.vertextype.PatternArriveVertex) Test(org.junit.Test)

Example 15 with Agency

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

the class AlertPatch method remove.

public void remove(Graph graph) {
    Agency agency = null;
    if (feedId != null) {
        Map<String, Agency> agencies = graph.index.agenciesForFeedId.get(feedId);
        agency = this.agency != null ? agencies.get(this.agency) : null;
    }
    Route route = this.route != null ? graph.index.routeForId.get(this.route) : null;
    Stop stop = this.stop != null ? graph.index.stopForId.get(this.stop) : null;
    Trip trip = this.trip != null ? graph.index.tripForId.get(this.trip) : null;
    if (route != null || trip != null || agency != null) {
        Collection<TripPattern> tripPatterns = null;
        if (trip != null) {
            tripPatterns = new LinkedList<TripPattern>();
            TripPattern tripPattern = graph.index.patternForTrip.get(trip);
            if (tripPattern != null) {
                tripPatterns.add(tripPattern);
            }
        } else if (route != null) {
            tripPatterns = graph.index.patternsForRoute.get(route);
        } else {
            // Find patterns for the feed.
            tripPatterns = graph.index.patternsForFeedId.get(feedId);
        }
        if (tripPatterns != null) {
            for (TripPattern tripPattern : tripPatterns) {
                if (direction != null && !direction.equals(tripPattern.getDirection())) {
                    continue;
                }
                if (directionId != -1 && directionId != tripPattern.directionId) {
                    continue;
                }
                for (int i = 0; i < tripPattern.stopPattern.stops.length; i++) {
                    if (stop == null || stop.equals(tripPattern.stopPattern.stops[i])) {
                        graph.removeAlertPatch(tripPattern.boardEdges[i], this);
                        graph.removeAlertPatch(tripPattern.alightEdges[i], this);
                    }
                }
            }
        }
    } else if (stop != null) {
        TransitStop transitStop = graph.index.stopVertexForStop.get(stop);
        for (Edge edge : transitStop.getOutgoing()) {
            if (edge instanceof PreBoardEdge) {
                graph.removeAlertPatch(edge, this);
                break;
            }
        }
        for (Edge edge : transitStop.getIncoming()) {
            if (edge instanceof PreAlightEdge) {
                graph.removeAlertPatch(edge, this);
                break;
            }
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PreBoardEdge(org.opentripplanner.routing.edgetype.PreBoardEdge) Agency(org.onebusaway.gtfs.model.Agency) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) TransitStop(org.opentripplanner.routing.vertextype.TransitStop) Stop(org.onebusaway.gtfs.model.Stop) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) PreAlightEdge(org.opentripplanner.routing.edgetype.PreAlightEdge) PreAlightEdge(org.opentripplanner.routing.edgetype.PreAlightEdge) PreBoardEdge(org.opentripplanner.routing.edgetype.PreBoardEdge) Edge(org.opentripplanner.routing.graph.Edge) Route(org.onebusaway.gtfs.model.Route)

Aggregations

Agency (org.onebusaway.gtfs.model.Agency)57 Test (org.junit.Test)28 Route (org.onebusaway.gtfs.model.Route)21 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)20 Trip (org.onebusaway.gtfs.model.Trip)19 Stop (org.onebusaway.gtfs.model.Stop)18 StopTime (org.onebusaway.gtfs.model.StopTime)15 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)10 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)9 ArrayList (java.util.ArrayList)8 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)7 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)7 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)6 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)5 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)5 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)5 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)5 StopPattern (org.opentripplanner.model.StopPattern)5 Graph (org.opentripplanner.routing.graph.Graph)5