Search in sources :

Example 36 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate 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 37 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsHibernateReaderExampleMain method main.

public static void main(String[] args) throws IOException {
    if (!(args.length == 1 || args.length == 2)) {
        System.err.println("usage: gtfsPath [hibernate-config.xml]");
        System.exit(-1);
    }
    String resource = "classpath:org/onebusaway/gtfs/examples/hibernate-configuration-examples.xml";
    if (args.length == 2)
        resource = args[1];
    HibernateGtfsFactory factory = createHibernateGtfsFactory(resource);
    GtfsReader reader = new GtfsReader();
    reader.setInputLocation(new File(args[0]));
    GtfsMutableRelationalDao dao = factory.getDao();
    reader.setEntityStore(dao);
    reader.run();
    Collection<Stop> stops = dao.getAllStops();
    for (Stop stop : stops) System.out.println(stop.getName());
    CalendarService calendarService = factory.getCalendarService();
    Set<AgencyAndId> serviceIds = calendarService.getServiceIds();
    for (AgencyAndId serviceId : serviceIds) {
        Set<ServiceDate> dates = calendarService.getServiceDatesForServiceId(serviceId);
        ServiceDate from = null;
        ServiceDate to = null;
        for (ServiceDate date : dates) {
            from = min(from, date);
            to = max(to, date);
        }
        System.out.println("serviceId=" + serviceId + " from=" + from + " to=" + to);
    }
}
Also used : GtfsMutableRelationalDao(org.onebusaway.gtfs.services.GtfsMutableRelationalDao) GtfsReader(org.onebusaway.gtfs.serialization.GtfsReader) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) HibernateGtfsFactory(org.onebusaway.gtfs.services.HibernateGtfsFactory) File(java.io.File) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService)

Example 38 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarServiceDataFactoryImpl method getServiceDatesForServiceId.

public Set<ServiceDate> getServiceDatesForServiceId(AgencyAndId serviceId, TimeZone serviceIdTimeZone) {
    Set<ServiceDate> activeDates = new HashSet<ServiceDate>();
    ServiceCalendar c = _dao.getCalendarForServiceId(serviceId);
    if (c != null) {
        addDatesFromCalendar(c, serviceIdTimeZone, activeDates);
    }
    for (ServiceCalendarDate cd : _dao.getCalendarDatesForServiceId(serviceId)) {
        addAndRemoveDatesFromCalendarDate(cd, serviceIdTimeZone, activeDates);
    }
    return activeDates;
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HashSet(java.util.HashSet) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 39 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarServiceDataFactoryImpl method addDatesFromCalendar.

private void addDatesFromCalendar(ServiceCalendar calendar, TimeZone timeZone, Set<ServiceDate> activeDates) {
    /**
     * We calculate service dates relative to noon so as to avoid any weirdness
     * relative to DST.
     */
    Date startDate = getServiceDateAsNoon(calendar.getStartDate(), timeZone);
    Date endDate = getServiceDateAsNoon(calendar.getEndDate(), timeZone);
    java.util.Calendar c = java.util.Calendar.getInstance(timeZone);
    c.setTime(startDate);
    while (true) {
        Date date = c.getTime();
        if (date.after(endDate))
            break;
        int day = c.get(java.util.Calendar.DAY_OF_WEEK);
        boolean active = false;
        switch(day) {
            case java.util.Calendar.MONDAY:
                active = calendar.getMonday() == 1;
                break;
            case java.util.Calendar.TUESDAY:
                active = calendar.getTuesday() == 1;
                break;
            case java.util.Calendar.WEDNESDAY:
                active = calendar.getWednesday() == 1;
                break;
            case java.util.Calendar.THURSDAY:
                active = calendar.getThursday() == 1;
                break;
            case java.util.Calendar.FRIDAY:
                active = calendar.getFriday() == 1;
                break;
            case java.util.Calendar.SATURDAY:
                active = calendar.getSaturday() == 1;
                break;
            case java.util.Calendar.SUNDAY:
                active = calendar.getSunday() == 1;
                break;
        }
        if (active) {
            addServiceDate(activeDates, new ServiceDate(c), timeZone);
        }
        c.add(java.util.Calendar.DAY_OF_YEAR, 1);
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Calendar(java.util.Calendar) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate)

Example 40 with ServiceDate

use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.

the class CalendarServiceDataFactoryImpl method addAndRemoveDatesFromCalendarDate.

private void addAndRemoveDatesFromCalendarDate(ServiceCalendarDate calendarDate, TimeZone serviceIdTimeZone, Set<ServiceDate> activeDates) {
    ServiceDate serviceDate = calendarDate.getDate();
    Date targetDate = calendarDate.getDate().getAsDate();
    Calendar c = Calendar.getInstance();
    c.setTime(targetDate);
    switch(calendarDate.getExceptionType()) {
        case ServiceCalendarDate.EXCEPTION_TYPE_ADD:
            addServiceDate(activeDates, serviceDate, serviceIdTimeZone);
            break;
        case ServiceCalendarDate.EXCEPTION_TYPE_REMOVE:
            activeDates.remove(serviceDate);
            break;
        default:
            _log.warn("unknown CalendarDate exception type: " + calendarDate.getExceptionType());
            break;
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Calendar(java.util.Calendar) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date) ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate)

Aggregations

ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)134 Test (org.junit.Test)49 Date (java.util.Date)46 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)45 ArrayList (java.util.ArrayList)23 ServiceCalendar (org.onebusaway.gtfs.model.ServiceCalendar)23 Calendar (java.util.Calendar)22 ServiceCalendarDate (org.onebusaway.gtfs.model.ServiceCalendarDate)22 HashSet (java.util.HashSet)17 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)14 CalendarServiceData (org.onebusaway.gtfs.model.calendar.CalendarServiceData)13 CalendarService (org.onebusaway.gtfs.services.calendar.CalendarService)13 Set (java.util.Set)11 Trip (org.onebusaway.gtfs.model.Trip)11 TimeZone (java.util.TimeZone)10 GtfsMutableRelationalDao (org.onebusaway.gtfs.services.GtfsMutableRelationalDao)10 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)9 Agency (org.onebusaway.gtfs.model.Agency)8 TripDescriptor (com.google.transit.realtime.GtfsRealtime.TripDescriptor)7