use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsDaoImplTest method testBart.
@Test
public void testBart() throws IOException {
GtfsDaoImpl dao = new GtfsDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getBartGtfs(), "BART");
Collection<Agency> agencies = dao.getAllAgencies();
assertEquals(2, agencies.size());
Agency agency = dao.getAgencyForId("BART");
assertEquals("BART", agency.getId());
Collection<ServiceCalendarDate> calendarDates = dao.getAllCalendarDates();
assertEquals(32, calendarDates.size());
ServiceCalendarDate calendarDate = dao.getCalendarDateForId(1);
assertEquals(new AgencyAndId("BART", "SUN"), calendarDate.getServiceId());
assertEquals(new ServiceDate(2009, 1, 1), calendarDate.getDate());
assertEquals(1, calendarDate.getExceptionType());
Collection<ServiceCalendar> calendars = dao.getAllCalendars();
assertEquals(5, calendars.size());
ServiceCalendar calendar = dao.getCalendarForId(1);
assertEquals(new AgencyAndId("BART", "WKDY"), calendar.getServiceId());
assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
assertEquals(new ServiceDate(2010, 12, 31), calendar.getEndDate());
assertEquals(1, calendar.getMonday());
assertEquals(1, calendar.getTuesday());
assertEquals(1, calendar.getWednesday());
assertEquals(1, calendar.getThursday());
assertEquals(1, calendar.getFriday());
assertEquals(0, calendar.getSaturday());
assertEquals(0, calendar.getSunday());
Collection<FareAttribute> fareAttributes = dao.getAllFareAttributes();
assertEquals(106, fareAttributes.size());
FareAttribute fareAttribute = dao.getFareAttributeForId(new AgencyAndId("BART", "30"));
assertEquals(new AgencyAndId("BART", "30"), fareAttribute.getId());
Collection<FareRule> fareRules = dao.getAllFareRules();
assertEquals(1849, fareRules.size());
FareRule fareRule = dao.getFareRuleForId(1);
assertEquals(new AgencyAndId("BART", "98"), fareRule.getFare().getId());
Collection<Frequency> frequencies = dao.getAllFrequencies();
assertEquals(6, frequencies.size());
Frequency frequency = dao.getFrequencyForId(1);
assertEquals(new AgencyAndId("AirBART", "M-FSAT1DN"), frequency.getTrip().getId());
Collection<Route> routes = dao.getAllRoutes();
assertEquals(11, routes.size());
Route route = dao.getRouteForId(new AgencyAndId("BART", "01"));
assertEquals(new AgencyAndId("BART", "01"), route.getId());
Collection<ShapePoint> shapePoints = dao.getAllShapePoints();
assertEquals(105, shapePoints.size());
ShapePoint shapePoint = dao.getShapePointForId(1);
assertEquals(new AgencyAndId("BART", "airbart-dn.csv"), shapePoint.getShapeId());
Collection<Stop> stops = dao.getAllStops();
assertEquals(46, stops.size());
Stop stop = dao.getStopForId(new AgencyAndId("BART", "DBRK"));
assertEquals("Downtown Berkeley BART", stop.getName());
Collection<StopTime> stopTimes = dao.getAllStopTimes();
assertEquals(33270, stopTimes.size());
StopTime stopTime = stopTimes.iterator().next();
assertEquals(18000, stopTime.getArrivalTime());
Collection<Transfer> transfers = dao.getAllTransfers();
assertEquals(4, transfers.size());
Transfer transfer = dao.getTransferForId(1);
assertEquals(1, transfer.getTransferType());
Collection<Trip> trips = dao.getAllTrips();
assertEquals(1620, trips.size());
Trip trip = dao.getTripForId(new AgencyAndId("BART", "15PB1"));
assertEquals(new AgencyAndId("BART", "WKDY"), trip.getServiceId());
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class ShiftNegativeStopTimesUpdateStrategyTest method test.
@Test
public void test() throws IOException {
_gtfs.putAgencies(1);
_gtfs.putStops(3);
_gtfs.putRoutes(1);
_gtfs.putCalendars(1, "start_date=20120903", "end_date=20121016", "mask=1111100");
_gtfs.putTrips(1, "r0", "sid0");
_gtfs.putLines("stop_times.txt", "trip_id,stop_id,stop_sequence,arrival_time,departure_time", "t0,s0,0,-01:00:00,-01:05:00", "t0,s1,1,-01:30:00,-01:30:00", "t0,s2,2,00:30:00,00:30:00");
GtfsMutableRelationalDao dao = _gtfs.read();
_strategy.run(new TransformContext(), dao);
Trip trip = dao.getTripForId(_gtfs.id("t0"));
assertEquals("sid0 -1", trip.getServiceId().getId());
List<StopTime> stopTimes = dao.getStopTimesForTrip(trip);
assertEquals(3, stopTimes.size());
{
StopTime stopTime = stopTimes.get(0);
assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:00:00"));
assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:05:00"));
}
{
StopTime stopTime = stopTimes.get(1);
assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("23:30:00"));
}
{
StopTime stopTime = stopTimes.get(2);
assertEquals(stopTime.getArrivalTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
assertEquals(stopTime.getDepartureTime(), StopTimeFieldMappingFactory.getStringAsSeconds("24:30:00"));
}
ServiceCalendar c = dao.getCalendarForServiceId(trip.getServiceId());
assertEquals(c.getStartDate(), new ServiceDate(2012, 9, 2));
assertEquals(c.getEndDate(), new ServiceDate(2012, 10, 15));
assertEquals(1, c.getMonday());
assertEquals(1, c.getTuesday());
assertEquals(1, c.getWednesday());
assertEquals(1, c.getThursday());
assertEquals(0, c.getFriday());
assertEquals(0, c.getSaturday());
assertEquals(1, c.getSunday());
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class StopTimeArray method get.
@Override
public StopTime get(int index) {
if (index < 0 || index >= size) {
throw new NoSuchElementException();
}
StopTime stopTime = new StopTime();
stopTime.setProxy(new StopTimeProxyImpl(index));
return stopTime;
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class PropertyMethodResolverImplTest method testTripStopTimesVirtualMethod.
@Test
public void testTripStopTimesVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Trip trip = new Trip();
trip.setId(new AgencyAndId("1", "t0"));
_dao.saveEntity(trip);
StopTime stopTime = new StopTime();
stopTime.setTrip(trip);
stopTime.setStop(new Stop());
_dao.saveEntity(stopTime);
PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "stop_times");
assertEquals(Arrays.asList(stopTime), method.invoke(trip));
}
use of org.onebusaway.gtfs.model.StopTime in project onebusaway-gtfs-modules by OneBusAway.
the class GtfsReaderTest method testCaltrain.
@Test
public void testCaltrain() throws IOException, ParseException {
File resourcePath = GtfsTestData.getCaltrainGtfs();
String agencyId = "Caltrain";
GtfsDao entityStore = processFeed(resourcePath, agencyId, false);
Collection<Agency> agencies = entityStore.getAllAgencies();
assertEquals(1, agencies.size());
Agency agency = entityStore.getAgencyForId(agencyId);
assertNotNull(agency);
assertEquals("Caltrain", agency.getName());
assertEquals("http://www.caltrain.com", agency.getUrl());
assertEquals("America/Los_Angeles", agency.getTimezone());
assertNull(agency.getPhone());
assertNull(agency.getLang());
Collection<Route> routes = entityStore.getAllRoutes();
assertEquals(3, routes.size());
AgencyAndId routeBulletId = new AgencyAndId(agencyId, "ct_bullet");
Route routeBullet = entityStore.getRouteForId(routeBulletId);
assertEquals(routeBulletId, routeBullet.getId());
assertEquals(agency, routeBullet.getAgency());
assertNull(routeBullet.getShortName());
assertEquals("Bullet", routeBullet.getLongName());
assertNull(routeBullet.getDesc());
assertEquals(2, routeBullet.getType());
assertNull(routeBullet.getUrl());
assertNull(routeBullet.getColor());
assertEquals("ff0000", routeBullet.getTextColor());
Route routeLocal = entityStore.getRouteForId(new AgencyAndId(agencyId, "ct_local"));
Collection<Stop> stops = entityStore.getAllStops();
assertEquals(31, stops.size());
AgencyAndId stopAId = new AgencyAndId(agencyId, "San Francisco Caltrain");
Stop stopA = entityStore.getStopForId(stopAId);
assertEquals(stopAId, stopA.getId());
assertNull(stopA.getCode());
assertEquals("700 4th Street, San Francisco", stopA.getDesc());
assertEquals(37.7764393371, stopA.getLat(), 0.000001);
assertEquals(-122.394322993, stopA.getLon(), 0.000001);
assertEquals(0, stopA.getLocationType());
assertEquals("San Francisco Caltrain", stopA.getName());
assertEquals("1", stopA.getZoneId());
assertNull(stopA.getUrl());
AgencyAndId stopBId = new AgencyAndId(agencyId, "Gilroy Caltrain");
Stop stopB = entityStore.getStopForId(stopBId);
assertEquals(stopBId, stopB.getId());
assertNull(stopB.getCode());
assertEquals("7150 Monterey Street, Gilroy", stopB.getDesc());
assertEquals(37.003084, stopB.getLat(), 0.000001);
assertEquals(-121.567091, stopB.getLon(), 0.000001);
assertEquals(0, stopB.getLocationType());
assertEquals("Gilroy Caltrain", stopB.getName());
assertEquals("6", stopB.getZoneId());
assertNull(stopB.getUrl());
Collection<Trip> trips = entityStore.getAllTrips();
assertEquals(260, trips.size());
AgencyAndId tripAId = new AgencyAndId(agencyId, "10101272009");
Trip tripA = entityStore.getTripForId(tripAId);
assertEquals(tripAId, tripA.getId());
assertNull(tripA.getBlockId());
assertEquals("0", tripA.getDirectionId());
assertEquals(routeLocal, tripA.getRoute());
assertEquals(new AgencyAndId(agencyId, "WD01272009"), tripA.getServiceId());
assertEquals(new AgencyAndId(agencyId, "cal_sj_sf"), tripA.getShapeId());
assertEquals("San Jose to San Francisco", tripA.getTripHeadsign());
Collection<StopTime> stopTimes = entityStore.getAllStopTimes();
assertEquals(4712, stopTimes.size());
StopTime stopTimeA = stopTimes.iterator().next();
assertEquals(entityStore.getTripForId(new AgencyAndId(agencyId, "10101272009")), stopTimeA.getTrip());
assertEquals(21120, stopTimeA.getArrivalTime());
assertEquals(21120, stopTimeA.getDepartureTime());
assertEquals(entityStore.getStopForId(new AgencyAndId(agencyId, "22nd Street Caltrain")), stopTimeA.getStop());
assertEquals(21, stopTimeA.getStopSequence());
assertNull(stopTimeA.getStopHeadsign());
assertEquals(0, stopTimeA.getPickupType());
assertEquals(0, stopTimeA.getDropOffType());
assertFalse(stopTimeA.isShapeDistTraveledSet());
Collection<ShapePoint> shapePoints = entityStore.getAllShapePoints();
assertEquals(2677, shapePoints.size());
AgencyAndId shapeId = new AgencyAndId(agencyId, "cal_sf_gil");
ShapePoint shapePointA = getShapePoint(shapePoints, shapeId, 1);
assertEquals(shapeId, shapePointA.getShapeId());
assertEquals(1, shapePointA.getSequence());
assertEquals(37.776439059278346, shapePointA.getLat(), 0.0);
assertEquals(-122.39441156387329, shapePointA.getLon(), 0.0);
assertFalse(shapePointA.isDistTraveledSet());
Collection<ServiceCalendar> calendars = entityStore.getAllCalendars();
assertEquals(6, calendars.size());
ServiceCalendar calendarA = entityStore.getCalendarForId(new Integer(1));
assertEquals(new Integer(1), calendarA.getId());
assertEquals(new AgencyAndId(agencyId, "SN01272009"), calendarA.getServiceId());
assertEquals(new ServiceDate(2009, 3, 2), calendarA.getStartDate());
assertEquals(new ServiceDate(2019, 3, 2), calendarA.getEndDate());
assertEquals(0, calendarA.getMonday());
assertEquals(0, calendarA.getTuesday());
assertEquals(0, calendarA.getWednesday());
assertEquals(0, calendarA.getThursday());
assertEquals(0, calendarA.getFriday());
assertEquals(1, calendarA.getSaturday());
assertEquals(1, calendarA.getSunday());
Collection<ServiceCalendarDate> calendarDates = entityStore.getAllCalendarDates();
assertEquals(10, calendarDates.size());
ServiceCalendarDate cd = entityStore.getCalendarDateForId(new Integer(1));
assertEquals(new Integer(1), cd.getId());
assertEquals(new AgencyAndId(agencyId, "SN01272009"), cd.getServiceId());
assertEquals(new ServiceDate(2009, 5, 25), cd.getDate());
assertEquals(1, cd.getExceptionType());
Collection<FareAttribute> fareAttributes = entityStore.getAllFareAttributes();
assertEquals(6, fareAttributes.size());
AgencyAndId fareId = new AgencyAndId(agencyId, "OW_1");
FareAttribute fareAttribute = entityStore.getFareAttributeForId(fareId);
assertEquals(fareId, fareAttribute.getId());
assertEquals(2.50, fareAttribute.getPrice(), 0.0);
assertEquals("USD", fareAttribute.getCurrencyType());
assertEquals(1, fareAttribute.getPaymentMethod());
assertFalse(fareAttribute.isTransfersSet());
assertFalse(fareAttribute.isTransferDurationSet());
Collection<FareRule> fareRules = entityStore.getAllFareRules();
assertEquals(36, fareRules.size());
List<FareRule> fareRuleMatches = GtfsTestData.grep(fareRules, "fare", fareAttribute);
assertEquals(6, fareRuleMatches.size());
fareRuleMatches = GtfsTestData.grep(fareRuleMatches, "originId", "1");
assertEquals(1, fareRuleMatches.size());
FareRule fareRule = fareRuleMatches.get(0);
assertEquals(fareAttribute, fareRule.getFare());
assertEquals("1", fareRule.getOriginId());
assertEquals("1", fareRule.getDestinationId());
assertNull(fareRule.getRoute());
assertNull(fareRule.getContainsId());
}
Aggregations