use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationBeforeStartOfBlock.
private ScheduledBlockLocation getScheduledBlockLocationBeforeStartOfBlock(List<BlockStopTimeEntry> stopTimes, int scheduleTime) {
/**
* The first block stop time
*/
BlockStopTimeEntry blockStopTime = stopTimes.get(0);
StopTimeEntry stopTime = blockStopTime.getStopTime();
double distanceAlongBlock = Double.NaN;
boolean inService = false;
/**
* If we have more than one stop time in the block (we'd hope!), then we
* attempt to interpolate the distance along the block
*/
if (stopTimes.size() > 1) {
BlockStopTimeEntry secondBlockStopTime = stopTimes.get(1);
StopTimeEntry secondStopTime = secondBlockStopTime.getStopTime();
distanceAlongBlock = InterpolationLibrary.interpolatePair(stopTime.getDepartureTime(), blockStopTime.getDistanceAlongBlock(), secondStopTime.getArrivalTime(), secondBlockStopTime.getDistanceAlongBlock(), scheduleTime);
if (distanceAlongBlock >= 0)
inService = true;
else
distanceAlongBlock = 0.0;
}
PointAndOrientation po = null;
if (!Double.isNaN(distanceAlongBlock))
po = getLocationAlongShape(blockStopTime.getTrip(), distanceAlongBlock, 0, nextShapePointIndex(stopTime));
ScheduledBlockLocation result = new ScheduledBlockLocation();
if (po != null) {
result.setLocation(po.getPoint());
result.setOrientation(po.getOrientation());
}
result.setClosestStop(blockStopTime);
result.setClosestStopTimeOffset(stopTime.getArrivalTime() - scheduleTime);
result.setPreviousStop(null);
result.setNextStop(blockStopTime);
result.setNextStopTimeOffset(stopTime.getArrivalTime() - scheduleTime);
result.setScheduledTime(scheduleTime);
result.setDistanceAlongBlock(distanceAlongBlock);
result.setActiveTrip(blockStopTime.getTrip());
result.setInService(inService);
result.setStopTimeIndex(0);
return result;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method computeDirectionOfTravel.
private double computeDirectionOfTravel(List<BlockStopTimeEntry> bsts) {
BlockStopTimeEntry fromBst = bsts.get(0);
BlockStopTimeEntry toBst = bsts.get(bsts.size() - 1);
StopEntry fromStop = fromBst.getStopTime().getStop();
StopEntry toStop = toBst.getStopTime().getStop();
return SphericalGeometryLibrary.getOrientation(fromStop.getStopLat(), fromStop.getStopLon(), toStop.getStopLat(), toStop.getStopLon());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method getBlockStopTimesAsBlockInterval.
/**
**
*
***
*/
private <T extends HasBlockStopTimes> ServiceIntervalBlock getBlockStopTimesAsBlockInterval(List<T> entries) {
int n = entries.size();
int[] minArrivals = new int[n];
int[] minDepartures = new int[n];
int[] maxArrivals = new int[n];
int[] maxDepartures = new int[n];
int index = 0;
for (T entry : entries) {
ServiceInterval interval = null;
List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
StopTimeEntry first = stopTimes.get(0).getStopTime();
StopTimeEntry last = stopTimes.get(stopTimes.size() - 1).getStopTime();
interval = extend(interval, first);
interval = extend(interval, last);
minArrivals[index] = interval.getMinArrival();
minDepartures[index] = interval.getMinDeparture();
maxArrivals[index] = interval.getMaxArrival();
maxDepartures[index] = interval.getMaxDeparture();
index++;
}
return new ServiceIntervalBlock(minArrivals, minDepartures, maxArrivals, maxDepartures);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockIndexFactoryServiceImpl method areBlockTripsContinuous.
private boolean areBlockTripsContinuous(BlockTripEntry prevBlockTrip, BlockTripEntry nextBlockTrip) {
List<BlockStopTimeEntry> prevStopTimes = prevBlockTrip.getStopTimes();
List<BlockStopTimeEntry> nextStopTimes = nextBlockTrip.getStopTimes();
BlockStopTimeEntry from = prevStopTimes.get(prevStopTimes.size() - 1);
BlockStopTimeEntry to = nextStopTimes.get(0);
int slack = to.getAccumulatedSlackTime() - (from.getAccumulatedSlackTime() + from.getStopTime().getSlackTime());
int schedTime = to.getStopTime().getArrivalTime() - from.getStopTime().getDepartureTime();
/**
* If the slack time is too much, the trips are not continuous
*/
if (slack >= _maxSlackBetweenConsecutiveTrips)
return false;
/**
* If the sched time is too much, the trips are not continuous
*/
if (schedTime >= _maxScheduledTimeBetweenConsecutiveTrips)
return false;
TripEntry prevTrip = prevBlockTrip.getTrip();
TripEntry nextTrip = nextBlockTrip.getTrip();
AgencyAndId lineIdA = prevTrip.getRouteCollection().getId();
AgencyAndId lineIdB = nextTrip.getRouteCollection().getId();
String directionA = prevTrip.getDirectionId();
String directionB = nextTrip.getDirectionId();
/**
* If the route has not changed, but the direction has, the trips are not
* continuous
*/
if (lineIdA.equals(lineIdB) && (directionA == null || !directionA.equals(directionB)))
return false;
double prevOrientation = computeDirectionOfTravel(prevStopTimes);
double nextOrientation = computeDirectionOfTravel(nextStopTimes);
double delta = GeometryLibrary.getAngleDifference(prevOrientation, nextOrientation);
return true;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockStopTimeIndicesFactory method createFrequencyBlockStopTimeIndexForGroup.
private FrequencyBlockStopTimeIndex createFrequencyBlockStopTimeIndexForGroup(List<FrequencyBlockStopTimeEntry> group) {
int n = group.size();
List<FrequencyEntry> frequencies = new ArrayList<FrequencyEntry>(n);
List<BlockConfigurationEntry> blockConfigs = new ArrayList<BlockConfigurationEntry>(n);
int[] stopIndices = new int[n];
ServiceInterval interval = null;
for (int i = 0; i < n; i++) {
FrequencyBlockStopTimeEntry frequencyBlockStopTime = group.get(i);
FrequencyEntry frequency = frequencyBlockStopTime.getFrequency();
frequencies.add(frequency);
BlockStopTimeEntry blockStopTime = frequencyBlockStopTime.getStopTime();
blockConfigs.add(blockStopTime.getTrip().getBlockConfiguration());
stopIndices[i] = blockStopTime.getBlockSequence();
interval = ServiceInterval.extend(interval, frequency.getStartTime(), frequency.getStartTime());
interval = ServiceInterval.extend(interval, frequency.getEndTime(), frequency.getEndTime());
}
return new FrequencyBlockStopTimeIndex(frequencies, blockConfigs, stopIndices, interval);
}
Aggregations