use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method setPredictedTimesFromScheduleDeviation.
private void setPredictedTimesFromScheduleDeviation(ArrivalAndDepartureInstance instance, BlockLocation blockLocation, int scheduleDeviation, long targetTime) {
BlockStopTimeEntry blockStopTime = instance.getBlockStopTime();
int effectiveScheduleTime = (int) (((targetTime - instance.getServiceDate()) / 1000) - scheduleDeviation);
int arrivalDeviation = calculateArrivalDeviation(blockLocation.getNextStop(), blockStopTime, effectiveScheduleTime, scheduleDeviation);
int departureDeviation = calculateDepartureDeviation(blockLocation.getNextStop(), blockStopTime, effectiveScheduleTime, scheduleDeviation);
/**
* Why don't we use the ArrivalAndDepartureTime scheduled arrival and
* departures here? Because they may have been artificially shifted for a
* frequency-based method
*/
InstanceState state = instance.getStopTimeInstance().getState();
ArrivalAndDepartureTime schedule = ArrivalAndDepartureTime.getScheduledTime(state, instance.getBlockStopTime());
long arrivalTime = schedule.getArrivalTime() + arrivalDeviation * 1000;
setPredictedArrivalTimeForInstance(instance, arrivalTime);
long departureTime = schedule.getDepartureTime() + departureDeviation * 1000;
setPredictedDepartureTimeForInstance(instance, departureTime);
}
use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getNextStopArrivalAndDeparture.
@Override
public ArrivalAndDepartureInstance getNextStopArrivalAndDeparture(ArrivalAndDepartureInstance instance) {
BlockStopTimeEntry stopTime = instance.getBlockStopTime();
BlockTripEntry trip = stopTime.getTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = stopTime.getBlockSequence() + 1;
if (index >= stopTimes.size())
return null;
BlockStopTimeEntry nextStopTime = stopTimes.get(index);
InstanceState state = instance.getStopTimeInstance().getState();
ArrivalAndDepartureTime scheduledTime = ArrivalAndDepartureTime.getScheduledTime(state, nextStopTime);
if (state.getFrequency() != null) {
StopTimeEntry nStopTime = nextStopTime.getStopTime();
int betweenStopDelta = nStopTime.getArrivalTime() - stopTime.getStopTime().getDepartureTime();
int atStopDelta = nStopTime.getDepartureTime() - nStopTime.getArrivalTime();
long scheduledArrivalTime = instance.getScheduledDepartureTime() + betweenStopDelta * 1000;
long scheduledDepartureTime = scheduledArrivalTime + atStopDelta * 1000;
scheduledTime.setArrivalTime(scheduledArrivalTime);
scheduledTime.setDepartureTime(scheduledDepartureTime);
}
StopTimeInstance nextStopTimeInstance = new StopTimeInstance(stopTime, state);
ArrivalAndDepartureInstance nextInstance = new ArrivalAndDepartureInstance(nextStopTimeInstance, scheduledTime);
if (instance.isPredictedDepartureTimeSet()) {
int scheduledDeviation = (int) ((instance.getPredictedDepartureTime() - instance.getScheduledDepartureTime()) / 1000);
int arrivalDeviation = propagateScheduleDeviationForwardBetweenStops(stopTime, nextStopTime, scheduledDeviation);
int departureDeviation = propagateScheduleDeviationForwardAcrossStop(nextStopTime, arrivalDeviation);
setPredictedArrivalTimeForInstance(nextInstance, nextInstance.getScheduledArrivalTime() + arrivalDeviation * 1000);
setPredictedDepartureTimeForInstance(nextInstance, nextInstance.getScheduledDepartureTime() + departureDeviation * 1000);
}
return nextInstance;
}
use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method getPreviousStopArrivalAndDeparture.
@Override
public ArrivalAndDepartureInstance getPreviousStopArrivalAndDeparture(ArrivalAndDepartureInstance instance) {
BlockStopTimeEntry stopTime = instance.getBlockStopTime();
BlockTripEntry trip = stopTime.getTrip();
BlockConfigurationEntry blockConfig = trip.getBlockConfiguration();
List<BlockStopTimeEntry> stopTimes = blockConfig.getStopTimes();
int index = stopTime.getBlockSequence() - 1;
if (index < 0)
return null;
BlockStopTimeEntry prevStopTime = stopTimes.get(index);
InstanceState state = instance.getStopTimeInstance().getState();
ArrivalAndDepartureTime scheduledTime = ArrivalAndDepartureTime.getScheduledTime(state, prevStopTime);
if (instance.getFrequency() != null) {
StopTimeEntry pStopTime = prevStopTime.getStopTime();
int betweenStopDelta = stopTime.getStopTime().getArrivalTime() - pStopTime.getDepartureTime();
int atStopDelta = pStopTime.getDepartureTime() - pStopTime.getArrivalTime();
long scheduledDepartureTime = instance.getScheduledArrivalTime() - betweenStopDelta * 1000;
long scheduledArrivalTime = scheduledDepartureTime - atStopDelta * 1000;
scheduledTime.setArrivalTime(scheduledArrivalTime);
scheduledTime.setDepartureTime(scheduledDepartureTime);
}
StopTimeInstance prevStopTimeInstance = new StopTimeInstance(prevStopTime, state);
ArrivalAndDepartureInstance prevInstance = new ArrivalAndDepartureInstance(prevStopTimeInstance, scheduledTime);
if (instance.isPredictedArrivalTimeSet()) {
int scheduledDeviation = (int) ((instance.getPredictedArrivalTime() - instance.getScheduledArrivalTime()) / 1000);
int departureDeviation = propagateScheduleDeviationBackwardBetweenStops(prevStopTime, stopTime, scheduledDeviation);
int arrivalDeviation = propagateScheduleDeviationBackwardAcrossStop(prevStopTime, departureDeviation);
setPredictedArrivalTimeForInstance(prevInstance, prevInstance.getScheduledArrivalTime() + arrivalDeviation * 1000);
setPredictedDepartureTimeForInstance(prevInstance, prevInstance.getScheduledDepartureTime() + departureDeviation * 1000);
}
return prevInstance;
}
use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImpl method createArrivalAndDepartureForStopTimeInstanceWithTime.
private ArrivalAndDepartureInstance createArrivalAndDepartureForStopTimeInstanceWithTime(StopTimeInstance sti, long time) {
ArrivalAndDepartureTime scheduledTime = new ArrivalAndDepartureTime(time, time);
ArrivalAndDepartureInstance instance = new ArrivalAndDepartureInstance(sti, scheduledTime);
instance.setBlockSequence(sti.getBlockSequence());
return instance;
}
Aggregations