Search in sources :

Example 1 with FrequencyInstanceBean

use of org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean in project onebusaway-application-modules by camsys.

the class ScheduleAction method getFilteredFrequencies.

private List<FrequencyInstanceBean> getFilteredFrequencies(StopRouteDirectionScheduleBean direction) {
    List<FrequencyInstanceBean> frequencies = direction.getFrequencies();
    List<FrequencyInstanceBean> filteredFrequencies = new ArrayList<FrequencyInstanceBean>(frequencies.size());
    boolean showArrivals = (_showArrivals == null) ? !(directionHasDepartures(direction)) : _showArrivals;
    for (FrequencyInstanceBean frequency : frequencies) {
        if ((showArrivals && frequency.isArrivalEnabled()) || (!showArrivals && frequency.isDepartureEnabled()))
            filteredFrequencies.add(frequency);
    }
    return filteredFrequencies;
}
Also used : FrequencyInstanceBean(org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean) ArrayList(java.util.ArrayList)

Example 2 with FrequencyInstanceBean

use of org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean in project onebusaway-application-modules by camsys.

the class ScheduleAction method filterResults.

/**
 **
 *
 ***
 */
private void filterResults() {
    List<StopRouteScheduleBean> routes = _result.getRoutes();
    List<StopRouteScheduleBean> filteredRoutes = new ArrayList<StopRouteScheduleBean>(routes.size());
    for (StopRouteScheduleBean route : routes) {
        List<StopRouteDirectionScheduleBean> directions = route.getDirections();
        List<StopRouteDirectionScheduleBean> filteredDirections = new ArrayList<StopRouteDirectionScheduleBean>(directions.size());
        for (StopRouteDirectionScheduleBean direction : directions) {
            List<StopTimeInstanceBean> filteredStopTimes = getFilteredStopTimes(direction);
            List<FrequencyInstanceBean> filteredFrequencies = getFilteredFrequencies(direction);
            if (!(filteredStopTimes.isEmpty() && filteredFrequencies.isEmpty())) {
                direction.setStopTimes(filteredStopTimes);
                direction.setFrequencies(filteredFrequencies);
                filteredDirections.add(direction);
            }
        }
        if (!filteredDirections.isEmpty()) {
            route.setDirections(filteredDirections);
            filteredRoutes.add(route);
        }
    }
    _result.setRoutes(filteredRoutes);
}
Also used : StopTimeInstanceBean(org.onebusaway.transit_data.model.StopTimeInstanceBean) StopRouteScheduleBean(org.onebusaway.transit_data.model.StopRouteScheduleBean) FrequencyInstanceBean(org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean) ArrayList(java.util.ArrayList) StopRouteDirectionScheduleBean(org.onebusaway.transit_data.model.StopRouteDirectionScheduleBean)

Example 3 with FrequencyInstanceBean

use of org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean in project onebusaway-application-modules by camsys.

the class BeanFactoryV2 method getStopRouteDirectionSchedule.

public StopRouteDirectionScheduleV2Bean getStopRouteDirectionSchedule(StopRouteDirectionScheduleBean direction) {
    StopRouteDirectionScheduleV2Bean bean = new StopRouteDirectionScheduleV2Bean();
    bean.setTripHeadsign(direction.getTripHeadsign());
    List<ScheduleStopTimeInstanceV2Bean> stopTimes = new ArrayList<ScheduleStopTimeInstanceV2Bean>();
    for (StopTimeInstanceBean sti : direction.getStopTimes()) {
        ScheduleStopTimeInstanceV2Bean stiBean = new ScheduleStopTimeInstanceV2Bean();
        stiBean.setArrivalEnabled(sti.isArrivalEnabled());
        stiBean.setArrivalTime(sti.getArrivalTime());
        stiBean.setDepartureEnabled(sti.isDepartureEnabled());
        stiBean.setDepartureTime(sti.getDepartureTime());
        stiBean.setServiceId(sti.getServiceId());
        stiBean.setTripId(sti.getTripId());
        stiBean.setStopHeadsign(stiBean.getStopHeadsign());
        stopTimes.add(stiBean);
    }
    if (!stopTimes.isEmpty())
        bean.setScheduleStopTimes(stopTimes);
    List<ScheduleFrequencyInstanceV2Bean> frequencies = new ArrayList<ScheduleFrequencyInstanceV2Bean>();
    for (FrequencyInstanceBean freq : direction.getFrequencies()) {
        ScheduleFrequencyInstanceV2Bean freqBean = new ScheduleFrequencyInstanceV2Bean();
        freqBean.setServiceDate(freq.getServiceDate());
        freqBean.setServiceId(freq.getServiceId());
        freqBean.setTripId(freq.getTripId());
        freqBean.setStartTime(freq.getStartTime());
        freqBean.setEndTime(freq.getEndTime());
        freqBean.setHeadway(freq.getHeadwaySecs());
        freqBean.setStopHeadsign(freq.getStopHeadsign());
        freqBean.setArrivalEnabled(freq.isArrivalEnabled());
        freqBean.setDepartureEnabled(freq.isDepartureEnabled());
        frequencies.add(freqBean);
    }
    if (!frequencies.isEmpty())
        bean.setScheduleFrequencies(frequencies);
    return bean;
}
Also used : StopTimeInstanceBean(org.onebusaway.transit_data.model.StopTimeInstanceBean) FrequencyInstanceBean(org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean) ArrayList(java.util.ArrayList)

Example 4 with FrequencyInstanceBean

use of org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean 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)

Aggregations

ArrayList (java.util.ArrayList)4 FrequencyInstanceBean (org.onebusaway.transit_data.model.schedule.FrequencyInstanceBean)4 StopTimeInstanceBean (org.onebusaway.transit_data.model.StopTimeInstanceBean)3 StopRouteDirectionScheduleBean (org.onebusaway.transit_data.model.StopRouteDirectionScheduleBean)2 StopRouteScheduleBean (org.onebusaway.transit_data.model.StopRouteScheduleBean)2 HashSet (java.util.HashSet)1 List (java.util.List)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 Cacheable (org.onebusaway.container.cache.Cacheable)1 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1 StopTimeGroupBean (org.onebusaway.transit_data.model.StopTimeGroupBean)1 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)1 TripNarrative (org.onebusaway.transit_data_federation.model.narrative.TripNarrative)1 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)1 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)1 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)1 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)1 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)1 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)1