Search in sources :

Example 6 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState 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 7 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.

the class StopTimeServiceImpl method getFrequenciesForStopAndServiceIdsAndTimeRange.

private List<Integer> getFrequenciesForStopAndServiceIdsAndTimeRange(FrequencyStopTripIndex index, Date serviceDate, Date from, Date to, List<StopTimeInstance> stopTimeInstances, EFrequencyStopTimeBehavior frequencyBehavior) {
    int relativeFrom = effectiveTime(serviceDate, from);
    int relativeTo = effectiveTime(serviceDate, to);
    int fromIndex = GenericBinarySearch.search(index, index.size(), relativeFrom, IndexAdapters.FREQUENCY_END_TIME_INSTANCE);
    int toIndex = GenericBinarySearch.search(index, index.size(), relativeTo, IndexAdapters.FREQUENCY_START_TIME_INSTANCE);
    List<FrequencyBlockStopTimeEntry> frequencyStopTimes = index.getFrequencyStopTimes();
    List<Integer> offsetsIntoIndex = new ArrayList<Integer>();
    for (int in = fromIndex; in < toIndex; in++) {
        FrequencyBlockStopTimeEntry entry = frequencyStopTimes.get(in);
        BlockStopTimeEntry bst = entry.getStopTime();
        FrequencyEntry frequency = entry.getFrequency();
        InstanceState state = new InstanceState(serviceDate.getTime(), frequency);
        switch(frequencyBehavior) {
            case INCLUDE_UNSPECIFIED:
                {
                    stopTimeInstances.add(new StopTimeInstance(bst, state));
                    offsetsIntoIndex.add(in);
                    break;
                }
            case INCLUDE_INTERPOLATED:
                {
                    int stopTimeOffset = entry.getStopTimeOffset();
                    int tFrom = Math.max(relativeFrom, frequency.getStartTime());
                    int tTo = Math.min(relativeTo, frequency.getEndTime());
                    tFrom = snapToFrequencyStopTime(frequency, tFrom, stopTimeOffset, true);
                    tTo = snapToFrequencyStopTime(frequency, tTo, stopTimeOffset, false);
                    for (int t = tFrom; t <= tTo; t += frequency.getHeadwaySecs()) {
                        int frequencyOffset = t - bst.getStopTime().getDepartureTime();
                        stopTimeInstances.add(new StopTimeInstance(bst, state, frequencyOffset));
                        offsetsIntoIndex.add(in);
                    }
                    break;
                }
        }
    }
    return offsetsIntoIndex;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) ArrayList(java.util.ArrayList) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Example 8 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState 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 9 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState 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 10 with InstanceState

use of org.onebusaway.transit_data_federation.services.blocks.InstanceState in project onebusaway-application-modules by camsys.

the class StopScheduleBeanServiceImpl method groupFrequencyInstancesByRouteCollectionId.

private void groupFrequencyInstancesByRouteCollectionId(StopEntry stopEntry, ServiceDate date, Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId) {
    for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) {
        ServiceIdActivation serviceIds = index.getServiceIds();
        Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
        if (!serviceDates.contains(date))
            continue;
        Date serviceDate = date.getAsDate(serviceIds.getTimeZone());
        for (FrequencyBlockStopTimeEntry entry : index.getFrequencyStopTimes()) {
            BlockStopTimeEntry stopTime = entry.getStopTime();
            BlockTripEntry blockTrip = stopTime.getTrip();
            TripEntry trip = blockTrip.getTrip();
            AgencyAndId routeCollectionId = trip.getRouteCollection().getId();
            InstanceState state = new InstanceState(serviceDate.getTime(), entry.getFrequency());
            StopTimeInstance sti = new StopTimeInstance(stopTime, state);
            frequenciesByRouteCollectionId.get(routeCollectionId).add(sti);
        }
    }
}
Also used : ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Aggregations

InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)14 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)8 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)7 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)7 Date (java.util.Date)5 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)5 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)5 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)4 ArrayList (java.util.ArrayList)3 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)3 ArrivalAndDepartureTime (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureTime)3 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)2 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)2 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1