Search in sources :

Example 6 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class RouteCollectionEntriesFactoryTest method testGroupRoutesByShortName.

@Test
public void testGroupRoutesByShortName() {
    TransitGraphImpl graph = new TransitGraphImpl();
    AgencyEntryImpl agency = new AgencyEntryImpl();
    agency.setId("A");
    graph.putAgencyEntry(agency);
    graph.refreshAgencyMapping();
    RouteEntryImpl routeA = new RouteEntryImpl();
    routeA.setId(new AgencyAndId("A", "routeA"));
    graph.putRouteEntry(routeA);
    RouteEntryImpl routeB = new RouteEntryImpl();
    routeB.setId(new AgencyAndId("A", "routeB"));
    graph.putRouteEntry(routeB);
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Route rA = new Route();
    rA.setId(routeA.getId());
    rA.setShortName("10");
    Mockito.when(gtfsDao.getRouteForId(routeA.getId())).thenReturn(rA);
    Route rB = new Route();
    rB.setId(routeB.getId());
    rB.setShortName("10");
    Mockito.when(gtfsDao.getRouteForId(routeB.getId())).thenReturn(rB);
    RouteCollectionEntriesFactory factory = new RouteCollectionEntriesFactory();
    factory.setGroupRoutesByShortName(true);
    factory.setGtfsDao(gtfsDao);
    factory.setUniqueService(new UniqueServiceImpl());
    factory.processRouteCollections(graph);
    AgencyAndId id = new AgencyAndId("A", "10");
    RouteCollectionEntry routeCollectionEntry = graph.getRouteCollectionForId(id);
    assertEquals(id, routeCollectionEntry.getId());
    List<RouteEntry> routes = routeCollectionEntry.getChildren();
    assertEquals(2, routes.size());
    assertTrue(routes.contains(routeA));
    assertTrue(routes.contains(routeB));
    List<RouteCollectionEntry> routeCollections = graph.getAllRouteCollections();
    assertEquals(1, routeCollections.size());
    assertTrue(routeCollections.contains(routeCollectionEntry));
    routeCollections = agency.getRouteCollections();
    assertEquals(1, routeCollections.size());
    assertTrue(routeCollections.contains(routeCollectionEntry));
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 7 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class StopTimeEntriesFactoryTest method testThreeInARowDuplicateRemoval.

@Test
public void testThreeInARowDuplicateRemoval() {
    TransitGraphImpl graph = new TransitGraphImpl();
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    Stop stopC = new Stop();
    stopC.setId(aid("stopC"));
    graph.putStopEntry(stop("stopC", 47.66847942216854, -122.37545336180114));
    Stop stopD = new Stop();
    stopD.setId(aid("stopD"));
    graph.putStopEntry(stop("stopD", 47.66947942216854, -122.37545336180114));
    graph.refreshStopMapping();
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    Route route = new Route();
    route.setAgency(agency);
    Trip trip = new Trip();
    trip.setRoute(route);
    trip.setServiceId(aid("serviceId"));
    TripEntryImpl tripEntry = trip("trip");
    StopTime stA = new StopTime();
    stA.setId(100);
    stA.setArrivalTime(time(9, 00));
    stA.setDepartureTime(time(9, 05));
    stA.setStopSequence(100);
    stA.setStop(stopA);
    stA.setTrip(trip);
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setArrivalTime(time(9, 00));
    stB.setDepartureTime(time(9, 05));
    stB.setStopSequence(101);
    stB.setStop(stopB);
    stB.setTrip(trip);
    StopTime stC = new StopTime();
    stC.setId(102);
    stC.setArrivalTime(time(9, 00));
    stC.setDepartureTime(time(9, 05));
    stC.setStopSequence(102);
    stC.setStop(stopC);
    stC.setTrip(trip);
    StopTime stD = new StopTime();
    stD.setId(103);
    stD.setArrivalTime(time(11, 00));
    stD.setDepartureTime(time(11, 05));
    stD.setStopSequence(103);
    stD.setStop(stopD);
    stD.setTrip(trip);
    StopTimeEntriesFactory factory = new StopTimeEntriesFactory();
    factory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    List<StopTime> stopTimes = Arrays.asList(stA, stB, stC, stD);
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    shapePointsFactory.addPoint(47.66947942216854, -122.37545336180114);
    ShapePoints shapePoints = shapePointsFactory.create();
    List<StopTimeEntryImpl> entries = factory.processStopTimes(graph, stopTimes, tripEntry, shapePoints);
    assertEquals(stopTimes.size(), entries.size());
    StopTimeEntryImpl entry = entries.get(0);
    assertEquals(0, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 00), entry.getArrivalTime());
    assertEquals(time(9, 05), entry.getDepartureTime());
    assertEquals(0, entry.getSequence());
    assertEquals(181.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(5 * 60, entry.getSlackTime());
    entry = entries.get(1);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(9, 28, 45), entry.getArrivalTime());
    assertEquals(time(9, 28, 45), entry.getDepartureTime());
    assertEquals(1, entry.getSequence());
    assertEquals(738.7, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(2);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(10, 00, 34), entry.getArrivalTime());
    assertEquals(time(10, 00, 34), entry.getDepartureTime());
    assertEquals(2, entry.getSequence());
    assertEquals(1484.5, entry.getShapeDistTraveled(), 0.1);
    assertEquals(0, entry.getSlackTime());
    entry = entries.get(3);
    assertEquals(5 * 60, entry.getAccumulatedSlackTime());
    assertEquals(time(11, 00), entry.getArrivalTime());
    assertEquals(time(11, 05), entry.getDepartureTime());
    assertEquals(3, entry.getSequence());
    assertEquals(2877.69, entry.getShapeDistTraveled(), 0.1);
    assertEquals(60 * 5, entry.getSlackTime());
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopTimeEntriesFactory) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) DistanceAlongShapeLibrary(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.DistanceAlongShapeLibrary) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 8 with Route

