use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry 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.BlockTripEntry 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.BlockTripEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromScheduledTime.
@Override
public ScheduledBlockLocation getScheduledBlockLocationFromScheduledTime(ScheduledBlockLocation previousLocation, int scheduleTime) {
if (previousLocation.getScheduledTime() > scheduleTime)
throw new IllegalStateException("previousLocation's scheduledTime must be before the requested scheduleTime");
BlockTripEntry trip = previousLocation.getActiveTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = previousLocation.getStopTimeIndex();
while (index < stopTimes.size()) {
int t = blockConfig.getDepartureTimeForIndex(index);
if (scheduleTime <= t)
break;
index++;
}
return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, index);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getLocationAlongShape.
private PointAndOrientation getLocationAlongShape(BlockTripEntry activeBlockTrip, double distanceAlongBlock, int shapePointIndexFrom, int shapePointIndexTo) {
TripEntry activeTrip = activeBlockTrip.getTrip();
AgencyAndId shapeId = activeTrip.getShapeId();
if (shapeId == null)
return null;
ShapePoints shapePoints = _shapePointService.getShapePointsForShapeId(shapeId);
if (shapePoints == null || shapePoints.isEmpty())
return null;
/**
* We allow callers of this method to specify an arbitrarily high
* shapePointIndexTo, knowing we'll bound it by the max number of points
*/
shapePointIndexFrom = Math.min(shapePointIndexFrom, shapePoints.getSize());
shapePointIndexTo = Math.min(shapePointIndexTo, shapePoints.getSize());
double distanceAlongTrip = distanceAlongBlock - activeBlockTrip.getDistanceAlongBlock();
ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(distanceAlongTrip, shapePointIndexFrom, shapePointIndexTo);
return shapePointIndexMethod.getPointAndOrientation(shapePoints);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method ensureFrequencyTripGroups.
private List<FrequencyTripGroup> ensureFrequencyTripGroups(List<BlockTripEntry> tripsWithSameSequence) {
List<BlockTripWithFrequency> btwfs = new ArrayList<BlockTripWithFrequency>();
for (BlockTripEntry trip : tripsWithSameSequence) {
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
for (FrequencyEntry frequency : blockConfig.getFrequencies()) btwfs.add(new BlockTripWithFrequency(trip, frequency));
}
Collections.sort(btwfs);
List<FrequencyTripGroup> lists = new ArrayList<FrequencyTripGroup>();
for (BlockTripWithFrequency btwf : btwfs) {
FrequencyTripGroup group = getBestFrequencyTripGroup(lists, btwf);
if (group == null) {
group = new FrequencyTripGroup();
lists.add(group);
}
group.addEntry(btwf);
}
return lists;
}
Aggregations