Search in sources :

Example 26 with Route

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

the class GtfsRelationalDaoImplTest method testBart.

@Test
public void testBart() throws IOException {
    GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
    GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
    List<String> tripAgencyIds = dao.getTripAgencyIdsReferencingServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(1, tripAgencyIds.size());
    assertEquals("BART", tripAgencyIds.get(0));
    Agency agency = dao.getAgencyForId("BART");
    List<Route> routes = dao.getRoutesForAgency(agency);
    assertEquals(10, routes.size());
    agency = dao.getAgencyForId("AirBART");
    routes = dao.getRoutesForAgency(agency);
    assertEquals(1, routes.size());
    Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
    List<Trip> trips = dao.getTripsForRoute(route);
    assertEquals(225, trips.size());
    Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(12, stopTimes.size());
    // Ensure the stopTimes are in stop sequence order
    for (int i = 0; i < stopTimes.size() - 1; i++) assertTrue(stopTimes.get(i).getStopSequence() < stopTimes.get(i + 1).getStopSequence());
    Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
    stopTimes = dao.getStopTimesForStop(stop);
    assertEquals(584, stopTimes.size());
    List<ShapePoint> shapePoints = dao.getShapePointsForShapeId(new AgencyAndId("BART", "airbart-dn.csv"));
    assertEquals(50, shapePoints.size());
    for (int i = 0; i < shapePoints.size() - 1; i++) assertTrue(shapePoints.get(i).getSequence() < shapePoints.get(i + 1).getSequence());
    trip = dao.getTripForId(new AgencyAndId("AirBART", "M-FSAT1DN"));
    List<Frequency> frequencies = dao.getFrequenciesForTrip(trip);
    assertEquals(1, frequencies.size());
    Frequency frequency = frequencies.get(0);
    assertEquals(5 * 60 * 60, frequency.getStartTime());
    assertEquals(6 * 60 * 60, frequency.getEndTime());
    assertEquals(trip, frequency.getTrip());
    assertEquals(1200, frequency.getHeadwaySecs());
    ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
    List<ServiceCalendarDate> calendarDates = dao.getCalendarDatesForServiceId(new AgencyAndId("BART", "WKDY"));
    assertEquals(7, calendarDates.size());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Agency(org.onebusaway.gtfs.model.Agency) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) ShapePoint(org.onebusaway.gtfs.model.ShapePoint) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Frequency(org.onebusaway.gtfs.model.Frequency) Route(org.onebusaway.gtfs.model.Route) StopTime(org.onebusaway.gtfs.model.StopTime) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 27 with Route

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

the class MTASubwayShuttleRouteStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    Map<Route, Route> shuttleRoutes = new HashMap<>();
    for (Trip trip : dao.getAllTrips()) {
        if (trip.getTripHeadsign().endsWith(SHUTTLE_HEADSIGN_SUFFIX)) {
            Route shuttleRoute = shuttleRoutes.computeIfAbsent(trip.getRoute(), r -> getShuttleRoute(dao, r));
            trip.setRoute(shuttleRoute);
            dao.updateEntity(trip);
        }
    }
    // Shuttle stops share mta_stop_id with non-shuttle version
    Map<String, String> parentStopByMtaStopId = new HashMap<>();
    for (Stop stop : dao.getAllStops()) {
        if (!stop.getName().endsWith(SHUTTLE_STOP_SUFFIX) && stop.getParentStation() != null) {
            parentStopByMtaStopId.put(stop.getMtaStopId(), stop.getParentStation());
        }
    }
    for (Stop stop : dao.getAllStops()) {
        if (stop.getName().endsWith(SHUTTLE_STOP_SUFFIX)) {
            String parent = parentStopByMtaStopId.get(stop.getMtaStopId());
            if (parent == null) {
                _log.info("No parent for shuttle stop {}", stop.getId());
            }
            stop.setParentStation(parent);
            dao.updateEntity(stop);
        }
    }
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) HashMap(java.util.HashMap) Stop(org.onebusaway.gtfs.model.Stop) Route(org.onebusaway.gtfs.model.Route)

Example 28 with Route

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

the class MergeRouteFromReferenceStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    HashMap<String, Route> referenceRoutes = new HashMap<>();
    for (Route route : reference.getAllRoutes()) {
        referenceRoutes.put(route.getId().getId(), route);
    }
    for (Route route : dao.getAllRoutes()) {
        String identifier = route.getId().getId();
        if (identifier.length() > 2) {
            identifier = identifier.substring(0, 2);
        }
        Route refRoute = referenceRoutes.get(identifier);
        if (refRoute != null) {
            route.setShortName(refRoute.getShortName());
            route.setLongName(refRoute.getLongName());
            route.setType(refRoute.getType());
            route.setDesc(refRoute.getDesc());
            route.setUrl(refRoute.getUrl());
            route.setColor(refRoute.getColor());
            route.setTextColor(refRoute.getTextColor());
            route.setId(refRoute.getId());
        }
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) HashMap(java.util.HashMap) Route(org.onebusaway.gtfs.model.Route)

Example 29 with Route

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

the class MergeRouteFromReferenceStrategyByLongName method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    GtfsMutableRelationalDao reference = (GtfsMutableRelationalDao) context.getReferenceReader().getEntityStore();
    HashMap<String, Route> referenceRoutes = new HashMap<>();
    for (Route route : reference.getAllRoutes()) {
        referenceRoutes.put(route.getId().getId(), route);
    }
    /* use the initial characters in the longname to match up with the shortname
        in the reference route.  If the longname is null, try the shortname
         */
    for (Route route : dao.getAllRoutes()) {
        String longname = route.getLongName();
        String identifier = "";
        if (longname != null) {
            if (longname.contains(" -")) {
                String[] parts = longname.split(" -");
                identifier = parts[0];
                if (identifier.length() > 2) {
                    identifier = identifier.substring(0, 2);
                }
            }
        } else {
            identifier = route.getShortName();
        }
        Route refRoute = referenceRoutes.get(identifier);
        if (refRoute != null) {
            route.setShortName(refRoute.getShortName());
            route.setLongName(refRoute.getLongName());
            route.setType(refRoute.getType());
            route.setDesc(refRoute.getDesc());
            route.setUrl(refRoute.getUrl());
            route.setColor(refRoute.getColor());
            route.setTextColor(refRoute.getTextColor());
        }
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) HashMap(java.util.HashMap) Route(org.onebusaway.gtfs.model.Route)

Example 30 with Route

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

the class PierceTransitTripHeadsignCleanupModStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
    if (!(entity instanceof Trip))
        return;
    Trip trip = (Trip) entity;
    String headsign = trip.getTripHeadsign();
    Route route = trip.getRoute();
    String shortName = route.getShortName();
    if (headsign == null || shortName == null)
        return;
    headsign = headsign.replaceAll("^" + shortName + "\\s+", "");
    headsign = headsign.replaceAll("-\\s+" + shortName + "\\s+", "- ");
    trip.setTripHeadsign(headsign);
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) 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