use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImpl method getBlockTripsForIndicesMatchingRouteCollection.
/**
* A block index potentially includes trips with different routes. We only
* want the trips matching our route collection.
*
* @param <T>
* @param blockIndices
* @param routeCollectionId
* @param resultingTrips
*/
private <T extends AbstractBlockTripIndex> void getBlockTripsForIndicesMatchingRouteCollection(List<T> blockIndices, AgencyAndId routeCollectionId, List<BlockTripEntry> resultingTrips) {
for (AbstractBlockTripIndex blockIndex : blockIndices) {
for (BlockTripEntry blockTrip : blockIndex.getTrips()) {
TripEntry trip = blockTrip.getTrip();
AgencyAndId rcId = trip.getRouteCollection().getId();
if (!rcId.equals(routeCollectionId))
continue;
resultingTrips.add(blockTrip);
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImpl method getShapeIdsForStopSequenceBlock.
private Set<AgencyAndId> getShapeIdsForStopSequenceBlock(StopSequenceCollection block) {
Set<AgencyAndId> shapeIds = new HashSet<AgencyAndId>();
for (StopSequence sequence : block.getStopSequences()) {
for (BlockTripEntry blockTrip : sequence.getTrips()) {
TripEntry trip = blockTrip.getTrip();
AgencyAndId shapeId = trip.getShapeId();
if (shapeId != null && shapeId.hasValues())
shapeIds.add(shapeId);
}
}
return shapeIds;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class StopSequenceCollectionServiceImpl method constructCollections.
/**
* @param route
* @param sequenceStats
* @param sequencesByGroupId
* @return
*/
private List<StopSequenceCollection> constructCollections(Map<StopSequence, PatternStats> sequenceStats, Map<String, List<StopSequence>> sequencesByGroupId) {
computeContinuations(sequenceStats, sequencesByGroupId);
Set<String> allNames = new HashSet<String>();
Map<String, String> directionToName = new HashMap<String, String>();
Map<String, Segment> segments = new HashMap<String, Segment>();
for (Map.Entry<String, List<StopSequence>> entry : sequencesByGroupId.entrySet()) {
String direction = entry.getKey();
List<StopSequence> sequences = entry.getValue();
Max<StopSequence> maxTripCount = new Max<StopSequence>();
Counter<String> names = new Counter<String>();
for (StopSequence sequence : sequences) {
maxTripCount.add(sequence.getTripCount(), sequence);
for (BlockTripEntry blockTrip : sequence.getTrips()) {
TripEntry trip = blockTrip.getTrip();
TripNarrative tripNarrative = _narrativeService.getTripForId(trip.getId());
String headsign = tripNarrative.getTripHeadsign();
if (headsign != null && headsign.length() > 0)
names.increment(headsign);
}
}
String dName = names.getMax();
RecursiveStats rs = new RecursiveStats();
rs.maxTripCount = (long) maxTripCount.getMaxValue();
exploreStopSequences(rs, sequenceStats, sequences, "");
allNames.add(dName);
directionToName.put(direction, dName);
segments.put(direction, rs.longestSegment.getMaxElement());
}
if (allNames.size() < directionToName.size()) {
for (Map.Entry<String, String> entry : directionToName.entrySet()) {
String direction = entry.getKey();
String name = entry.getValue();
direction = direction.charAt(0) + direction.substring(1).toLowerCase();
entry.setValue(name + " - " + direction);
}
}
List<StopSequenceCollection> blocks = new ArrayList<StopSequenceCollection>();
for (Map.Entry<String, String> entry : directionToName.entrySet()) {
String direction = entry.getKey();
String name = entry.getValue();
List<StopSequence> patterns = sequencesByGroupId.get(direction);
Segment segment = segments.get(direction);
// System.out.println(" " + direction + " => " + name);
StopSequenceCollection block = new StopSequenceCollection();
if (segment.fromLat == 0.0)
throw new IllegalStateException("what?");
StopSequenceCollectionKey key = new StopSequenceCollectionKey(null, direction);
block.setId(key);
block.setPublicId(direction);
block.setDescription(name);
block.setStopSequences(patterns);
block.setStartLat(segment.fromLat);
block.setStartLon(segment.fromLon);
block.setEndLat(segment.toLat);
block.setEndLon(segment.toLon);
blocks.add(block);
}
return blocks;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method getStopTimeInstanceAsBean.
/**
**
* Private Methods
***
*/
private ArrivalAndDepartureBean getStopTimeInstanceAsBean(long time, ArrivalAndDepartureInstance instance, Map<AgencyAndId, StopBean> stopBeanCache) {
ArrivalAndDepartureBean pab = new ArrivalAndDepartureBean();
pab.setServiceDate(instance.getServiceDate());
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
BlockTripEntry blockTrip = blockStopTime.getTrip();
StopTimeEntry stopTime = blockStopTime.getStopTime();
StopEntry stop = stopTime.getStop();
TripEntry trip = stopTime.getTrip();
TripBean tripBean = _tripBeanService.getTripForId(trip.getId());
pab.setTrip(tripBean);
pab.setBlockTripSequence(blockTrip.getSequence());
pab.setArrivalEnabled(stopTime.getSequence() > 0);
pab.setDepartureEnabled(stopTime.getSequence() + 1 < trip.getStopTimes().size());
StopTimeNarrative stopTimeNarrative = _narrativeService.getStopTimeForEntry(stopTime);
pab.setRouteShortName(stopTimeNarrative.getRouteShortName());
pab.setTripHeadsign(stopTimeNarrative.getStopHeadsign());
StopBean stopBean = stopBeanCache.get(stop.getId());
if (stopBean == null) {
stopBean = _stopBeanService.getStopForId(stop.getId());
stopBeanCache.put(stop.getId(), stopBean);
}
pab.setStop(stopBean);
pab.setStopSequence(stopTime.getSequence());
pab.setTotalStopsInTrip(stopTime.getTotalStopsInTrip());
pab.setStatus("default");
pab.setScheduledArrivalTime(instance.getScheduledArrivalTime());
pab.setScheduledDepartureTime(instance.getScheduledDepartureTime());
FrequencyEntry frequency = instance.getFrequencyLabel();
pab.setFrequency(null);
if (frequency != null) {
FrequencyBean fb = FrequencyBeanLibrary.getBeanForFrequency(instance.getServiceDate(), frequency);
pab.setFrequency(fb);
}
return pab;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.TripEntry 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());
}
}
}
Aggregations