Search in sources :

Example 66 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class ExtendedCalendarServiceImpl method determineAllServiceIds.

private Set<ServiceIdActivation> determineAllServiceIds() {
    Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
    for (BlockEntry block : _transitGraphDao.getAllBlocks()) {
        for (BlockConfigurationEntry blockConfig : block.getConfigurations()) {
            ServiceIdActivation serviceIds = blockConfig.getServiceIds();
            allServiceIds.add(serviceIds);
        }
    }
    return allServiceIds;
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) HashSet(java.util.HashSet)

Example 67 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry 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 68 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry 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 69 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class StopScheduleBeanServiceImpl method getScheduledArrivalsForStopAndDate.

@Cacheable
public List<StopRouteScheduleBean> getScheduledArrivalsForStopAndDate(AgencyAndId stopId, ServiceDate date) {
    StopEntry stopEntry = _graph.getStopEntryForId(stopId);
    Map<AgencyAndId, List<StopTimeInstance>> stopTimesByRouteCollectionId = new FactoryMap<AgencyAndId, List<StopTimeInstance>>(new ArrayList<StopTimeInstance>());
    Map<AgencyAndId, List<StopTimeInstance>> frequenciesByRouteCollectionId = new FactoryMap<AgencyAndId, List<StopTimeInstance>>(new ArrayList<StopTimeInstance>());
    groupStopTimeInstancesByRouteCollectionId(stopEntry, date, stopTimesByRouteCollectionId, frequenciesByRouteCollectionId);
    groupFrequencyInstancesByRouteCollectionId(stopEntry, date, frequenciesByRouteCollectionId);
    Set<AgencyAndId> routeIds = new HashSet<AgencyAndId>();
    routeIds.addAll(stopTimesByRouteCollectionId.keySet());
    routeIds.addAll(frequenciesByRouteCollectionId.keySet());
    List<StopRouteScheduleBean> beans = new ArrayList<StopRouteScheduleBean>();
    for (AgencyAndId routeId : routeIds) {
        StopRouteScheduleBean routeScheduleBean = new StopRouteScheduleBean();
        beans.add(routeScheduleBean);
        RouteBean route = _routeBeanService.getRouteForId(routeId);
        routeScheduleBean.setRoute(route);
        Map<String, StopTimeByDirectionEntry> stopTimesByDirection = new FactoryMap<String, StopTimeByDirectionEntry>(new StopTimeByDirectionEntry());
        List<StopTimeInstance> stopTimesForRoute = stopTimesByRouteCollectionId.get(routeId);
        for (StopTimeInstance sti : stopTimesForRoute) {
            BlockStopTimeEntry bst = sti.getStopTime();
            BlockTripEntry blockTrip = sti.getTrip();
            BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
            TripEntry trip = blockTrip.getTrip();
            AgencyAndId tripId = trip.getId();
            AgencyAndId serviceId = trip.getServiceId().getId();
            TripNarrative narrative = _narrativeService.getTripForId(tripId);
            StopTimeInstanceBean stiBean = new StopTimeInstanceBean();
            stiBean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
            stiBean.setServiceDate(sti.getServiceDate());
            stiBean.setArrivalTime(sti.getArrivalTime());
            stiBean.setDepartureTime(sti.getDepartureTime());
            stiBean.setServiceId(AgencyAndIdLibrary.convertToString(serviceId));
            stiBean.setArrivalEnabled(bst.getBlockSequence() > 0);
            stiBean.setDepartureEnabled(bst.getBlockSequence() + 1 < blockConfig.getStopTimes().size());
            String directionId = trip.getDirectionId();
            if (directionId == null)
                directionId = "0";
            String tripHeadsign = narrative.getTripHeadsign();
            TripHeadsignStopTimeGroupKey groupKey = new TripHeadsignStopTimeGroupKey(tripHeadsign);
            ContinuesAsStopTimeGroupKey continuesAsGroupKey = getContinuesAsGroupKeyForStopTimeInstance(sti);
            StopTimeByDirectionEntry stopTimesForDirection = stopTimesByDirection.get(directionId);
            stopTimesForDirection.addEntry(stiBean, tripHeadsign, groupKey, continuesAsGroupKey);
        }
        List<StopTimeInstance> frequenciesForRoute = frequenciesByRouteCollectionId.get(routeId);
        for (StopTimeInstance sti : frequenciesForRoute) {
            BlockStopTimeEntry blockStopTime = sti.getStopTime();
            BlockTripEntry blockTrip = blockStopTime.getTrip();
            TripEntry trip = blockTrip.getTrip();
            BlockConfigurationEntry blockConfig = blockTrip.getBlockConfiguration();
            AgencyAndId tripId = trip.getId();
            AgencyAndId serviceId = trip.getServiceId().getId();
            TripNarrative narrative = _narrativeService.getTripForId(tripId);
            FrequencyInstanceBean bean = new FrequencyInstanceBean();
            bean.setTripId(AgencyAndIdLibrary.convertToString(tripId));
            bean.setServiceDate(sti.getServiceDate());
            bean.setStartTime(sti.getServiceDate() + sti.getFrequency().getStartTime() * 1000);
            bean.setEndTime(sti.getServiceDate() + sti.getFrequency().getEndTime() * 1000);
            bean.setHeadwaySecs(sti.getFrequency().getHeadwaySecs());
            bean.setServiceId(AgencyAndIdLibrary.convertToString(serviceId));
            bean.setArrivalEnabled(blockStopTime.getBlockSequence() > 0);
            bean.setDepartureEnabled(blockStopTime.getBlockSequence() + 1 < blockConfig.getStopTimes().size());
            String directionId = trip.getDirectionId();
            if (directionId == null)
                directionId = "0";
            StopTimeByDirectionEntry stopTimesForDirection = stopTimesByDirection.get(directionId);
            stopTimesForDirection.addEntry(bean, narrative.getTripHeadsign());
        }
        for (StopTimeByDirectionEntry stopTimesForDirection : stopTimesByDirection.values()) {
            StopRouteDirectionScheduleBean directionBean = new StopRouteDirectionScheduleBean();
            directionBean.getStopTimes().addAll(stopTimesForDirection.getStopTimes());
            directionBean.getFrequencies().addAll(stopTimesForDirection.getFrequencies());
            String headsign = stopTimesForDirection.getBestHeadsign();
            directionBean.setTripHeadsign(headsign);
            Collections.sort(directionBean.getStopTimes(), _stopTimeComparator);
            Collections.sort(directionBean.getFrequencies(), _frequencyComparator);
            List<StopTimeGroupBean> groups = new ArrayList<StopTimeGroupBean>();
            applyTripHeadsignStopTimeGroups(stopTimesForDirection, groups);
            applyContinuesAsStopTimeGroups(stopTimesForDirection, groups);
            directionBean.setGroups(groups);
            routeScheduleBean.getDirections().add(directionBean);
        }
        Collections.sort(routeScheduleBean.getDirections(), _directionComparator);
    }
    Collections.sort(beans, _stopRouteScheduleComparator);
    return beans;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) StopRouteScheduleBean(org.onebusaway.transit_data.model.StopRouteScheduleBean) ArrayList(java.util.ArrayList) StopTimeGroupBean(org.onebusaway.transit_data.model.StopTimeGroupBean) RouteBean(org.onebusaway.transit_data.model.RouteBean) StopTimeInstanceBean(org.onebusaway.transit_data.model.StopTimeInstanceBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) List(java.util.List) ArrayList(java.util.ArrayList) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) HashSet(java.util.HashSet) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyInstanceBean(org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean) TripNarrative(org.onebusaway.transit_data_federation.model.narrative.TripNarrative) StopRouteDirectionScheduleBean(org.onebusaway.transit_data.model.StopRouteDirectionScheduleBean) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 70 with BlockConfigurationEntry

