Search in sources :

Example 16 with StopTime

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

the class TrimTripTransformStrategyTest method testStopTimeTrimming.

@Test
public void testStopTimeTrimming() throws IOException {
    _gtfs.putAgencies(1);
    _gtfs.putStops(6);
    _gtfs.putRoutes(1);
    _gtfs.putTrips(1, "r0", "sid0");
    _gtfs.putStopTimes("t0", "s0,s1,s2,s3,s4,s5");
    GtfsMutableRelationalDao dao = _gtfs.read();
    TrimOperation operation = new TrimOperation();
    operation.setMatch(new TypedEntityMatch(Trip.class, new AlwaysMatch()));
    operation.setToStopId("s1");
    operation.setFromStopId("s4");
    _strategy.addOperation(operation);
    _strategy.run(_context, dao);
    Collection<Trip> allTrips = dao.getAllTrips();
    assertEquals(1, allTrips.size());
    Trip trip = allTrips.iterator().next();
    assertEquals(new AgencyAndId("a0", "t0-s1-s4"), trip.getId());
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    assertEquals(2, stopTimes.size());
    assertEquals("s2", stopTimes.get(0).getStop().getId().getId());
    assertEquals("s3", stopTimes.get(1).getStop().getId().getId());
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) TrimOperation(org.onebusaway.gtfs_transformer.updates.TrimTripTransformStrategy.TrimOperation) AlwaysMatch(org.onebusaway.gtfs_transformer.match.AlwaysMatch) StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 17 with StopTime

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

the class DeferredValueConverterTest method testCsvFieldMappingTime.

@Test
public void testCsvFieldMappingTime() {
    Object value = convert(new StopTime(), "arrivalTime", "06:00:00");
    assertEquals(6 * 60 * 60, ((Integer) value).intValue());
}
Also used : StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 18 with StopTime

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

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

the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetStopTimesForId.

@Test
public void testGetStopTimesForId() {
    StopTime first = _dao.getStopTimeForId(1);
    assertEquals(21120, first.getArrivalTime());
    assertEquals(21120, first.getDepartureTime());
    assertEquals(0, first.getDropOffType());
    assertEquals(0, first.getPickupType());
    assertFalse(first.isShapeDistTraveledSet());
    assertEquals(21, first.getStopSequence());
    assertEquals(aid("22nd Street Caltrain"), first.getStop().getId());
    assertEquals(aid("10101272009"), first.getTrip().getId());
    StopTime second = _dao.getStopTimeForId(193);
    assertEquals(41220, second.getArrivalTime());
    assertEquals(41220, second.getDepartureTime());
    assertEquals(0, second.getDropOffType());
    assertEquals(0, second.getPickupType());
    assertFalse(second.isShapeDistTraveledSet());
    assertEquals(5, second.getStopSequence());
    assertEquals(aid("San Bruno Caltrain"), second.getStop().getId());
    assertEquals(aid("14201272009"), second.getTrip().getId());
}
Also used : StopTime(org.onebusaway.gtfs.model.StopTime) Test(org.junit.Test)

Example 20 with StopTime

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

the class TripScheduleOverlapDuplicateScoringStrategy method getScheduleIntervalForTrip.

private int[] getScheduleIntervalForTrip(GtfsRelationalDao dao, Trip trip) {
    List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
    if (stopTimes.isEmpty()) {
        return null;
    }
    StopTime first = stopTimes.get(0);
    StopTime last = stopTimes.get(stopTimes.size() - 1);
    if (!first.isDepartureTimeSet() || !last.isArrivalTimeSet()) {
        throw new IllegalStateException("expected departure time for first stop and arrival time for last stop to be set for trip with id " + trip.getId());
    }
    int minTime = first.getDepartureTime();
    int maxTime = last.getArrivalTime();
    return new int[] { minTime, maxTime };
}
Also used : StopTime(org.onebusaway.gtfs.model.StopTime)

Aggregations

StopTime (org.onebusaway.gtfs.model.StopTime)37 Trip (org.onebusaway.gtfs.model.Trip)22 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)15 Test (org.junit.Test)12 Stop (org.onebusaway.gtfs.model.Stop)11 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)8 ArrayList (java.util.ArrayList)7 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)7 List (java.util.List)6 Agency (org.onebusaway.gtfs.model.Agency)6 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)5 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)5 HashSet (java.util.HashSet)4 Frequency (org.onebusaway.gtfs.model.Frequency)4 Route (org.onebusaway.gtfs.model.Route)4 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)4 HashMap (java.util.HashMap)3 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)3 FareRule (org.onebusaway.gtfs.model.FareRule)3 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)3