use of org.onebusaway.gtfs.model.Route in project onebusaway-application-modules by camsys.

the class TripEntriesFactoryTest method test.

@Test
public void test() {
    GtfsRelationalDao gtfsDao = Mockito.mock(GtfsRelationalDao.class);
    Agency agency = new Agency();
    agency.setId("1");
    agency.setTimezone("America/Los_Angeles");
    // gtfsDao.saveEntity(agency);
    Route route = new Route();
    route.setId(new AgencyAndId("1", "routeA"));
    route.setAgency(agency);
    Mockito.when(gtfsDao.getAllRoutes()).thenReturn(Arrays.asList(route));
    AgencyAndId shapeId = new AgencyAndId("1", "shapeId");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "tripA"));
    trip.setRoute(route);
    trip.setServiceId(new AgencyAndId("1", "serviceId"));
    trip.setShapeId(shapeId);
    Mockito.when(gtfsDao.getTripsForRoute(route)).thenReturn(Arrays.asList(trip));
    Stop stopA = new Stop();
    stopA.setId(aid("stopA"));
    StopTime stA = new StopTime();
    stA.setId(100);
    stA.setArrivalTime(time(9, 00));
    stA.setDepartureTime(time(9, 05));
    stA.setStopSequence(100);
    stA.setStop(stopA);
    stA.setTrip(trip);
    Stop stopB = new Stop();
    stopB.setId(aid("stopB"));
    StopTime stB = new StopTime();
    stB.setId(101);
    stB.setArrivalTime(time(10, 00));
    stB.setDepartureTime(time(10, 05));
    stB.setStopSequence(102);
    stB.setStop(stopB);
    stB.setTrip(trip);
    Mockito.when(gtfsDao.getStopTimesForTrip(trip)).thenReturn(Arrays.asList(stA, stB));
    TransitGraphImpl graph = new TransitGraphImpl();
    graph.putStopEntry(stop("stopA", 47.672207391799056, -122.387855896286));
    graph.putStopEntry(stop("stopB", 47.66852277218285, -122.3853882639923));
    RouteEntryImpl routeEntry = route("routeA");
    graph.putRouteEntry(routeEntry);
    graph.initialize();
    ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
    shapePointsFactory.addPoint(47.673840100841396, -122.38756621771239);
    shapePointsFactory.addPoint(47.668667271970484, -122.38756621771239);
    shapePointsFactory.addPoint(47.66868172192725, -122.3661729186096);
    ShapePoints shapePoints = shapePointsFactory.create();
    ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
    Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeId)).thenReturn(shapePoints);
    TripEntriesFactory factory = new TripEntriesFactory();
    factory.setGtfsDao(gtfsDao);
    factory.setShapePointHelper(shapePointHelper);
    factory.setUniqueService(new UniqueServiceImpl());
    StopTimeEntriesFactory stopTimeEntriesFactory = new StopTimeEntriesFactory();
    stopTimeEntriesFactory.setDistanceAlongShapeLibrary(new DistanceAlongShapeLibrary());
    factory.setStopTimeEntriesFactory(stopTimeEntriesFactory);
    factory.processTrips(graph);
    TripEntryImpl entry = graph.getTripEntryForId(trip.getId());
    assertEquals(trip.getId(), entry.getId());
    assertEquals(route.getId(), entry.getRoute().getId());
    assertEquals(lsid("serviceId"), entry.getServiceId());
    assertEquals(trip.getShapeId(), entry.getShapeId());
    assertEquals(2177.1, entry.getTotalTripDistance(), 0.1);
    List<StopTimeEntry> stopTimes = entry.getStopTimes();
    assertEquals(2, stopTimes.size());
    for (StopTimeEntry stopTime : stopTimes) {
        assertSame(entry, stopTime.getTrip());
    }
}
Also used : UniqueServiceImpl(org.onebusaway.transit_data_federation.bundle.tasks.UniqueServiceImpl) GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ShapePointHelper(org.onebusaway.transit_data_federation.bundle.tasks.ShapePointHelper) RouteEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 9 with Route

use of org.onebusaway.gtfs.model.Route 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 10 with Route

use of org.onebusaway.gtfs.model.Route 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)

Aggregations

Route (org.onebusaway.gtfs.model.Route)90 Trip (org.onebusaway.gtfs.model.Trip)52 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)46 Test (org.junit.Test)33 Stop (org.onebusaway.gtfs.model.Stop)28 Agency (org.onebusaway.gtfs.model.Agency)21 ArrayList (java.util.ArrayList)16 StopTime (org.onebusaway.gtfs.model.StopTime)14 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)14 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)12 HashMap (java.util.HashMap)10 Edge (org.opentripplanner.routing.graph.Edge)8 GET (javax.ws.rs.GET)7 Path (javax.ws.rs.Path)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 TransitGraphImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl)7 List (java.util.List)6 RouteEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.RouteEntryImpl)6 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)6 Coordinate (com.vividsolutions.jts.geom.Coordinate)5