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