use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.

the class BlockCalendarServiceImpl method getBlockInstance.

/**
 **
 * {@link BlockCalendarService} Interface
 ***
 */
@Cacheable(isValueSerializable = false)
@Override
public BlockInstance getBlockInstance(AgencyAndId blockId, long serviceDate) {
    BlockEntry block = _transitGraphDao.getBlockEntryForId(blockId);
    if (block == null)
        throw new IllegalArgumentException("unknown block: " + blockId);
    List<BlockConfigurationEntry> configurations = block.getConfigurations();
    int index = 0;
    Date date = new Date(serviceDate);
    InstanceState state = new InstanceState(serviceDate);
    /**
     * See the specific contract for {@link BlockEntry#getConfigurations()}
     * about the sort order of configurations
     */
    for (BlockConfigurationEntry configuration : configurations) {
        if (allServiceIdsAreActiveForServiceDate(configuration, date)) {
            return new BlockInstance(configuration, state);
        }
        index++;
    }
    return null;
}
Also used : InstanceState(org.onebusaway.transit_data_federation.services.blocks.InstanceState) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) Date(java.util.Date) Cacheable(org.onebusaway.container.cache.Cacheable)

Aggregations

BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)89 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)36 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)34 Test (org.junit.Test)30 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)29 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)27 ArrayList (java.util.ArrayList)23 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)23 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)18 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)17 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)14 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)13 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)13 Date (java.util.Date)12 List (java.util.List)11 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)10 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)10 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)8 FactoryMap (org.onebusaway.collections.FactoryMap)8