use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceImpl method search.
private int search(List<Date> serviceDates, ServiceIdOp op, int indexFrom, int indexTo, Date key) {
if (indexTo == indexFrom)
return indexFrom;
int index = (indexFrom + indexTo) / 2;
Date serviceDate = op.getServiceDate(serviceDates, index);
int rc = op.compare(key, serviceDate);
if (rc == 0)
return index;
if (rc < 0)
return search(serviceDates, op, indexFrom, index, key);
else
return search(serviceDates, op, index + 1, indexTo, key);
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarServiceImplTest method test.
@Test
public void test() throws IOException {
GtfsRelationalDaoImpl dao = new GtfsRelationalDaoImpl();
GtfsTestData.readGtfs(dao, GtfsTestData.getIslandGtfs(), "26");
CalendarServiceDataFactoryImpl factory = new CalendarServiceDataFactoryImpl();
factory.setGtfsDao(dao);
CalendarServiceData data = factory.createData();
CalendarServiceImpl service = new CalendarServiceImpl();
service.setData(data);
ServiceDate from = new ServiceDate(2008, 10, 27);
ServiceDate to = new ServiceDate(2009, 9, 27);
Set<ServiceDate> toExclude = new HashSet<ServiceDate>();
toExclude.add(new ServiceDate(2009, 1, 1));
// 23,1,1,1,1,1,0,0,20081027,20090927
Set<ServiceDate> dates = service.getServiceDatesForServiceId(new AgencyAndId("26", "23"));
assertEquals(239, dates.size());
Date fromDate = from.getAsDate();
Date toDate = to.getAsDate();
Calendar c = Calendar.getInstance();
c.setTime(fromDate);
while (c.getTime().compareTo(toDate) <= 0) {
ServiceDate day = new ServiceDate(c);
int dow = c.get(Calendar.DAY_OF_WEEK);
if (!(dow == Calendar.SATURDAY || dow == Calendar.SUNDAY || toExclude.contains(day))) {
assertTrue(dates.contains(day));
}
c.add(Calendar.DAY_OF_YEAR, 1);
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate 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());
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class ServiceDateTest method testGetAsDateWithTimezoneA.
@Test
public void testGetAsDateWithTimezoneA() {
ServiceDate serviceDateA = new ServiceDate(2010, 2, 16);
TimeZone tzA = TimeZone.getTimeZone("America/Los_Angeles");
Date dateA = serviceDateA.getAsDate(tzA);
assertEquals(date("2010-02-16 00:00 Pacific Standard Time"), dateA);
TimeZone tzB = TimeZone.getTimeZone("America/Denver");
Date dateB = serviceDateA.getAsDate(tzB);
assertEquals(date("2010-02-16 00:00 Mountain Standard Time"), dateB);
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class ServiceDateTest method testCalendarConstructor.
@Test
public void testCalendarConstructor() {
Calendar c = Calendar.getInstance();
c.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
c.set(Calendar.YEAR, 2010);
c.set(Calendar.MONTH, Calendar.FEBRUARY);
c.set(Calendar.DAY_OF_MONTH, 12);
ServiceDate serviceDateA = new ServiceDate(c);
ServiceDate serviceDateB = new ServiceDate(2010, 2, 12);
assertEquals(serviceDateA, serviceDateB);
}
Aggregations