Search in sources :

Example 11 with ServiceDate

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

the class ExtendedCalendarServiceImplTest method testGetServiceDatesWithinRange02.

@Test
public void testGetServiceDatesWithinRange02() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA", "sB"), lsids());
    Date from = UnitTestingSupport.date("2010-09-11 09:30");
    Date to = UnitTestingSupport.date("2010-09-11 10:30");
    Collection<Date> dates = _service.getServiceDatesWithinRange(serviceIds, interval, from, to);
    assertEquals(1, dates.size());
    assertTrue(dates.contains(new ServiceDate(2010, 9, 11).getAsDate(timeZone())));
    from = UnitTestingSupport.date("2010-09-10 09:30");
    to = UnitTestingSupport.date("2010-09-10 10:30");
    dates = _service.getServiceDatesWithinRange(serviceIds, interval, from, to);
    assertEquals(0, dates.size());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Test(org.junit.Test)

Example 12 with ServiceDate

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

the class ExtendedCalendarServiceImplTest method testGetServiceDatesWithinRange01.

@Test
public void testGetServiceDatesWithinRange01() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
    Date from = UnitTestingSupport.date("2010-09-10 09:30");
    Date to = UnitTestingSupport.date("2010-09-10 10:30");
    Collection<Date> dates = _service.getServiceDatesWithinRange(serviceIds, interval, from, to);
    assertEquals(1, dates.size());
    assertTrue(dates.contains(new ServiceDate(2010, 9, 10).getAsDate(timeZone())));
    from = UnitTestingSupport.date("2010-09-11 09:30");
    to = UnitTestingSupport.date("2010-09-11 10:30");
    dates = _service.getServiceDatesWithinRange(serviceIds, interval, from, to);
    assertEquals(0, dates.size());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Test(org.junit.Test)

Example 13 with ServiceDate

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

the class HastusTranslateTask method createGtfs.

private void createGtfs(HastusData hd) {
    if (hd == null) {
        _log.info("nothing to do");
        return;
    }
    if (!hd.isValid()) {
        _log.info("incomplete hd=" + hd);
        return;
    }
    File hastus = new File(hd.getScheduleDataDirectory());
    File gis = new File(hd.getGisDataDirectory());
    try {
        HastusGtfsFactory factory = new HastusGtfsFactory();
        if (hastus != null && gis != null) {
            File outputDir = new File(requestResponse.getResponse().getBundleOutputDirectory() + File.separator + hd.getAgencyId());
            outputDir.mkdirs();
            factory.setScheduleInputPath(hastus);
            factory.setGisInputPath(gis);
            factory.setGtfsOutputPath(outputDir);
            factory.setCalendarStartDate(new ServiceDate(requestResponse.getRequest().getBundleStartDate().toDateTimeAtStartOfDay().toDate()));
            factory.setCalendarEndDate(new ServiceDate(requestResponse.getRequest().getBundleEndDate().toDateTimeAtStartOfDay().toDate()));
            _log.info("running HastusGtfsFactory...");
            factory.run();
            _log.info("done!");
            String zipFilename = postPackage(outputDir.toString(), requestResponse.getResponse().getTmpDirectory(), hd.getAgencyId());
            cleanup(outputDir);
            updateGtfsBundle(requestResponse, zipFilename, hd);
            _log.info("created zipFilename=" + zipFilename);
            String msg = "Packaged " + hastus + " and " + gis + " to GTFS to support Community Transit with output=" + outputDir;
            _log.info(msg);
            logger.changelog(msg);
        } else {
            _log.error("missing required inputs: hastus=" + hastus + ", gis=" + gis);
        }
    } catch (Throwable ex) {
        _log.error("error packaging Community Transit gtfs:", ex);
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HastusGtfsFactory(org.onebusaway.admin.service.bundle.hastus.HastusGtfsFactory) File(java.io.File)

Example 14 with ServiceDate

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

the class ModifyStartDateTask method run.

public void run() {
    if (!requestResponse.getRequest().getPredate()) {
        _log.info("ModifyStartDateTask Exiting, predate flag not set");
        return;
    }
    _log.info("ModifyStartDateTask Running:  predate flag is set");
    Collection<ServiceCalendar> calendars = _gtfsMutableRelationalDao.getAllCalendars();
    _log.info("found " + calendars.size() + " calendar entries");
    for (ServiceCalendar sc : calendars) {
        if (isApplicable(sc)) {
            Calendar cal = Calendar.getInstance();
            cal.setTime(sc.getStartDate().getAsDate());
            // go back 15 days recomputing month if necessary
            cal.add(Calendar.DAY_OF_YEAR, ROLLBACK_INTERVAL);
            _log.info("changed (" + sc.getServiceId() + ") calendar start date from " + sc.getStartDate().getAsDate() + " to " + cal.getTime());
            sc.setStartDate(new ServiceDate(cal));
        }
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Calendar(java.util.Calendar) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar)

Example 15 with ServiceDate

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

the class ServiceIdOverlapCache method computeCombinationsInternal.

private List<ServiceIdActivation> computeCombinationsInternal(Set<LocalizedServiceId> serviceIds) {
    Map<ServiceDate, Set<LocalizedServiceId>> serviceIdsByServiceDate = new FactoryMap<ServiceDate, Set<LocalizedServiceId>>(new HashSet<LocalizedServiceId>());
    for (LocalizedServiceId lsid : serviceIds) {
        AgencyAndId serviceId = lsid.getId();
        for (ServiceDate serviceDate : _calendarService.getServiceDatesForServiceId(serviceId)) serviceIdsByServiceDate.get(serviceDate).add(lsid);
    }
    Set<Set<LocalizedServiceId>> sets = new HashSet<Set<LocalizedServiceId>>();
    sets.addAll(serviceIdsByServiceDate.values());
    List<ServiceIdActivation> combinations = new ArrayList<ServiceIdActivation>();
    for (Set<LocalizedServiceId> activeServiceIds : sets) {
        Set<LocalizedServiceId> inactiveServiceIds = new HashSet<LocalizedServiceId>();
        for (Set<LocalizedServiceId> combo2 : sets) {
            if (isSubset(activeServiceIds, combo2))
                inactiveServiceIds.addAll(combo2);
        }
        inactiveServiceIds.removeAll(activeServiceIds);
        combinations.add(new ServiceIdActivation(list(activeServiceIds), list(inactiveServiceIds)));
    }
    Collections.sort(combinations);
    return combinations;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Set(java.util.Set) HashSet(java.util.HashSet) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) ArrayList(java.util.ArrayList) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) HashSet(java.util.HashSet)

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