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());
}
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());
}
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());
}
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());
}
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 };
}
Aggregations