Search in sources :

Example 41 with Trip

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

the class StopTimeComparator method compare.

@Override
public int compare(StopTime o1, StopTime o2) {
    Trip trip1 = o1.getTrip();
    Trip trip2 = o2.getTrip();
    int c = trip1.getId().compareTo(trip2.getId());
    if (c == 0)
        c = o1.getStopSequence() - o2.getStopSequence();
    return c;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip)

Example 42 with Trip

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

the class RouteStopsInCommonDuplicateScoringStrategy method getAllStopsForRoute.

private Set<StopLocation> getAllStopsForRoute(GtfsRelationalDao dao, Route route) {
    Set<StopLocation> stops = new HashSet<>();
    List<Trip> tripsForRoute = new ArrayList<Trip>();
    // make this thread safe
    tripsForRoute.addAll(dao.getTripsForRoute(route));
    for (Trip trip : tripsForRoute) {
        List<StopTime> stopTimesForTrip = new ArrayList<StopTime>();
        stopTimesForTrip.addAll(dao.getStopTimesForTrip(trip));
        for (StopTime stopTime : stopTimesForTrip) {
            stops.add(stopTime.getStop());
        }
    }
    return stops;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) ArrayList(java.util.ArrayList) StopLocation(org.onebusaway.gtfs.model.StopLocation) HashSet(java.util.HashSet) StopTime(org.onebusaway.gtfs.model.StopTime)

Example 43 with Trip

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

the class GtfsMergerTest method testRenamingTrips.

/**
 * Test that when renaming trips stop times are preserved (issue 14)
 */
@Test
public void testRenamingTrips() throws IOException {
    // modified construction code copied from above test
    _oldGtfs.putAgencies(1);
    _oldGtfs.putRoutes(1);
    _oldGtfs.putStops(3);
    _oldGtfs.putCalendars(1, "mask=1111100", "start_date=20120504", "end_date=20120608");
    _oldGtfs.putTrips(1, "r0", "sid0");
    _oldGtfs.putStopTimes("t0", "s0,s1,s2");
    _newGtfs.putAgencies(1);
    _newGtfs.putRoutes(1);
    _newGtfs.putStops(3);
    _newGtfs.putCalendars(1, "mask=1111100", "start_date=20120601", "end_date=20120601");
    _newGtfs.putTrips(1, "r0", "sid0");
    _newGtfs.putStopTimes("t0", "s0,s1");
    TripMergeStrategy strategy = new TripMergeStrategy();
    strategy.setDuplicateDetectionStrategy(EDuplicateDetectionStrategy.IDENTITY);
    _merger.setTripStrategy(strategy);
    GtfsRelationalDao dao = merge();
    for (Trip trip : dao.getAllTrips()) {
        assertTrue(dao.getStopTimesForTrip(trip).size() > 0);
    }
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) Trip(org.onebusaway.gtfs.model.Trip) TripMergeStrategy(org.onebusaway.gtfs_merge.strategies.TripMergeStrategy) Test(org.junit.Test)

Example 44 with Trip

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

the class CalendarServiceDataFactoryImplSyntheticTest method trip.

private Trip trip(String agencyId, String id, AgencyAndId serviceId) {
    Trip trip = new Trip();
    trip.setId(new AgencyAndId(agencyId, id));
    trip.setServiceId(serviceId);
    return trip;
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

Example 45 with Trip

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

Aggregations

Trip (org.onebusaway.gtfs.model.Trip)166 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)89 Test (org.junit.Test)56 StopTime (org.onebusaway.gtfs.model.StopTime)52 Route (org.onebusaway.gtfs.model.Route)51 Stop (org.onebusaway.gtfs.model.Stop)40 ArrayList (java.util.ArrayList)34 List (java.util.List)23 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)21 TripPattern (org.opentripplanner.routing.edgetype.TripPattern)20 Agency (org.onebusaway.gtfs.model.Agency)19 TransitStop (org.opentripplanner.routing.vertextype.TransitStop)19 HashMap (java.util.HashMap)14 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)13 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)13 HashSet (java.util.HashSet)12 Vertex (org.opentripplanner.routing.graph.Vertex)12 FactoryMap (org.onebusaway.collections.FactoryMap)10 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)10 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)10