use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.
the class StopSequenceCollectionServiceImpl method exploreStopSequences.
private void exploreStopSequences(RecursiveStats rs, Map<StopSequence, PatternStats> patternStats, Iterable<StopSequence> patterns, String depth) {
Segment prevSegment = rs.prevSegment;
for (StopSequence pattern : patterns) {
if (rs.visited.contains(pattern))
continue;
PatternStats stats = patternStats.get(pattern);
double count = stats.tripCounts;
double ratio = count / rs.maxTripCount;
if (ratio < SERVICE_PATTERN_TRIP_COUNT_RATIO_MIN)
continue;
Segment segment = stats.segment;
if (prevSegment != null)
segment = new Segment(prevSegment, segment, prevSegment.distance + segment.distance);
rs.longestSegment.add(segment.distance, segment);
Set<StopSequence> nextPatterns = stats.continuations;
if (!nextPatterns.isEmpty()) {
rs.visited.add(pattern);
rs.prevSegment = segment;
exploreStopSequences(rs, patternStats, nextPatterns, depth + " ");
rs.visited.remove(pattern);
}
}
}
use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.
the class StopSequenceCollectionServiceImpl method getStatsForStopSequences.
/**
* Computes some general statistics for each {@link StopSequence} in a
* collection, including the number of trips taking that stop sequence, the
* set of regions for the destination of the stop sequence
*
* @param sequences
* @return the computed statistics
*/
private Map<StopSequence, PatternStats> getStatsForStopSequences(List<StopSequence> sequences) {
Map<StopSequence, PatternStats> patternStats = new HashMap<StopSequence, PatternStats>();
for (StopSequence sequence : sequences) {
PatternStats stats = new PatternStats();
stats.tripCounts = sequence.getTripCount();
stats.segment = getSegmentForStopSequence(sequence);
patternStats.put(sequence, stats);
}
return patternStats;
}
use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.
the class StopSequenceCollectionServiceImpl method groupStopSequencesByNotDirectionIds.
private Map<String, List<StopSequence>> groupStopSequencesByNotDirectionIds(Iterable<StopSequence> sequences) {
TreeUnionFind<StopSequence> unionFind = new TreeUnionFind<StopSequence>();
for (StopSequence stopSequenceA : sequences) {
unionFind.find(stopSequenceA);
for (StopSequence stopSequenceB : sequences) {
if (stopSequenceA == stopSequenceB)
continue;
double ratio = getMaxCommonStopSequenceRatio(stopSequenceA, stopSequenceB);
if (ratio >= STOP_SEQUENCE_MIN_COMMON_RATIO)
unionFind.union(stopSequenceA, stopSequenceB);
}
}
Map<String, List<StopSequence>> results = new HashMap<String, List<StopSequence>>();
int index = 0;
for (Set<StopSequence> sequencesByDirection : unionFind.getSetMembers()) {
String key = Integer.toString(index);
List<StopSequence> asList = new ArrayList<StopSequence>(sequencesByDirection);
results.put(key, asList);
index++;
}
return results;
}
use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.
the class StopSequencesServiceImpl method getStopSequencesForTrips.
@Override
public List<StopSequence> getStopSequencesForTrips(List<BlockTripEntry> trips) {
Map<StopSequenceKey, List<BlockTripEntry>> tripsByStopSequenceKey = new FactoryMap<StopSequenceKey, List<BlockTripEntry>>(new ArrayList<BlockTripEntry>());
for (BlockTripEntry blockTrip : trips) {
TripEntry trip = blockTrip.getTrip();
String directionId = trip.getDirectionId();
if (directionId == null)
directionId = NO_DIRECTION_ID;
AgencyAndId shapeId = trip.getShapeId();
if (shapeId == null || !shapeId.hasValues())
shapeId = NO_SHAPE_ID;
List<StopEntry> stops = getStopTimesAsStops(trip.getStopTimes());
StopSequenceKey key = new StopSequenceKey(stops, directionId, shapeId);
tripsByStopSequenceKey.get(key).add(blockTrip);
}
List<StopSequence> sequences = new ArrayList<StopSequence>();
for (Map.Entry<StopSequenceKey, List<BlockTripEntry>> entry : tripsByStopSequenceKey.entrySet()) {
StopSequenceKey key = entry.getKey();
StopSequence ss = new StopSequence();
ss.setId(sequences.size());
ss.setRoute(null);
ss.setStops(key.getStops());
if (!key.getDirectionId().equals(NO_DIRECTION_ID))
ss.setDirectionId(key.getDirectionId());
if (!key.getShapeId().equals(NO_SHAPE_ID))
ss.setShapeId(key.getShapeId());
ss.setTrips(entry.getValue());
ss.setTripCount(entry.getValue().size());
sequences.add(ss);
}
return sequences;
}
use of org.onebusaway.transit_data_federation.model.StopSequence in project onebusaway-application-modules by camsys.
the class RouteBeanServiceImpl method getStopsForRouteCollectionAndNarrative.
private StopsForRouteBean getStopsForRouteCollectionAndNarrative(RouteCollectionEntry routeCollection, RouteCollectionNarrative narrative) {
StopsForRouteBean result = new StopsForRouteBean();
AgencyAndId routeCollectionId = routeCollection.getId();
result.setRoute(getRouteBeanForRouteCollection(routeCollectionId, narrative));
result.setStops(getStopBeansForRoute(routeCollectionId));
result.setPolylines(getEncodedPolylinesForRoute(routeCollection));
StopGroupingBean directionGrouping = new StopGroupingBean();
directionGrouping.setType(TransitDataConstants.STOP_GROUPING_TYPE_DIRECTION);
List<StopGroupBean> directionGroups = new ArrayList<StopGroupBean>();
directionGrouping.setStopGroups(directionGroups);
directionGrouping.setOrdered(true);
result.addGrouping(directionGrouping);
List<BlockTripIndex> blockIndices = _blockIndexService.getBlockTripIndicesForRouteCollectionId(routeCollectionId);
List<FrequencyBlockTripIndex> frequencyBlockIndices = _blockIndexService.getFrequencyBlockTripIndicesForRouteCollectionId(routeCollectionId);
List<BlockTripEntry> blockTrips = new ArrayList<BlockTripEntry>();
getBlockTripsForIndicesMatchingRouteCollection(blockIndices, routeCollectionId, blockTrips);
getBlockTripsForIndicesMatchingRouteCollection(frequencyBlockIndices, routeCollectionId, blockTrips);
List<StopSequence> sequences = _stopSequencesService.getStopSequencesForTrips(blockTrips);
List<StopSequenceCollection> blocks = _stopSequenceBlocksService.getStopSequencesAsCollections(sequences);
for (StopSequenceCollection block : blocks) {
NameBean name = new NameBean(NameBeanTypes.DESTINATION, block.getDescription());
List<StopEntry> stops = getStopsInOrder(block);
List<String> groupStopIds = new ArrayList<String>();
for (StopEntry stop : stops) groupStopIds.add(ApplicationBeanLibrary.getId(stop.getId()));
Set<AgencyAndId> shapeIds = getShapeIdsForStopSequenceBlock(block);
List<EncodedPolylineBean> polylines = _shapeBeanService.getMergedPolylinesForShapeIds(shapeIds);
StopGroupBean group = new StopGroupBean();
group.setId(block.getPublicId());
group.setName(name);
group.setStopIds(groupStopIds);
group.setPolylines(polylines);
directionGroups.add(group);
}
sortResult(result);
return result;
}
Aggregations