use of org.onebusaway.gtfs.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class RoutingContext method setServiceDays.
/**
* Cache ServiceDay objects representing which services are running yesterday, today, and tomorrow relative to the search time. This information
* is very heavily used (at every transit boarding) and Date operations were identified as a performance bottleneck. Must be called after the
* TraverseOptions already has a CalendarService set.
*/
private void setServiceDays() {
Calendar c = Calendar.getInstance();
c.setTime(new Date(opt.getSecondsSinceEpoch() * 1000));
c.setTimeZone(graph.getTimeZone());
final ServiceDate serviceDate = new ServiceDate(c);
this.serviceDays = new ArrayList<ServiceDay>(3);
if (calendarService == null && graph.getCalendarService() != null && (opt.modes == null || opt.modes.contains(TraverseMode.TRANSIT))) {
LOG.warn("RoutingContext has no CalendarService. Transit will never be boarded.");
return;
}
for (String feedId : graph.getFeedIds()) {
for (Agency agency : graph.getAgencies(feedId)) {
addIfNotExists(this.serviceDays, new ServiceDay(graph, serviceDate.previous(), calendarService, agency.getId()));
addIfNotExists(this.serviceDays, new ServiceDay(graph, serviceDate, calendarService, agency.getId()));
addIfNotExists(this.serviceDays, new ServiceDay(graph, serviceDate.next(), calendarService, agency.getId()));
}
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class ServiceDay method init.
private void init(Graph graph, CalendarService cs, TimeZone timeZone) {
Date d = serviceDate.getAsDate(timeZone);
this.midnight = d.getTime() / 1000;
serviceIdsRunning = new BitSet(cs.getServiceIds().size());
for (AgencyAndId serviceId : cs.getServiceIdsOnDate(serviceDate)) {
int n = graph.serviceCodes.get(serviceId);
if (n < 0)
continue;
serviceIdsRunning.set(n);
}
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class RoutersTest method getRouterInfoReturnsFirstAndLastValidDateForGraph.
@Test
public void getRouterInfoReturnsFirstAndLastValidDateForGraph() {
final CalendarServiceData calendarService = new CalendarServiceData();
final List<ServiceDate> serviceDates = new ArrayList<ServiceDate>() {
{
add(new ServiceDate(2015, 10, 1));
add(new ServiceDate(2015, 11, 1));
}
};
calendarService.putServiceDatesForServiceId(new AgencyAndId("NA", "1"), serviceDates);
final Graph graph = new Graph();
graph.updateTransitFeedValidity(calendarService);
graph.expandToInclude(0, 100);
OTPServer otpServer = new OTPServer(new CommandLineParameters(), new GraphService());
otpServer.getGraphService().registerGraph("A", new MemoryGraphSource("A", graph));
Routers routerApi = new Routers();
routerApi.otpServer = otpServer;
RouterInfo info = routerApi.getGraphId("A");
assertNotNull(info.transitServiceStarts);
assertNotNull(info.transitServiceEnds);
assertTrue(info.transitServiceStarts < info.transitServiceEnds);
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate 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());
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-gtfs-modules by OneBusAway.
the class HibernateGtfsRelationalDaoImplCaltrainTest method testGetAllCalendarDates.
/**
**
* {@link ServiceCalendar} and {@link ServiceCalendarDate} Methods
***
*/
@Test
public void testGetAllCalendarDates() throws ParseException {
List<ServiceCalendarDate> calendarDates = _dao.getAllCalendarDates();
assertEquals(10, calendarDates.size());
List<ServiceCalendarDate> weekdays = grep(calendarDates, new Filter<ServiceCalendarDate>() {
public boolean isEnabled(ServiceCalendarDate element) {
return element.getServiceId().equals(aid("WD01272009"));
}
});
assertEquals(4, weekdays.size());
final ServiceDate serviceDate = new ServiceDate(2009, 5, 25);
List<ServiceCalendarDate> onDate = grep(weekdays, new Filter<ServiceCalendarDate>() {
@Override
public boolean isEnabled(ServiceCalendarDate object) {
return object.getDate().equals(serviceDate);
}
});
assertEquals(1, onDate.size());
ServiceCalendarDate cd = onDate.get(0);
assertEquals(2, cd.getExceptionType());
}
Aggregations