use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImpl method isLastPrediction.
/**
* @param stopTime is the current stop
* @param timepointPredictions is the all time-point predictions in the block
* @param timepointPredictionRecord is the current tpr for the stop
* @param index is the index of the current tpr in timepointPredictions
* @return return true if the given tpr is the last prediction for the trip
*/
private boolean isLastPrediction(StopTimeEntry stopTime, List<TimepointPredictionRecord> timepointPredictions, TimepointPredictionRecord timepointPredictionRecord, int index) {
List<StopTimeEntry> stopTimes = stopTime.getTrip().getStopTimes();
AgencyAndId lastStopId = stopTimes.get(stopTimes.size() - 1).getStop().getId();
if (lastStopId.equals(timepointPredictionRecord.getTimepointId()) && stopTime.getTrip().getId().equals(timepointPredictionRecord.getTripId())) {
return index + 1 == timepointPredictions.size() || (index < timepointPredictions.size() && !timepointPredictions.get(index + 1).getTripId().equals(timepointPredictionRecord.getTripId()));
}
return false;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImpl method isFirstOrLastStopInTrip.
/**
* @param stopTime
* @return true if the given stop is the first or the last stop in given trip
*/
private boolean isFirstOrLastStopInTrip(StopTimeEntry stopTime) {
List<StopTimeEntry> stopTimes = stopTime.getTrip().getStopTimes();
AgencyAndId firstStopId = stopTimes.get(0).getStop().getId();
AgencyAndId lastStopId = stopTimes.get(stopTimes.size() - 1).getStop().getId();
AgencyAndId currentStopId = stopTime.getStop().getId();
return firstStopId.equals(currentStopId) || lastStopId.equals(currentStopId);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ScheduledBlockLocationServiceImpl method getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex.
/**
**
* Private Methods
***
*/
private ScheduledBlockLocation getScheduledBlockLocationFromDistanceAlongBlockAndStopTimeIndex(List<BlockStopTimeEntry> stopTimes, double distanceAlongBlock, int stopTimeIndex) {
int n = stopTimes.size();
// Are we out beyond our last stop-time?
if (stopTimeIndex == n) {
// If we only have one stop time, we can't interpolate the schedule time
if (n == 1)
return null;
BlockStopTimeEntry blockFrom = stopTimes.get(n - 2);
BlockStopTimeEntry blockTo = stopTimes.get(n - 1);
if (n == 2)
return interpolateLocation(blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
BlockStopTimeEntry previousBlock = stopTimes.get(n - 3);
return interpolateLocation(previousBlock, blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
}
// Are we before out first stop-time?
if (stopTimeIndex == 0) {
// If we only have one stop time, we can't interpolate the schedule time
if (n == 1)
return null;
BlockStopTimeEntry blockFrom = stopTimes.get(0);
BlockStopTimeEntry blockTo = stopTimes.get(1);
return interpolateLocation(blockFrom, blockTo, distanceAlongBlock, stopTimeIndex);
}
BlockStopTimeEntry blockBefore = stopTimes.get(stopTimeIndex - 1);
BlockStopTimeEntry blockAfter = stopTimes.get(stopTimeIndex);
StopTimeEntry before = blockBefore.getStopTime();
StopTimeEntry after = blockAfter.getStopTime();
double ratio = (distanceAlongBlock - blockBefore.getDistanceAlongBlock()) / (blockAfter.getDistanceAlongBlock() - blockBefore.getDistanceAlongBlock());
int scheduleTime = (int) (before.getDepartureTime() + (after.getArrivalTime() - before.getDepartureTime()) * ratio);
return getScheduledBlockLocationFromScheduleTimeAndStopTimeIndex(stopTimes, scheduleTime, stopTimeIndex);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry 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.StopTimeEntry 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);
}
Aggregations