Search in sources :

Example 31 with ServiceDate

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()));
        }
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Agency(org.onebusaway.gtfs.model.Agency) Calendar(java.util.Calendar) LineString(com.vividsolutions.jts.geom.LineString) NonLocalizedString(org.opentripplanner.util.NonLocalizedString) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate)

Example 32 with ServiceDate

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);
    }
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BitSet(java.util.BitSet) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Date(java.util.Date)

Example 33 with ServiceDate

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);
}
Also used : CalendarServiceData(org.onebusaway.gtfs.model.calendar.CalendarServiceData) GraphService(org.opentripplanner.routing.services.GraphService) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) CommandLineParameters(org.opentripplanner.standalone.CommandLineParameters) Graph(org.opentripplanner.routing.graph.Graph) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) OTPServer(org.opentripplanner.standalone.OTPServer) MemoryGraphSource(org.opentripplanner.routing.impl.MemoryGraphSource) RouterInfo(org.opentripplanner.api.model.RouterInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 34 with ServiceDate

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());
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) ServiceCalendar(org.onebusaway.gtfs.model.ServiceCalendar) Test(org.junit.Test)

Example 35 with ServiceDate

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());
}
Also used : ServiceCalendarDate(org.onebusaway.gtfs.model.ServiceCalendarDate) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Test(org.junit.Test)

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