Search in sources :

Example 6 with ServiceDate

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

the class StopTimeServiceImpl method getNextBlockSequenceDeparturesForStop.

@Override
public List<StopTimeInstance> getNextBlockSequenceDeparturesForStop(StopEntry stopEntry, long time, boolean includePrivateSerivce) {
    List<StopTimeInstance> stopTimeInstances = new ArrayList<StopTimeInstance>();
    List<BlockStopSequenceIndex> blockStopTripIndices = _blockIndexService.getStopSequenceIndicesForStop(stopEntry);
    for (BlockStopSequenceIndex index : blockStopTripIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.BLOCK_STOP_TIME_DEPARTURE_INSTANCE);
            if (fromIndex < index.size()) {
                BlockStopTimeEntry blockStopTime = index.getBlockStopTimeForIndex(fromIndex);
                InstanceState state = new InstanceState(serviceDate.getTime());
                StopTimeInstance sti = new StopTimeInstance(blockStopTime, state);
                stopTimeInstances.add(sti);
            }
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
        List<Date> serviceDates = _calendarService.getNextServiceDatesForDepartureInterval(index.getServiceIds(), index.getServiceInterval(), time);
        for (Date serviceDate : serviceDates) {
            int relativeFrom = effectiveTime(serviceDate.getTime(), time);
            int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
            List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
            if (fromIndex < index.size()) {
                FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(fromIndex);
                BlockStopTimeEntry bst = entry.getStopTime();
                FrequencyEntry frequency = entry.getFrequency();
                InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
                int stopTimeOffset = entry.getStopTimeOffset();
                int frequencyOffset = computeFrequencyOffset(relativeFrom, bst, frequency, stopTimeOffset, true);
                StopTimeInstance sti = new StopTimeInstance(bst, state, frequencyOffset);
                stopTimeInstances.add(sti);
            }
        }
    }
    return stopTimeInstances;
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopSequenceIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopSequenceIndex) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 7 with ServiceDate

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

the class TransitDataServiceTemplateImpl method getScheduleForStop.

// @Override
public StopScheduleBean getScheduleForStop(String stopId, Date date) throws ServiceException {
    StopScheduleBean bean = new StopScheduleBean();
    bean.setDate(date);
    AgencyAndId id = convertAgencyAndId(stopId);
    StopBean stopBean = _stopBeanService.getStopForId(id);
    if (stopBean == null)
        return null;
    bean.setStop(stopBean);
    ServiceDate serviceDate = new ServiceDate(date);
    List<StopRouteScheduleBean> routes = _stopScheduleBeanService.getScheduledArrivalsForStopAndDate(id, serviceDate);
    bean.setRoutes(routes);
    StopCalendarDaysBean calendarDays = _stopScheduleBeanService.getCalendarForStop(id);
    bean.setCalendarDays(calendarDays);
    return bean;
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId)

Example 8 with ServiceDate

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

the class AgencyResource method getAgencyExpiryDateDelta.

@Path("{agencyId}/expiry-date-delta")
@GET
@Produces("application/json")
public Response getAgencyExpiryDateDelta(@PathParam("agencyId") String agencyId) {
    try {
        Date endDate = agencyEndDateMap.get(agencyId);
        if (endDate == null) {
            _log.info("Service end date for agency " + agencyId + " not cached.  Reloading");
            List<TripEntry> trips = _graph.getAllTrips();
            Set<AgencyAndId> tripSvcIds = new HashSet<AgencyAndId>();
            for (TripEntry trip : trips) {
                if (trip.getRoute().getId().getAgencyId().equals(agencyId)) {
                    tripSvcIds.add(trip.getServiceId().getId());
                }
            }
            Set<ServiceDate> serviceDates = new HashSet<ServiceDate>();
            for (AgencyAndId serviceId : tripSvcIds) {
                serviceDates.addAll(_calendarService.getServiceDatesForServiceId(serviceId));
            }
            ServiceDate[] serviceDateArray = serviceDates.toArray(new ServiceDate[serviceDates.size()]);
            Arrays.sort(serviceDateArray);
            if (serviceDateArray.length > 0) {
                endDate = serviceDateArray[serviceDateArray.length - 1].getAsDate();
                agencyEndDateMap.put(agencyId, endDate);
            } else {
                // set the end date to the epoch
                endDate = new Date(0l);
            }
        }
        Calendar latestSvcDate = Calendar.getInstance();
        latestSvcDate.setTime(endDate);
        int delta = deltaInDays(Calendar.getInstance(), latestSvcDate);
        return Response.ok(ok("agency-expiry-date-delta", delta)).build();
    } catch (Exception e) {
        _log.error("getAgencyExpiryDateDelta broke", e);
        return Response.ok(error("agency-expiry-date-delta", e)).build();
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Calendar(java.util.Calendar) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with ServiceDate

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

the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds03.

@Test
public void testGetServiceDatesForServiceIds03() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sC", "sD"), lsids());
    Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
    assertEquals(1, dates.size());
    assertTrue(dates.contains(new ServiceDate(2010, 9, 13).getAsDate(timeZone())));
}
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 10 with ServiceDate

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

the class ExtendedCalendarServiceImplTest method testGetServiceDatesForServiceIds02.

@Test
public void testGetServiceDatesForServiceIds02() {
    ServiceIdActivation serviceIds = serviceIds(lsids("sA", "sB"), lsids());
    Set<Date> dates = _service.getDatesForServiceIds(serviceIds);
    assertEquals(1, dates.size());
    assertTrue(dates.contains(new ServiceDate(2010, 9, 11).getAsDate(timeZone())));
}
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)

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