Search in sources :

Example 11 with ServiceCalendar

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

the class CalendarServiceDataFactoryImplSyntheticTest method calendar.

private ServiceCalendar calendar(AgencyAndId serviceId, ServiceDate startDate, ServiceDate endDate, String days) {
    if (days.length() != 7)
        throw new IllegalStateException("invalid days string: " + days);
    ServiceCalendar calendar = new ServiceCalendar();
    calendar.setStartDate(startDate);
    calendar.setEndDate(endDate);
    calendar.setServiceId(serviceId);
    calendar.setMonday(days.charAt(0) == '1' ? 1 : 0);
    calendar.setTuesday(days.charAt(1) == '1' ? 1 : 0);
    calendar.setWednesday(days.charAt(2) == '1' ? 1 : 0);
    calendar.setThursday(days.charAt(3) == '1' ? 1 : 0);
    calendar.setFriday(days.charAt(4) == '1' ? 1 : 0);
    calendar.setSaturday(days.charAt(5) == '1' ? 1 : 0);
    calendar.setSunday(days.charAt(5) == '1' ? 1 : 0);
    return calendar;
}
Also used : ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 12 with ServiceCalendar

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

the class PropertyMethodResolverImplTest method testTripCalendarsVirtualMethod.

@Test
public void testTripCalendarsVirtualMethod() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
    Trip trip = new Trip();
    trip.setId(new AgencyAndId("1", "t0"));
    trip.setServiceId(new AgencyAndId("1", "sid0"));
    _dao.saveEntity(trip);
    ServiceCalendar calendar = new ServiceCalendar();
    calendar.setServiceId(trip.getServiceId());
    _dao.saveEntity(calendar);
    PropertyMethod method = _resolver.getPropertyMethod(Trip.class, "calendar");
    assertEquals(calendar, method.invoke(trip));
}
Also used : Trip(org.onebusaway.gtfs.model.Trip) PropertyMethod(org.onebusaway.collections.beans.PropertyMethod) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 13 with ServiceCalendar

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

