Search in sources :

Example 41 with StopEntry

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

the class StopScheduleServiceImpl method getServiceDateSummariesForStop.

@Override
public List<ServiceDateSummary> getServiceDateSummariesForStop(AgencyAndId stopId, boolean includePrivateService) {
    StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
    Set<ServiceIdActivation> allServiceIds = getAllServiceIdsForStop(stop, includePrivateService);
    Map<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = new FactoryMap<ServiceDate, Set<ServiceIdActivation>>(new HashSet<ServiceIdActivation>());
    for (ServiceIdActivation serviceIds : allServiceIds) {
        Set<ServiceDate> serviceDates = _calendarService.getServiceDatesForServiceIds(serviceIds);
        for (ServiceDate serviceDate : serviceDates) serviceIdsByDate.get(serviceDate).add(serviceIds);
    }
    Map<Set<ServiceIdActivation>, List<ServiceDate>> datesByServiceIds = new FactoryMap<Set<ServiceIdActivation>, List<ServiceDate>>(new ArrayList<ServiceDate>());
    for (Map.Entry<ServiceDate, Set<ServiceIdActivation>> entry : serviceIdsByDate.entrySet()) {
        ServiceDate serviceDate = entry.getKey();
        Set<ServiceIdActivation> serviceIds = entry.getValue();
        datesByServiceIds.get(serviceIds).add(serviceDate);
    }
    List<ServiceDateSummary> summaries = new ArrayList<ServiceDateSummary>();
    for (Map.Entry<Set<ServiceIdActivation>, List<ServiceDate>> entry : datesByServiceIds.entrySet()) {
        Set<ServiceIdActivation> serviceIds = entry.getKey();
        List<ServiceDate> serviceDates = entry.getValue();
        Collections.sort(serviceDates);
        summaries.add(new ServiceDateSummary(serviceIds, serviceDates));
    }
    Collections.sort(summaries);
    return summaries;
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ServiceDateSummary(org.onebusaway.transit_data_federation.model.ServiceDateSummary) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 42 with StopEntry

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

the class AgencyServiceImpl method getAgencyIdsAndCenterPoints.

@Cacheable
public Map<String, CoordinatePoint> getAgencyIdsAndCenterPoints() {
    Map<String, CoordinatePoint> centersByAgencyId = new HashMap<String, CoordinatePoint>();
    for (AgencyEntry agency : _graph.getAllAgencies()) {
        StopsCenterOfMass centerOfMass = new StopsCenterOfMass();
        for (RouteCollectionEntry routeCollection : agency.getRouteCollections()) {
            for (RouteEntry route : routeCollection.getChildren()) {
                for (TripEntry trip : route.getTrips()) {
                    for (StopTimeEntry stopTime : trip.getStopTimes()) {
                        StopEntry stop = stopTime.getStop();
                        centerOfMass.lats += stop.getStopLat();
                        centerOfMass.lons += stop.getStopLon();
                        centerOfMass.count++;
                    }
                }
            }
        }
        if (centerOfMass.count == 0) {
            _log.warn("Agency has no service: " + agency);
        } else {
            double lat = centerOfMass.lats / centerOfMass.count;
            double lon = centerOfMass.lons / centerOfMass.count;
            centersByAgencyId.put(agency.getId(), new CoordinatePoint(lat, lon));
        }
    }
    return centersByAgencyId;
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) RouteEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteEntry) HashMap(java.util.HashMap) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) RouteCollectionEntry(org.onebusaway.transit_data_federation.services.transit_graph.RouteCollectionEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 43 with StopEntry

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

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

the class StopScheduleBeanServiceImpl method getCalendarForStop.

@Cacheable
public StopCalendarDaysBean getCalendarForStop(AgencyAndId stopId) {
    TimeZone timeZone = _agencyService.getTimeZoneForAgencyId(stopId.getAgencyId());
    StopEntry stopEntry = _graph.getStopEntryForId(stopId);
    Set<ServiceIdActivation> serviceIds = new HashSet<ServiceIdActivation>();
    for (BlockStopTimeIndex index : _blockIndexService.getStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
    for (FrequencyBlockStopTimeIndex index : _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry)) serviceIds.add(index.getServiceIds());
    SortedMap<ServiceDate, Set<ServiceIdActivation>> serviceIdsByDate = getServiceIdsByDate(serviceIds);
    Counter<Set<ServiceIdActivation>> counts = new Counter<Set<ServiceIdActivation>>();
    for (Set<ServiceIdActivation> ids : serviceIdsByDate.values()) counts.increment(ids);
    int total = counts.size();
    Map<Set<ServiceIdActivation>, Integer> idsToGroup = new HashMap<Set<ServiceIdActivation>, Integer>();
    for (Set<ServiceIdActivation> ids : counts.getSortedKeys()) idsToGroup.put(ids, total--);
    List<StopCalendarDayBean> beans = new ArrayList<StopCalendarDayBean>(serviceIdsByDate.size());
    for (Map.Entry<ServiceDate, Set<ServiceIdActivation>> entry : serviceIdsByDate.entrySet()) {
        StopCalendarDayBean bean = new StopCalendarDayBean();
        ServiceDate serviceDate = entry.getKey();
        Date date = serviceDate.getAsDate(timeZone);
        bean.setDate(date);
        Integer indexId = idsToGroup.get(entry.getValue());
        bean.setGroup(indexId);
        beans.add(bean);
    }
    return new StopCalendarDaysBean(timeZone.getID(), beans);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StopCalendarDaysBean(org.onebusaway.transit_data.model.StopCalendarDaysBean) HashMap(java.util.HashMap) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) Date(java.util.Date) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) StopCalendarDayBean(org.onebusaway.transit_data.model.StopCalendarDayBean) TimeZone(java.util.TimeZone) ServiceDate(org.onebusaway.gtfs.model.calendar.ServiceDate) Counter(org.onebusaway.collections.Counter) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 45 with StopEntry

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

the class StopsBeanServiceImpl method getStopsIdsForAgencyId.

@Override
public ListBean<String> getStopsIdsForAgencyId(String agencyId) {
    AgencyEntry agency = _transitGraphDao.getAgencyForId(agencyId);
    if (agency == null)
        throw new NoSuchAgencyServiceException(agencyId);
    List<String> ids = new ArrayList<String>();
    for (StopEntry stop : agency.getStops()) {
        AgencyAndId id = stop.getId();
        ids.add(AgencyAndIdLibrary.convertToString(id));
    }
    return new ListBean<String>(ids, false);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) NoSuchAgencyServiceException(org.onebusaway.exceptions.NoSuchAgencyServiceException) ArrayList(java.util.ArrayList) ListBean(org.onebusaway.transit_data.model.ListBean) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) AgencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.AgencyEntry)

Aggregations

StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)54 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)28 ArrayList (java.util.ArrayList)15 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)14 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)12 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)12 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)10 List (java.util.List)9 FactoryMap (org.onebusaway.collections.FactoryMap)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Test (org.junit.Test)8 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopBean (org.onebusaway.transit_data.model.StopBean)4