use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetAllCalendarDates.
/****
* {@link ServiceCalendar} and {@link ServiceCalendarDate} Methods
****/
@Test
public void testGetAllCalendarDates() throws ParseException {
List<ServiceCalendarDate> calendarDates = _dao.getAllCalendarDates();
assertEquals(10, calendarDates.size());
List<ServiceCalendarDate> weekdays = grep(calendarDates, new Filter<ServiceCalendarDate>() {
public boolean isEnabled(ServiceCalendarDate element) {
return element.getServiceId().equals(aid("WD01272009"));
}
});
assertEquals(4, weekdays.size());
final ServiceDate serviceDate = new ServiceDate(2009, 5, 25);
List<ServiceCalendarDate> onDate = grep(weekdays, new Filter<ServiceCalendarDate>() {
@Override
public boolean isEnabled(ServiceCalendarDate object) {
return object.getDate().equals(serviceDate);
}
});
assertEquals(1, onDate.size());
ServiceCalendarDate cd = onDate.get(0);
assertEquals(2, cd.getExceptionType());
}
use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalImplBartTest method testCalendarDateForServiceId.
@Test
public void testCalendarDateForServiceId() {
List<ServiceCalendarDate> calendarDates = _dao.getCalendarDatesForServiceId(new AgencyAndId("BART", "WKDY"));
assertEquals(7, calendarDates.size());
}
use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.
the class DeduplicateServiceIdsStrategy method run.
@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
Map<Set<ServiceDate>, List<AgencyAndId>> serviceIdsByServiceDates = new FactoryMap<Set<ServiceDate>, List<AgencyAndId>>(new ArrayList<AgencyAndId>());
for (AgencyAndId serviceId : dao.getAllServiceIds()) {
Set<ServiceDate> serviceDates = service.getServiceDatesForServiceId(serviceId);
serviceIdsByServiceDates.get(serviceDates).add(serviceId);
}
Map<AgencyAndId, AgencyAndId> serviceIdMapping = new HashMap<AgencyAndId, AgencyAndId>();
for (List<AgencyAndId> serviceIds : serviceIdsByServiceDates.values()) {
Collections.sort(serviceIds);
if (serviceIds.size() == 1) {
continue;
}
AgencyAndId target = serviceIds.get(0);
for (int i = 1; i < serviceIds.size(); ++i) {
AgencyAndId source = serviceIds.get(i);
serviceIdMapping.put(source, target);
}
}
for (Trip trip : dao.getAllTrips()) {
AgencyAndId mappedServiceId = serviceIdMapping.get(trip.getServiceId());
if (mappedServiceId != null) {
trip.setServiceId(mappedServiceId);
}
}
for (AgencyAndId serviceId : serviceIdMapping.keySet()) {
ServiceCalendar serviceCalendar = dao.getCalendarForServiceId(serviceId);
if (serviceCalendar != null) {
dao.removeEntity(serviceCalendar);
}
for (ServiceCalendarDate date : dao.getCalendarDatesForServiceId(serviceId)) {
dao.removeEntity(date);
}
}
_log.info("removed {} duplicate service ids", serviceIdMapping.size());
UpdateLibrary.clearDaoCache(dao);
}
use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationLibraryTest method test.
@Test
public void test() throws IOException {
MockGtfs gtfs = MockGtfs.create();
gtfs.putAgencies(1, "agency_timezone=America/New_York");
gtfs.putRoutes(1);
gtfs.putTrips(1, "r0", "sid0");
gtfs.putStops(1);
gtfs.putStopTimes("t0", "s0");
gtfs.putCalendarDates("sid0=20120305,20120306,20120307,20120308,20120309," + "20120312,20120313,20120314,20120315,20120316,20120319,20120320,20120321,20120323," + "20120326,20120327,20120328,20120329,20120330");
GtfsMutableRelationalDao dao = gtfs.read();
CalendarService calendarService = CalendarServiceDataFactoryImpl.createService(dao);
AgencyAndId originalId = new AgencyAndId("a0", "sid0");
AgencyAndId updatedId = new AgencyAndId("a0", "sidX");
ServiceCalendarSummary summary = _library.getSummaryForServiceDates(calendarService.getServiceDatesForServiceId(originalId));
List<Object> newEntities = new ArrayList<Object>();
_library.computeSimplifiedCalendar(updatedId, summary, newEntities);
List<ServiceCalendar> calendars = getEntities(newEntities, ServiceCalendar.class);
assertEquals(1, calendars.size());
ServiceCalendar calendar = calendars.get(0);
assertEquals(updatedId, calendar.getServiceId());
assertEquals(new ServiceDate(2012, 03, 05), calendar.getStartDate());
assertEquals(new ServiceDate(2012, 03, 30), 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());
List<ServiceCalendarDate> calendarDates = getEntities(newEntities, ServiceCalendarDate.class);
assertEquals(1, calendarDates.size());
ServiceCalendarDate date = calendarDates.get(0);
assertEquals(updatedId, date.getServiceId());
assertEquals(new ServiceDate(2012, 03, 22), date.getDate());
assertEquals(ServiceCalendarDate.EXCEPTION_TYPE_REMOVE, date.getExceptionType());
}
use of org.onebusaway.gtfs.model.ServiceCalendarDate in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationStrategyTest method testBasicSimplification.
@Test
public void testBasicSimplification() {
_gtfs.putAgencies(1);
_gtfs.putStops(1);
_gtfs.putRoutes(1);
_gtfs.putTrips(1, "r0", "sid0");
_gtfs.putStopTimes("t0", "s0");
_gtfs.putCalendars(1, "start_date=20120903", "end_date=20120916");
_gtfs.putCalendarDates("sid0=20120917,20120918,20120919,20120920,20120921,20120922,20120923");
GtfsRelationalDao dao = transform();
AgencyAndId serviceId = new AgencyAndId("a0", "sid0");
ServiceCalendar c = dao.getCalendarForServiceId(serviceId);
assertEquals(new ServiceDate(2012, 9, 3), c.getStartDate());
assertEquals(new ServiceDate(2012, 9, 23), c.getEndDate());
List<ServiceCalendarDate> serviceDates = dao.getCalendarDatesForServiceId(serviceId);
assertEquals(0, serviceDates.size());
}
Aggregations