Search in sources :

Example 1 with ServiceCalendar

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());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 2 with ServiceCalendar

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());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 3 with ServiceCalendar

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);
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) Set(java.util.Set) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ArrayList(java.util.ArrayList) List(java.util.List) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 4 with ServiceCalendar

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;
}
Also used : ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 5 with ServiceCalendar

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());
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Aggregations

ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)28 Test (org.junit.Test)18 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)18 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)17 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)17 Trip (org.onebusaway.gtfs.model.Trip)13 Agency (org.onebusaway.gtfs.model.Agency)8 Route (org.onebusaway.gtfs.model.Route)6 Stop (org.onebusaway.gtfs.model.Stop)6 GtfsRelationalDao (org.onebusaway.gtfs.services.GtfsRelationalDao)6 ShapePoint (org.onebusaway.gtfs.model.ShapePoint)5 StopTime (org.onebusaway.gtfs.model.StopTime)5 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)5 FareAttribute (org.onebusaway.gtfs.model.FareAttribute)4 GtfsRelationalDaoImpl (org.onebusaway.gtfs.impl.GtfsRelationalDaoImpl)3 FareRule (org.onebusaway.gtfs.model.FareRule)3 Frequency (org.onebusaway.gtfs.model.Frequency)3 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)3 ArrayList (java.util.ArrayList)2 Calendar (java.util.Calendar)2