use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class TripBeanServiceImpl method getTripForId.
@Cacheable
public TripBean getTripForId(AgencyAndId tripId) {
TripEntry tripEntry = _graph.getTripEntryForId(tripId);
if (tripEntry == null)
return null;
AgencyAndId routeId = tripEntry.getRouteCollection().getId();
RouteBean routeBean = _routeBeanService.getRouteForId(routeId);
TripNarrative tripNarrative = _narrativeService.getTripForId(tripId);
TripBean tripBean = new TripBean();
tripBean.setId(ApplicationBeanLibrary.getId(tripId));
tripBean.setTripShortName(tripNarrative.getTripShortName());
tripBean.setTripHeadsign(tripNarrative.getTripHeadsign());
tripBean.setRoute(routeBean);
tripBean.setRouteShortName(tripNarrative.getRouteShortName());
tripBean.setServiceId(ApplicationBeanLibrary.getId(tripEntry.getServiceId().getId()));
AgencyAndId shapeId = tripEntry.getShapeId();
if (shapeId != null && shapeId.hasValues())
tripBean.setShapeId(ApplicationBeanLibrary.getId(shapeId));
tripBean.setDirectionId(tripEntry.getDirectionId());
tripBean.setTotalTripDistance(tripEntry.getTotalTripDistance());
BlockEntry block = tripEntry.getBlock();
tripBean.setBlockId(ApplicationBeanLibrary.getId(block.getId()));
return tripBean;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibrary method getTripDescriptorAsBlockDescriptor.
private BlockDescriptor getTripDescriptorAsBlockDescriptor(MonitoredResult result, TripDescriptor trip, long currentTime) {
if (!trip.hasTripId()) {
return null;
}
TripEntry tripEntry = _entitySource.getTrip(trip.getTripId());
if (tripEntry == null) {
if (result != null) {
_log.debug("reporting unmatched trip with id=" + trip.getTripId());
result.addUnmatchedTripId(trip.getTripId());
} else {
_log.warn("no trip found with id=" + trip.getTripId());
}
return null;
}
ServiceDate serviceDate = null;
BlockInstance instance;
BlockEntry block = tripEntry.getBlock();
if (trip.hasStartDate() && !"0".equals(trip.getStartDate())) {
try {
serviceDate = ServiceDate.parseString(trip.getStartDate());
} catch (ParseException ex) {
_log.warn("Could not parse service date " + trip.getStartDate(), ex);
}
}
if (serviceDate != null) {
instance = _blockCalendarService.getBlockInstance(block.getId(), serviceDate.getAsDate().getTime());
if (instance == null) {
_log.warn("block " + block.getId() + " does not exist on service date " + serviceDate);
return null;
}
} else {
long timeFrom = currentTime - 30 * 60 * 1000;
long timeTo = currentTime + 30 * 60 * 1000;
List<BlockInstance> instances = _blockCalendarService.getActiveBlocks(block.getId(), timeFrom, timeTo);
if (instances.isEmpty()) {
instances = _blockCalendarService.getClosestActiveBlocks(block.getId(), currentTime);
}
if (instances.isEmpty()) {
_log.warn("could not find any active instances for the specified block=" + block.getId() + " trip=" + trip);
return null;
}
instance = instances.get(0);
}
if (serviceDate == null) {
serviceDate = new ServiceDate(new Date(instance.getServiceDate()));
}
BlockDescriptor blockDescriptor = new BlockDescriptor();
blockDescriptor.setBlockInstance(instance);
blockDescriptor.setStartDate(serviceDate);
if (trip.hasScheduleRelationship()) {
blockDescriptor.setScheduleRelationshipValue(trip.getScheduleRelationship().toString());
}
int tripStartTime = 0;
int blockStartTime = 0;
if (trip.hasStartTime() && !"0".equals(trip.getStartTime())) {
try {
tripStartTime = StopTimeFieldMappingFactory.getStringAsSeconds(trip.getStartTime());
} catch (InvalidStopTimeException iste) {
_log.error("invalid stopTime of " + trip.getStartTime() + " for trip " + trip);
}
blockStartTime = getBlockStartTimeForTripStartTime(instance, tripEntry.getId(), tripStartTime);
blockDescriptor.setStartTime(blockStartTime);
}
return blockDescriptor;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class VehicleStatusServiceImpl method handleVehicleLocationRecord.
/**
**
* {@link VehicleLocationListener} Interface
***
*/
@Override
public void handleVehicleLocationRecord(VehicleLocationRecord record) {
if (record.getPhase() == null) {
// if we've received a report, assume it is in progress/in service
record.setPhase(EVehiclePhase.IN_PROGRESS);
}
if (record.getTimeOfRecord() == 0)
throw new IllegalArgumentException("you must specify a record time");
if (record.getVehicleId() != null)
_vehicleRecordsById.put(record.getVehicleId(), record);
AgencyAndId blockId = record.getBlockId();
if (blockId == null) {
AgencyAndId tripId = record.getTripId();
if (tripId != null) {
TripEntry tripEntry = _transitGraphDao.getTripEntryForId(tripId);
if (tripEntry == null)
throw new IllegalArgumentException("trip not found with id=" + tripId);
BlockEntry block = tripEntry.getBlock();
blockId = block.getId();
}
}
// TODO : Maybe not require service date?
if (blockId != null && record.getServiceDate() != 0)
_blockVehicleLocationService.handleVehicleLocationRecord(record);
else // if vehicle has no block or has lost it, remove it from the block VLS.
{
if (record.getVehicleId() != null) {
_blockVehicleLocationService.resetVehicleLocation(record.getVehicleId());
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method createSequenceIndices.
public List<BlockSequenceIndex> createSequenceIndices(Iterable<BlockEntry> blocks) {
List<BlockSequenceIndex> allIndices = new ArrayList<BlockSequenceIndex>();
Map<BlockSequenceKey, List<BlockSequence>> blockSequencesByKey = new FactoryMap<BlockSequenceKey, List<BlockSequence>>(new ArrayList<BlockSequence>());
if (_verbose)
_log.info("grouping block trips into sequence indices");
int sequenceCount = 0;
int blockTripCount = 0;
for (BlockEntry block : blocks) {
if (block.getConfigurations().isEmpty()) {
_log.warn("block has no active configurations: " + block.getId());
continue;
}
if (BlockLibrary.isFrequencyBased(block))
continue;
for (BlockConfigurationEntry blockConfiguration : block.getConfigurations()) {
blockTripCount += blockConfiguration.getTrips().size();
List<BlockSequence> sequences = groupTrips(blockConfiguration);
for (BlockSequence sequence : sequences) {
BlockSequenceKey key = getBlockSequenceAsSequenceKey(sequence);
blockSequencesByKey.get(key).add(sequence);
sequenceCount++;
}
}
}
if (_verbose)
_log.info("groups found: " + blockSequencesByKey.size() + " out of sequences: " + sequenceCount + " and trips: " + blockTripCount);
for (List<BlockSequence> sequences : blockSequencesByKey.values()) {
List<List<BlockSequence>> groupedBlocks = BlockLibrary.createStrictlyOrderedGroups(sequences, _blockSequenceLooseComparator, _blockSequenceStrictComparator);
for (List<BlockSequence> group : groupedBlocks) {
BlockSequenceIndex index = createSequenceIndexForGroupOfBlockSequences(group);
allIndices.add(index);
}
}
return allIndices;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndicesFactory method groupBlockStopTimes.
/**
**
*
***
*/
private Map<BlockStopTimeKey, List<BlockStopTimeEntry>> groupBlockStopTimes(Iterable<BlockEntry> blocks, boolean frequencyBased) {
Map<BlockStopTimeKey, List<BlockStopTimeEntry>> stopTimesByKey = new FactoryMap<BlockStopTimeKey, List<BlockStopTimeEntry>>(new ArrayList<BlockStopTimeEntry>());
if (_verbose)
_log.info("grouping block stop times by key");
int stopTimeCount = 0;
for (BlockEntry block : blocks) {
List<BlockConfigurationEntry> configurations = block.getConfigurations();
if (configurations.isEmpty()) {
_log.warn("block is not referred to in calendars (no active configurations): " + block.getId());
continue;
}
if (BlockLibrary.isFrequencyBased(block) != frequencyBased)
continue;
for (BlockConfigurationEntry blockConfiguration : configurations) {
List<BlockStopTimeEntry> blockStopTimes = blockConfiguration.getStopTimes();
for (BlockStopTimeEntry blockStopTime : blockStopTimes) {
BlockStopTimeKey key = getBlockStopTimeAsKey(blockStopTime);
List<BlockStopTimeEntry> stopTimesForKey = stopTimesByKey.get(key);
stopTimesForKey.add(blockStopTime);
stopTimeCount++;
}
}
}
if (_verbose)
_log.info("groups found: " + stopTimesByKey.size() + " out of stopTimes: " + stopTimeCount);
return stopTimesByKey;
}
Aggregations