Search in sources :

Example 1 with ArrivalAndDepartureTime

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);
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) ArrivalAndDepartureTime(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 2 with ArrivalAndDepartureTime

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;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) ArrivalAndDepartureTime(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 3 with ArrivalAndDepartureTime

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;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) ArrivalAndDepartureTime(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 4 with ArrivalAndDepartureTime

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;
}
Also used : ArrivalAndDepartureTime(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)

Aggregations

ArrivalAndDepartureTime (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime)4 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)3 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)3 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)3 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)2 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)2