Search in sources :

Example 76 with Route

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

the class PropertyMethodResolverImplTest method testUseCsvFieldMappings.

@Test
public void testUseCsvFieldMappings() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    DefaultEntitySchemaFactory factory = GtfsEntitySchemaFactory.createEntitySchemaFactory();
    EntitySchema entitySchema = factory.getSchema(Route.class);
    _schemaCache.addEntitySchema(entitySchema);
    PropertyMethod method = _resolver.getPropertyMethod(Route.class, "route_id");
    Route route = new Route();
    AgencyAndId id = new AgencyAndId("1", "10");
    route.setId(id);
    assertSame(id, method.invoke(route));
}
Also used : PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) DefaultEntitySchemaFactory(org.onebusaway.csv_entities.schema.DefaultEntitySchemaFactory) EntitySchema(org.onebusaway.csv_entities.schema.EntitySchema) Route(org.onebusaway.gtfs.model.Route) Test(org.junit.Test)

Example 77 with Route

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

the class PropertyMethodResolverImplTest method testRouteTripsVirtualMethod.

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

Example 78 with Route

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

the class CheckForLengthyRouteNames method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    // this is inneficient, but if there are ever so many routes or a route
    // with such a long name that it matters, then their gtfs is effectively broken
    // or whatever is running the transform is woefully insufficient to work on anything
    // to do with trips, shapes, or stoptimes
    Collection<Route> routes = dao.getAllRoutes();
    Stack<String> longestRouteNames = new Stack();
    String longestNames = "";
    String tooLongNames = "";
    String namesWithDuplicateParts = "";
    for (Route route : routes) {
        String name = route.getLongName();
        if (name.length() > logIfLongerThan) {
            tooLongNames += name + "\n";
        }
        String[] nameParts = name.split(" ");
        for (int i = 0; i < nameParts.length - 1; i++) {
            if (nameParts[i].equals(nameParts[i + 1])) {
                namesWithDuplicateParts += name + "\n";
            }
        }
        if (longestRouteNames.size() < nLongestNames) {
            longestRouteNames.push(name);
        } else {
            if (longestRouteNames.lastElement().length() < name.length()) {
                longestRouteNames.pop();
                longestRouteNames.push(name);
            }
        }
        longestRouteNames.sort((a, b) -> {
            return a.length() < b.length() ? 1 : -1;
        });
    }
    for (String name : longestRouteNames) {
        longestNames += name + "\n";
    }
    _log.info("Route names with duplicate words: \n" + namesWithDuplicateParts);
    _log.info("Route names that are too long: \n" + tooLongNames);
    _log.info("Longest Route names: \n" + longestNames);
}
Also used : Route(org.onebusaway.gtfs.model.Route)

Example 79 with Route

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

the class MTASubwayShuttleRouteStrategy method getShuttleRoute.

private Route getShuttleRoute(GtfsMutableRelationalDao dao, Route orig) {
    Route shuttleRoute = new Route(orig);
    AgencyAndId id = new AgencyAndId(shuttleRoute.getId().getAgencyId(), shuttleRoute.getId().getId() + SHUTTLE_ID_SUFFIX);
    shuttleRoute.setId(id);
    shuttleRoute.setShortName(shuttleRoute.getShortName() + SHUTTLE_ID_SUFFIX);
    shuttleRoute.setLongName(shuttleRoute.getLongName() + SHUTTLE_NAME_SUFFIX);
    shuttleRoute.setType(SHUTTLE_ROUTE_TYPE);
    dao.saveEntity(shuttleRoute);
    return shuttleRoute;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route)

Example 80 with Route

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

the class MergeRouteFive method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    RemoveEntityLibrary removeEntityLibrary = new RemoveEntityLibrary();
    String agency = dao.getAllTrips().iterator().next().getId().getAgencyId();
    // Merge route 5X into route 5, then remove route 5X
    Route routeFive = dao.getRouteForId(new AgencyAndId(agency, "5"));
    Route routeFiveX = dao.getRouteForId(new AgencyAndId(agency, "5X"));
    if (routeFive != null && routeFiveX != null) {
        for (Trip trip : dao.getTripsForRoute(routeFiveX)) {
            trip.setRoute(routeFive);
        }
        dao.removeEntity(routeFiveX);
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Route(org.onebusaway.gtfs.model.Route)

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