the class CalendarExtensionStrategy method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao) {
    CalendarService service = CalendarServiceDataFactoryImpl.createService(dao);
    CalendarSimplicationLibrary simplication = new CalendarSimplicationLibrary();
    for (AgencyAndId serviceId : dao.getAllServiceIds()) {
        ServiceCalendarSummary summary = simplication.getSummaryForServiceDates(service.getServiceDatesForServiceId(serviceId));
        /**
       * If a service id has no active dates at all, we don't extend it.
       */
        if (summary.allServiceDates.isEmpty()) {
            continue;
        }
        ServiceCalendar calendar = dao.getCalendarForServiceId(serviceId);
        if (calendar == null) {
            ServiceDate lastDate = summary.serviceDatesInOrder.get(summary.serviceDatesInOrder.size() - 1);
            if (lastDate.compareTo(inactiveCalendarCutoff) < 0) {
                continue;
            }
            /**
         * We only want days of the week that are in service past our stale
         * calendar cutoff.
         */
            Set<Integer> daysOfTheWeekToUse = getDaysOfTheWeekToUse(summary);
            if (daysOfTheWeekToUse.isEmpty()) {
                continue;
            }
            ServiceDate firstMissingDate = lastDate.next();
            for (ServiceDate serviceDate = firstMissingDate; serviceDate.compareTo(endDate) <= 0; serviceDate = serviceDate.next()) {
                Calendar serviceDateAsCalendar = serviceDate.getAsCalendar(_utcTimeZone);
                // Move the calendar forward to "noon" to mitigate the effects of DST
                // (though the shouldn't be a problem for UTC?)
                serviceDateAsCalendar.add(Calendar.HOUR_OF_DAY, 12);
                int dayOfWeek = serviceDateAsCalendar.get(Calendar.DAY_OF_WEEK);
                if (daysOfTheWeekToUse.contains(dayOfWeek)) {
                    ServiceCalendarDate scd = new ServiceCalendarDate();
                    scd.setDate(serviceDate);
                    scd.setExceptionType(ServiceCalendarDate.EXCEPTION_TYPE_ADD);
                    scd.setServiceId(serviceId);
                    dao.saveEntity(scd);
                }
            }
        } else {
            if (calendar.getEndDate().compareTo(inactiveCalendarCutoff) >= 0) {
                calendar.setEndDate(endDate);
            }
        }
    }
    UpdateLibrary.clearDaoCache(dao);
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Calendar(java.util.Calendar) ServiceCalendarSummary(org.onebusaway.gtfs_transformer.updates.CalendarSimplicationLibrary.ServiceCalendarSummary) CalendarService(org.onebusaway.gtfs.services.calendar.CalendarService) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 14 with ServiceCalendar

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

the class CalendarSimplicationLibrary method computeSimplifiedCalendar.

public void computeSimplifiedCalendar(AgencyAndId updatedServiceId, ServiceCalendarSummary summary, List<Object> newEntities) {
    List<ServiceDate> serviceDatesInOrder = summary.serviceDatesInOrder;
    Set<Integer> daysOfTheWeekToUse = summary.daysOfTheWeekToUse;
    if (serviceDatesInOrder.isEmpty()) {
        return;
    }
    ServiceDate fromDate = serviceDatesInOrder.get(0);
    ServiceDate toDate = serviceDatesInOrder.get(serviceDatesInOrder.size() - 1);
    boolean useDateRange = summary.maxDayOfWeekCount >= _minNumberOfWeeksForCalendarEntry;
    if (useDateRange) {
        ServiceCalendar sc = createServiceCalendar(updatedServiceId, daysOfTheWeekToUse, fromDate, toDate);
        newEntities.add(sc);
    }
    TimeZone tz = TimeZone.getTimeZone("UTC");
    for (ServiceDate serviceDate = fromDate; serviceDate.compareTo(toDate) <= 0; serviceDate = serviceDate.next()) {
        boolean isActive = summary.allServiceDates.contains(serviceDate);
        Calendar serviceDateAsCalendar = serviceDate.getAsCalendar(tz);
        if (useDateRange) {
            int dayOfWeek = serviceDateAsCalendar.get(Calendar.DAY_OF_WEEK);
            boolean dateRangeIncludesServiceDate = daysOfTheWeekToUse.contains(dayOfWeek);
            if (isActive && !dateRangeIncludesServiceDate) {
                ServiceCalendarDate scd = new ServiceCalendarDate();
                scd.setDate(serviceDate);
                scd.setExceptionType(ServiceCalendarDate.EXCEPTION_TYPE_ADD);
                scd.setServiceId(updatedServiceId);
                newEntities.add(scd);
            }
            if (!isActive && dateRangeIncludesServiceDate) {
                ServiceCalendarDate scd = new ServiceCalendarDate();
                scd.setDate(serviceDate);
                scd.setExceptionType(ServiceCalendarDate.EXCEPTION_TYPE_REMOVE);
                scd.setServiceId(updatedServiceId);
                newEntities.add(scd);
            }
        } else {
            if (isActive) {
                ServiceCalendarDate scd = new ServiceCalendarDate();
                scd.setDate(serviceDate);
                scd.setExceptionType(ServiceCalendarDate.EXCEPTION_TYPE_ADD);
                scd.setServiceId(updatedServiceId);
                newEntities.add(scd);
            }
        }
    }
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) TimeZone(java.util.TimeZone) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Calendar(java.util.Calendar) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 15 with ServiceCalendar

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

the class ServiceIdTransformStrategyImpl method run.

@Override
public void run(TransformContext context, GtfsMutableRelationalDao dao, Object entity) {
    AgencyAndId oldServiceId = context.resolveId(ServiceIdKey.class, _oldServiceId);
    AgencyAndId newServiceId = context.resolveId(ServiceIdKey.class, _newServiceId);
    ServiceCalendar calendar = dao.getCalendarForServiceId(oldServiceId);
    if (calendar != null) {
        calendar.setServiceId(newServiceId);
    }
    for (ServiceCalendarDate calendarDate : dao.getCalendarDatesForServiceId(oldServiceId)) {
        calendarDate.setServiceId(newServiceId);
    }
    for (Trip trip : dao.getTripsForServiceId(oldServiceId)) {
        trip.setServiceId(newServiceId);
    }
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) Trip(org.onebusaway.gtfs.model.Trip) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

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