use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method calculateArrivalDeviation.
private int calculateArrivalDeviation(BlockStopTimeEntry nextBlockStopTime, BlockStopTimeEntry targetBlockStopTime, int effectiveScheduleTime, int scheduleDeviation) {
if (nextBlockStopTime == null || nextBlockStopTime.getBlockSequence() > targetBlockStopTime.getBlockSequence()) {
return scheduleDeviation;
}
int a = targetBlockStopTime.getAccumulatedSlackTime();
int b = nextBlockStopTime.getAccumulatedSlackTime();
double slack = a - b;
StopTimeEntry nextStopTime = nextBlockStopTime.getStopTime();
if (nextStopTime.getArrivalTime() <= effectiveScheduleTime && effectiveScheduleTime <= nextStopTime.getDepartureTime()) {
slack -= (effectiveScheduleTime - nextStopTime.getArrivalTime());
}
slack = Math.max(slack, 0);
if (slack > 0 && scheduleDeviation > 0)
scheduleDeviation -= Math.min(scheduleDeviation, slack);
return scheduleDeviation;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method calculateDepartureDeviation.
private int calculateDepartureDeviation(BlockStopTimeEntry nextBlockStopTime, BlockStopTimeEntry targetBlockStopTime, int effectiveScheduleTime, int scheduleDeviation) {
// TargetStopTime
if (nextBlockStopTime == null || nextBlockStopTime.getBlockSequence() > targetBlockStopTime.getBlockSequence()) {
return scheduleDeviation;
}
StopTimeEntry nextStopTime = nextBlockStopTime.getStopTime();
StopTimeEntry targetStopTime = targetBlockStopTime.getStopTime();
double slack = targetBlockStopTime.getAccumulatedSlackTime() - nextBlockStopTime.getAccumulatedSlackTime();
slack += targetStopTime.getSlackTime();
if (nextStopTime.getArrivalTime() <= effectiveScheduleTime && effectiveScheduleTime <= nextStopTime.getDepartureTime()) {
slack -= (effectiveScheduleTime - nextStopTime.getArrivalTime());
}
slack = Math.max(slack, 0);
if (slack > 0 && scheduleDeviation > 0)
scheduleDeviation -= Math.min(scheduleDeviation, slack);
return scheduleDeviation;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibrary method assignmentSanityCheck.
private void assignmentSanityCheck(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments) throws DistanceAlongShapeException {
int stIndex = 0;
for (List<PointAndIndex> assignments : possibleAssignments) {
if (assignments.isEmpty()) {
StopTimeEntry stopTime = stopTimes.get(stIndex);
throw new InvalidStopToShapeMappingException(stopTime.getTrip());
}
Min<PointAndIndex> m = new Min<PointAndIndex>();
for (PointAndIndex pindex : assignments) m.add(pindex.distanceFromTarget, pindex);
if (m.getMinValue() > _maxDistanceFromStopToShapePoint) {
StopTimeEntry stopTime = stopTimes.get(stIndex);
PointAndIndex pindex = m.getMinElement();
CoordinatePoint point = shapePoints.getPointForIndex(pindex.index);
throw new StopIsTooFarFromShapeException(stopTime, pindex, point);
}
stIndex++;
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method computePredictedArrivalTimeInterval.
private TimeIntervalBean computePredictedArrivalTimeInterval(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, long targetTime) {
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
StopTimeEntry stopTime = blockStopTime.getStopTime();
// interval
if (stopTime.getArrivalTime() <= blockLocation.getEffectiveScheduleTime())
return null;
ScheduleDeviationSamples samples = blockLocation.getScheduleDeviations();
if (samples == null || samples.isEmpty())
return null;
double mu = InterpolationLibrary.interpolate(samples.getScheduleTimes(), samples.getScheduleDeviationMus(), stopTime.getArrivalTime(), EOutOfRangeStrategy.LAST_VALUE, EInRangeStrategy.INTERPOLATE);
double sigma = InterpolationLibrary.interpolate(samples.getScheduleTimes(), samples.getScheduleDeviationSigmas(), stopTime.getArrivalTime(), EOutOfRangeStrategy.LAST_VALUE, EInRangeStrategy.INTERPOLATE);
long from = (long) (instance.getScheduledArrivalTime() + (mu - sigma) * 1000);
long to = (long) (instance.getScheduledArrivalTime() + (mu + sigma) * 1000);
return new TimeIntervalBean(from, to);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method isMatch.
private boolean isMatch(List<StopTimeEntry> stopTimes, AgencyAndId stopId, int index) {
if (index < 0 || index >= stopTimes.size())
return false;
StopTimeEntry stopTime = stopTimes.get(index);
StopEntry stop = stopTime.getStop();
return stop.getId().equals(stopId);
}
Aggregations