use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class StopScheduleBeanServiceImpl method groupStopTimeInstancesByRouteCollectionId.
private void groupStopTimeInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
Map<AgencyAndId, Set<FrequencyEntry>> frequencyLabelsByRouteCollectionId = new FactoryMap<AgencyAndId, Set<FrequencyEntry>>(new HashSet<FrequencyEntry>());
for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) {
ServiceIdActivation serviceIds = index.getServiceIds();
Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
if (!serviceDates.contains(date))
continue;
Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
for (BlockStopTimeEntry stopTime : index.getStopTimes()) {
BlockTripEntry blockTrip = stopTime.getTrip();
TripEntry trip = blockTrip.getTrip();
AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
FrequencyEntry frequencyLabel = trip.getFrequencyLabel();
InstanceState state = new InstanceState(serviceDate.getTime(), frequencyLabel);
StopTimeInstance sti = new StopTimeInstance(stopTime, state);
if (frequencyLabel == null) {
stopTimesByRouteCollectionId.get(routeCollectionId).add(sti);
} else if (frequencyLabelsByRouteCollectionId.get(routeCollectionId).add(frequencyLabel)) {
frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
}
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class TripStatusBeanServiceImpl method getTripEntryAndBlockLocationAsTripDetails.
private TripDetailsBean getTripEntryAndBlockLocationAsTripDetails(BlockTripInstance blockTripInstance, BlockLocation blockLocation, TripDetailsInclusionBean inclusion, long time) {
TripBean trip = null;
long serviceDate = blockTripInstance.getServiceDate();
FrequencyBean frequency = null;
TripStopTimesBean stopTimes = null;
TripStatusBean status = null;
AgencyAndId vehicleId = null;
boolean missing = false;
FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
frequency = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
}
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripEntry tripEntry = blockTrip.getTrip();
if (inclusion.isIncludeTripBean()) {
trip = _tripBeanService.getTripForId(tripEntry.getId());
if (trip == null)
missing = true;
}
if (inclusion.isIncludeTripSchedule()) {
stopTimes = _tripStopTimesBeanService.getStopTimesForBlockTrip(blockTripInstance);
if (stopTimes == null)
missing = true;
}
if (inclusion.isIncludeTripStatus() && blockLocation != null) {
status = getBlockLocationAsStatusBean(blockLocation, time);
if (status == null)
missing = true;
else
vehicleId = AgencyAndIdLibrary.convertFromString(status.getVehicleId());
}
List<ServiceAlertBean> situations = _serviceAlertBeanService.getServiceAlertsForVehicleJourney(time, blockTripInstance, vehicleId);
if (missing)
return null;
String tripId = AgencyAndIdLibrary.convertToString(tripEntry.getId());
TripDetailsBean bean = new TripDetailsBean();
bean.setTripId(tripId);
bean.setServiceDate(serviceDate);
bean.setFrequency(frequency);
bean.setTrip(trip);
bean.setSchedule(stopTimes);
bean.setStatus(status);
bean.setSituations(situations);
return bean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class TripStopTimesBeanServiceImpl method getStopTimesForBlockTrip.
@Override
public TripStopTimesBean getStopTimesForBlockTrip(BlockTripInstance blockTripInstance) {
BlockTripEntry blockTrip = blockTripInstance.getBlockTrip();
TripStopTimesBean bean = getStopTimesForTrip(blockTrip.getTrip());
if (blockTrip.getPreviousTrip() != null) {
BlockTripEntry previous = blockTrip.getPreviousTrip();
TripBean previousTrip = _tripBeanService.getTripForId(previous.getTrip().getId());
bean.setPreviousTrip(previousTrip);
}
if (blockTrip.getNextTrip() != null) {
BlockTripEntry next = blockTrip.getNextTrip();
TripBean nextTrip = _tripBeanService.getTripForId(next.getTrip().getId());
bean.setNextTrip(nextTrip);
}
FrequencyEntry frequencyLabel = blockTripInstance.getFrequencyLabel();
if (frequencyLabel != null) {
long serviceDate = blockTripInstance.getServiceDate();
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(serviceDate, frequencyLabel);
bean.setFrequency(fb);
}
return bean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method findBlockTripsInRange.
private void findBlockTripsInRange(ServiceIntervalBlock intervals, Date serviceDate, Date timeFrom, Date timeTo, List<BlockTripEntry> trips, Collection<BlockInstance> instances) {
int scheduledTimeFrom = (int) ((timeFrom.getTime() - serviceDate.getTime()) / 1000);
int scheduledTimeTo = (int) ((timeTo.getTime() - serviceDate.getTime()) / 1000);
int indexFrom = index(Arrays.binarySearch(intervals.getMaxDepartures(), scheduledTimeFrom));
int indexTo = index(Arrays.binarySearch(intervals.getMinArrivals(), scheduledTimeTo));
InstanceState state = new InstanceState(serviceDate.getTime());
for (int in = indexFrom; in < indexTo; in++) {
BlockTripEntry trip = trips.get(in);
BlockConfigurationEntry block = trip.getBlockConfiguration();
BlockInstance instance = new BlockInstance(block, state);
instances.add(instance);
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockCalendarServiceImpl method handleBlockIndex.
private Collection<BlockInstance> handleBlockIndex(BlockTripIndex index, Date timeFrom, Date timeTo, Collection<BlockInstance> instances) {
List<BlockTripEntry> trips = index.getTrips();
ServiceIntervalBlock serviceIntervalBlock = index.getServiceIntervalBlock();
ServiceInterval serviceInterval = serviceIntervalBlock.getRange();
Collection<Date> serviceDates = _calendarService.getServiceDatesWithinRange(index.getServiceIds(), serviceInterval, timeFrom, timeTo);
for (Date serviceDate : serviceDates) {
findBlockTripsInRange(serviceIntervalBlock, serviceDate, timeFrom, timeTo, trips, instances);
}
return instances;
}
Aggregations