use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-application-modules by camsys.
the class ExtendedCalendarServiceImpl method computeServiceDatesForServiceIds.
private List<Date> computeServiceDatesForServiceIds(ServiceIdActivation serviceIds, Date lowerBounds, Date upperBounds) {
Set<Date> serviceDates = null;
for (LocalizedServiceId lsid : serviceIds.getActiveServiceIds()) {
List<Date> dates = _calendarService.getDatesForLocalizedServiceId(lsid);
if (dates == null)
dates = Collections.emptyList();
if (serviceDates == null)
serviceDates = new HashSet<Date>(dates);
else
serviceDates.retainAll(dates);
}
for (LocalizedServiceId lsid : serviceIds.getInactiveServiceIds()) {
List<Date> dates = _calendarService.getDatesForLocalizedServiceId(lsid);
if (serviceDates != null)
serviceDates.removeAll(dates);
}
List<Date> dates = new ArrayList<Date>();
if (serviceDates != null) {
for (Date serviceDate : serviceDates) {
if ((lowerBounds == null || lowerBounds.before(serviceDate)) && (upperBounds == null || serviceDate.before(upperBounds)))
dates.add(serviceDate);
}
}
Collections.sort(dates);
return dates;
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntriesFactoryTest method before.
@Before
public void before() {
/**
**
* Calendar Service
***
*/
_calendarService = new CalendarServiceImpl();
CalendarServiceData data = new CalendarServiceData();
_calendarService.setData(data);
addServiceDates(data, "sA", new ServiceDate(2010, 9, 10), new ServiceDate(2010, 9, 11));
addServiceDates(data, "sB", new ServiceDate(2010, 9, 11), new ServiceDate(2010, 9, 12));
/**
**
* Service Id Cache
***
*/
ServiceIdOverlapCache serviceIdOverlapCache = new ServiceIdOverlapCache();
serviceIdOverlapCache.setCalendarService(_calendarService);
/**
**
* ShapePointsService
***
*/
ShapePointHelper shapePointService = Mockito.mock(ShapePointHelper.class);
ShapePointsFactory shapePointsFactory = new ShapePointsFactory();
shapePointsFactory.addPoint(0, 0);
Mockito.when(shapePointService.getShapePointsForShapeId((AgencyAndId) Mockito.any())).thenReturn(shapePointsFactory.create());
/**
**
* Factory
***
*/
_factory = new BlockConfigurationEntriesFactory();
_factory.setServiceIdOverlapCache(serviceIdOverlapCache);
_factory.setShapePointHelper(shapePointService);
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project onebusaway-application-modules by camsys.
the class ServiceIdController method index.
@RequestMapping()
public ModelAndView index(@RequestParam() String serviceId) {
AgencyAndId id = AgencyAndIdLibrary.convertFromString(serviceId);
List<ServiceDate> serviceDates = new ArrayList<ServiceDate>(_calendarService.getServiceDatesForServiceId(id));
Collections.sort(serviceDates);
List<Date> dates = new ArrayList<Date>();
for (ServiceDate serviceDate : serviceDates) dates.add(serviceDate.getAsDate());
ModelAndView mv = new ModelAndView("service-id.jsp");
mv.addObject("serviceId", serviceId);
mv.addObject("dates", dates);
return mv;
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method purgeExpiredData.
private boolean purgeExpiredData() {
final ServiceDate today = new ServiceDate();
// Just to be safe...
final ServiceDate previously = today.previous().previous();
if (lastPurgeDate != null && lastPurgeDate.compareTo(previously) > 0) {
return false;
}
LOG.debug("purging expired realtime data");
lastPurgeDate = previously;
return buffer.purgeExpiredData(previously);
}
use of org.onebusaway.gtfs.model.calendar.ServiceDate in project OpenTripPlanner by opentripplanner.
the class TimetableSnapshotSource method applyTripUpdates.
/**
* Method to apply a trip update list to the most recent version of the timetable snapshot. A
* GTFS-RT feed is always applied against a single static feed (indicated by feedId).
*<<<<<<< HEAD
*
*=======
*
* However, multi-feed support is not completed and we currently assume there is only one static
* feed when matching IDs.
*
*>>>>>>> 7296be8ffd532a13afb0bec263a9f436ab787022
* @param graph graph to update (needed for adding/changing stop patterns)
* @param fullDataset true iff the list with updates represent all updates that are active right
* now, i.e. all previous updates should be disregarded
* @param updates GTFS-RT TripUpdate's that should be applied atomically
* @param feedId
*/
public void applyTripUpdates(final Graph graph, final boolean fullDataset, final List<TripUpdate> updates, final String feedId) {
if (updates == null) {
LOG.warn("updates is null");
return;
}
// Acquire lock on buffer
bufferLock.lock();
try {
if (fullDataset) {
// Remove all updates from the buffer
buffer.clear(feedId);
}
LOG.debug("message contains {} trip updates", updates.size());
int uIndex = 0;
for (TripUpdate tripUpdate : updates) {
if (fuzzyTripMatcher != null && tripUpdate.hasTrip()) {
final TripDescriptor trip = fuzzyTripMatcher.match(feedId, tripUpdate.getTrip());
tripUpdate = tripUpdate.toBuilder().setTrip(trip).build();
}
if (!tripUpdate.hasTrip()) {
LOG.warn("Missing TripDescriptor in gtfs-rt trip update: \n{}", tripUpdate);
continue;
}
ServiceDate serviceDate = new ServiceDate();
final TripDescriptor tripDescriptor = tripUpdate.getTrip();
if (tripDescriptor.hasStartDate()) {
try {
serviceDate = ServiceDate.parseString(tripDescriptor.getStartDate());
} catch (final ParseException e) {
LOG.warn("Failed to parse start date in gtfs-rt trip update: \n{}", tripUpdate);
continue;
}
} else {
// TODO: figure out the correct service date. For the special case that a trip
// starts for example at 40:00, yesterday would probably be a better guess.
}
uIndex += 1;
LOG.debug("trip update #{} ({} updates) :", uIndex, tripUpdate.getStopTimeUpdateCount());
LOG.trace("{}", tripUpdate);
// Determine what kind of trip update this is
boolean applied = false;
final TripDescriptor.ScheduleRelationship tripScheduleRelationship = determineTripScheduleRelationship(tripUpdate);
switch(tripScheduleRelationship) {
case SCHEDULED:
applied = handleScheduledTrip(tripUpdate, feedId, serviceDate);
break;
case ADDED:
applied = validateAndHandleAddedTrip(graph, tripUpdate, feedId, serviceDate);
break;
case UNSCHEDULED:
applied = handleUnscheduledTrip(tripUpdate, feedId, serviceDate);
break;
case CANCELED:
applied = handleCanceledTrip(tripUpdate, feedId, serviceDate);
break;
case MODIFIED:
applied = validateAndHandleModifiedTrip(graph, tripUpdate, feedId, serviceDate);
break;
}
if (applied) {
appliedBlockCount++;
} else {
LOG.warn("Failed to apply TripUpdate.");
LOG.trace(" Contents: {}", tripUpdate);
}
if (appliedBlockCount % logFrequency == 0) {
LOG.info("Applied {} trip updates.", appliedBlockCount);
}
}
LOG.debug("end of update message");
// Make sure that the public (locking) getTimetableSnapshot function is not called.
if (purgeExpiredData) {
final boolean modified = purgeExpiredData();
getTimetableSnapshot(modified);
} else {
getTimetableSnapshot(false);
}
} finally {
// Always release lock
bufferLock.unlock();
}
}
Aggregations