use of org.onebusaway.gtfs.model.ShapePoint in project onebusaway-gtfs-modules by OneBusAway.
the class EntityRetentionGraph method retainShapeId.
private void retainShapeId(AgencyAndId shapeId, boolean retainUp) {
if (retainUp) {
} else {
for (ShapePoint shapePoint : _dao.getShapePointsForShapeId(shapeId)) retainDown(shapePoint);
/**
* Need to make sure a shape id's agency is included as well, since the
* agency might not be included by any trips serving that shape id
*/
String agencyId = shapeId.getAgencyId();
Agency agency = _dao.getAgencyForId(agencyId);
if (agency != null) {
retainDown(agency);
}
}
}
use of org.onebusaway.gtfs.model.ShapePoint 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.ShapePoint in project onebusaway-gtfs-modules by OneBusAway.
the class ShapeDirectionTransformStrategyTest 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.putLines("trips.txt", "trip_id,route_id,service_id,direction_id,shape_id", "t0,r0,sid0,0,shp0", "t1,r0,sid0,1,shp0");
_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,02:30:00,02:30:00", "t1,s0,0,01:00:00,01:05:00", "t1,s1,1,01:30:00,01:30:00", "t1,s2,2,02:30:00,02:30:00");
_gtfs.putLines("shapes.txt", "shape_id,shape_pt_sequence,shape_pt_lat,shape_pt_lon", "shp0,1,1,1", "shp0,2,2,2", "shp0,3,3,3");
GtfsMutableRelationalDao dao = _gtfs.read();
TransformContext tc = new TransformContext();
tc.setDefaultAgencyId("a0");
_strategy.setShapeId("shp0");
_strategy.setShapeDirection("0");
_strategy.run(tc, dao);
UpdateLibrary.clearDaoCache(dao);
Collection<ShapePoint> newShapePoints = dao.getShapePointsForShapeId(AgencyAndId.convertFromString("a0_shp0R"));
assertFalse(newShapePoints.isEmpty());
ShapePoint sp0 = newShapePoints.iterator().next();
assertEquals(sp0.getLat(), 3, 0);
assertEquals(sp0.getLon(), 3, 0);
Trip t = dao.getTripForId(AgencyAndId.convertFromString("a0_t1"));
assertEquals(t.getDirectionId(), "1");
assertEquals(t.getShapeId().getId(), "shp0R");
}
use of org.onebusaway.gtfs.model.ShapePoint in project onebusaway-gtfs-modules by OneBusAway.
the class ShapePointArray method get.
@Override
public ShapePoint get(int index) {
if (index < 0 || index >= size) {
throw new NoSuchElementException();
}
ShapePoint shapePoint = new ShapePoint();
shapePoint.setProxy(new ShapePointProxyImpl(index));
return shapePoint;
}
use of org.onebusaway.gtfs.model.ShapePoint 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