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());
}
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());
}
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);
}
}
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));
}
}
}
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;
}
Aggregations