Search in sources :

Example 36 with ArrivalAndDepartureInstance

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;
}
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 37 with ArrivalAndDepartureInstance

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

Aggregations

ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)37 Test (org.junit.Test)18 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)17 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)12 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)10 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)9 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 Date (java.util.Date)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 ArrayList (java.util.ArrayList)5 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 HashMap (java.util.HashMap)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 StopBean (org.onebusaway.transit_data.model.StopBean)3