use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance 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.ArrivalAndDepartureInstance 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