use of org.onebusaway.gtfs.model.ServiceCalendar in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetAllCalendars.
@Test
public void testGetAllCalendars() throws ParseException {
List<ServiceCalendar> calendars = _dao.getAllCalendars();
assertEquals(6, calendars.size());
List<ServiceCalendar> weekdays = grep(calendars, new Filter<ServiceCalendar>() {
@Override
public boolean isEnabled(ServiceCalendar object) {
return object.getServiceId().equals(aid("WD"));
}
});
assertEquals(1, weekdays.size());
ServiceCalendar weekday = weekdays.get(0);
assertEquals(new ServiceDate(2009, 1, 1), weekday.getStartDate());
assertEquals(new ServiceDate(2009, 3, 1), weekday.getEndDate());
assertEquals(1, weekday.getMonday());
assertEquals(1, weekday.getTuesday());
assertEquals(1, weekday.getWednesday());
assertEquals(1, weekday.getThursday());
assertEquals(1, weekday.getFriday());
assertEquals(0, weekday.getSaturday());
assertEquals(0, weekday.getSunday());
}
use of org.onebusaway.gtfs.model.ServiceCalendar in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalImplBartTest method testCalendarForServiceId.
@Test
public void testCalendarForServiceId() {
ServiceCalendar calendar = _dao.getCalendarForServiceId(new AgencyAndId("BART", "WKDY"));
assertEquals(new ServiceDate(2007, 1, 1), calendar.getStartDate());
}
use of org.onebusaway.gtfs.model.ServiceCalendar 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.ServiceCalendar in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarSimplicationLibrary method createServiceCalendar.
private ServiceCalendar createServiceCalendar(AgencyAndId updatedServiceId, Set<Integer> daysOfTheWeekToUse, ServiceDate fromDate, ServiceDate toDate) {
ServiceCalendar sc = new ServiceCalendar();
sc.setServiceId(updatedServiceId);
sc.setStartDate(fromDate);
sc.setEndDate(toDate);
if (daysOfTheWeekToUse.contains(Calendar.MONDAY))
sc.setMonday(1);
if (daysOfTheWeekToUse.contains(Calendar.TUESDAY))
sc.setTuesday(1);
if (daysOfTheWeekToUse.contains(Calendar.WEDNESDAY))
sc.setWednesday(1);
if (daysOfTheWeekToUse.contains(Calendar.THURSDAY))
sc.setThursday(1);
if (daysOfTheWeekToUse.contains(Calendar.FRIDAY))
sc.setFriday(1);
if (daysOfTheWeekToUse.contains(Calendar.SATURDAY))
sc.setSaturday(1);
if (daysOfTheWeekToUse.contains(Calendar.SUNDAY))
sc.setSunday(1);
return sc;
}
use of org.onebusaway.gtfs.model.ServiceCalendar in project onebusaway-gtfs-modules by OneBusAway.
the class CalendarExtensionStrategyTest method testCalendarSelectiveExtension.
@Test
public void testCalendarSelectiveExtension() throws IOException {
_gtfs.putCalendars(2, "start_date=20110630,20120701", "end_date=20120630,20121231", "mask=1111111");
GtfsMutableRelationalDao dao = _gtfs.read();
ServiceDate endDate = new ServiceDate(2013, 12, 31);
_strategy.setEndDate(endDate);
_strategy.run(_context, dao);
{
ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid0"));
assertEquals(new ServiceDate(2012, 6, 30), calendar.getEndDate());
}
{
ServiceCalendar calendar = dao.getCalendarForServiceId(new AgencyAndId("a0", "sid1"));
assertEquals(endDate, calendar.getEndDate());
}
}
Aggregations