Search in sources :

Example 36 with Route

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

the class PropertyMethodResolverImplTest method testAgencyRoutesVirtualMethod.

@Test
public void testAgencyRoutesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Agency agency = new Agency();
    agency.setId("1");
    Route route = new Route();
    route.setId(new AgencyAndId("1", "r0"));
    route.setAgency(agency);
    _dao.saveEntity(route);
    PropertyMethod method = _resolver.getPropertyMethod(Agency.class, "routes");
    assertEquals(Arrays.asList(route), method.invoke(agency));
}
Also used : PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 37 with Route

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

the class TransformFactoryTest method testPathInUpdate.

@Test
public void testPathInUpdate() throws IOException, TransformSpecificationException {
    _factory.addModificationsFromString("{'op':'update', " + "'match':{'file':'trips.txt'}, " + "'update':{'trip_headsign': 'path(route.longName)'}}");
    GtfsTransformStrategy transform = _transformer.getLastTransform();
    TransformContext context = new TransformContext();
    GtfsMutableRelationalDao dao = new GtfsRelationalDaoImpl();
    Route route = new Route();
    route.setLongName("long cat");
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "1"));
    trip.setRoute(route);
    dao.saveEntity(trip);
    transform.run(context, dao);
    assertEquals("long cat", trip.getTripHeadsign());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TransformContext(org.onebusaway.gtfs_transformer.services.TransformContext) GtfsTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsTransformStrategy) GtfsRelationalDaoImpl(org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 38 with Route

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

the class DeduplicateRoutesStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<AgencyAndId, List<Route>> routesById = new FactoryMap<AgencyAndId, List<Route>>(new ArrayList<Route>());
    for (Route route : dao.getAllRoutes()) {
        AgencyAndId aid = route.getId();
        String id = aid.getId();
        int index = id.indexOf('_');
        if (index == -1)
            continue;
        String commonId = id.substring(index + 1);
        AgencyAndId commonIdFull = new AgencyAndId(aid.getAgencyId(), commonId);
        routesById.get(commonIdFull).add(route);
    }
    for (Map.Entry<AgencyAndId, List<Route>> entry : routesById.entrySet()) {
        AgencyAndId routeId = entry.getKey();
        List<Route> routes = entry.getValue();
        if (routes.size() == 1)
            continue;
        // Remove the route with the old id
        Route route = routes.get(0);
        dao.removeEntity(route);
        // Add the route with the new id
        route.setId(routeId);
        dao.saveEntity(route);
        for (int i = 1; i < routes.size(); i++) {
            Route duplicateRoute = routes.get(i);
            dao.removeEntity(duplicateRoute);
            List<Trip> trips = dao.getTripsForRoute(duplicateRoute);
            for (Trip trip : trips) trip.setRoute(route);
        }
    }
    UpdateLibrary.clearDaoCache(dao);
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) Route(org.onebusaway.gtfs.model.Route)

Example 39 with Route

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

the class OTPRequest method handle.

@Override
public Object handle(OTPRequest oreq) {
    Map<String, Route> routes = Maps.newHashMap();
    for (TransitBoardAlight ba : Iterables.filter(oreq.graph.getEdges(), TransitBoardAlight.class)) {
        Route route = ba.getPattern().route;
        routes.put(route.getId().toString(), route);
    }
    if (oreq.id != null) {
        return routes.get(oreq.id);
    } else {
        return routes;
    }
}
Also used : TransitBoardAlight(org.opentripplanner.routing.edgetype.TransitBoardAlight) Route(org.onebusaway.gtfs.model.Route)

Example 40 with Route

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

the class TimetableFilterTest method setUp.

@Override
protected void setUp() {
    agency = new Agency();
    agency.setId("AGENCY");
    route = new Route();
    route.setType(com.conveyal.gtfs.model.Route.BUS);
    route.setShortName("T");
    route.setLongName("TEST");
    route.setAgency(agency);
    route.setId(new AgencyAndId(agency.getId(), "TEST"));
    metro = new Route();
    metro.setType(com.conveyal.gtfs.model.Route.SUBWAY);
    metro.setShortName("M");
    metro.setLongName("METRO");
    metro.setAgency(agency);
    metro.setId(new AgencyAndId(agency.getId(), "METRO"));
    trip = new Trip();
    trip.setRoute(route);
    trip.setId(new AgencyAndId(agency.getId(), "TRIP"));
    trip2 = new Trip();
    trip2.setRoute(route);
    trip2.setId(new AgencyAndId(agency.getId(), "TRIP2"));
    stops = new Stop[4];
    for (int i = 0; i < stops.length; i++) {
        Stop s = new Stop();
        s.setLat(-122.123);
        s.setLon(37.363 + i * 0.001);
        s.setId(new AgencyAndId(agency.getId(), "" + i));
        stops[i] = s;
    }
    List<StopTime> stopTimes = makeStopTimes(trip);
    StopPattern sp = new StopPattern(stopTimes);
    pattern = new TripPattern(route, sp);
    // make a triptimes
    times = makeTripTimes(trip, stopTimes);
    pattern.scheduledTimetable.addTripTimes(times);
    pattern.scheduledTimetable.addTripTimes(makeTripTimes(trip2, makeStopTimes(trip2)));
    // ten-minute frequency
    frequencyEntry = new FrequencyEntry(7 * 3600, 12 * 3600, 600, false, makeTripTimes(trip, makeStopTimes(trip)));
    pattern.scheduledTimetable.addFrequencyEntry(frequencyEntry);
    pattern.scheduledTimetable.addFrequencyEntry(new FrequencyEntry(7 * 3600, 12 * 3600, 600, false, makeTripTimes(trip2, makeStopTimes(trip2))));
    metroTrip = new Trip();
    metroTrip.setRoute(metro);
    metroTrip.setId(new AgencyAndId(agency.getId(), "TRIP"));
    stopTimes = makeStopTimes(metroTrip);
    sp = new StopPattern(stopTimes);
    metroPattern = new TripPattern(metro, sp);
    metroTimes = makeTripTimes(metroTrip, stopTimes);
    metroPattern.scheduledTimetable.addTripTimes(metroTimes);
}
Also used : StopPattern(org.opentripplanner.model.StopPattern) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) FrequencyEntry(org.opentripplanner.routing.trippattern.FrequencyEntry) Route(org.onebusaway.gtfs.model.Route) TripPattern(org.opentripplanner.routing.edgetype.TripPattern) StopTime(org.onebusaway.gtfs.model.StopTime)

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