Search in sources :

Example 6 with FrequencyBlockStopTimeIndex

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

the class StopScheduleServiceImpl method getAllServiceIdsForStop.

private Set<ServiceIdActivation> getAllServiceIdsForStop(StopEntry stop, boolean includePrivateService) {
    Set<ServiceIdActivation> allServiceIds = new HashSet<ServiceIdActivation>();
    List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stop);
    for (BlockStopTimeIndex index : indices) allServiceIds.add(index.getServiceIds());
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stop);
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) allServiceIds.add(index.getServiceIds());
    for (Iterator<ServiceIdActivation> it = allServiceIds.iterator(); it.hasNext(); ) {
        ServiceIdActivation activation = it.next();
        LocalizedServiceId lsid = activation.getActiveServiceIds().get(0);
        String agencyId = lsid.getId().getAgencyId();
        AgencyBean bean = _agencyBeanService.getAgencyForId(agencyId);
        if (bean.isPrivateService() && !includePrivateService)
            it.remove();
    }
    return allServiceIds;
}
Also used : FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) LocalizedServiceId(org.onebusaway.gtfs.model.calendar.LocalizedServiceId) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) HashSet(java.util.HashSet) AgencyBean(org.onebusaway.transit_data.model.AgencyBean)

Example 7 with FrequencyBlockStopTimeIndex

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

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

Example 9 with FrequencyBlockStopTimeIndex

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

the class BlockIndexServiceImpl method loadStopTimeIndices.

private void loadStopTimeIndices() {
    // Clear any existing indices
    for (StopEntry stop : _graphDao.getAllStops()) {
        StopEntryImpl stopImpl = (StopEntryImpl) stop;
        stopImpl.getStopTimeIndices().clear();
        stopImpl.getFrequencyStopTimeIndices().clear();
    }
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    factory.setVerbose(true);
    List<BlockStopTimeIndex> indices = factory.createIndices(_graphDao.getAllBlocks());
    for (BlockStopTimeIndex index : indices) {
        StopEntryImpl stop = (StopEntryImpl) index.getStop();
        stop.addStopTimeIndex(index);
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = factory.createFrequencyIndices(_graphDao.getAllBlocks());
    for (FrequencyBlockStopTimeIndex index : frequencyIndices) {
        StopEntryImpl stop = (StopEntryImpl) index.getStop();
        stop.addFrequencyStopTimeIndex(index);
    }
}
Also used : FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 10 with FrequencyBlockStopTimeIndex

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

the class BlockStopTimeIndicesFactory method createFrequencyIndicesFromGroups.

/**
 **
 *
 ***
 */
private List<FrequencyBlockStopTimeIndex> createFrequencyIndicesFromGroups(Map<BlockStopTimeKey, List<BlockStopTimeEntry>> stopTimesByKey) {
    List<FrequencyBlockStopTimeIndex> allIndices = new ArrayList<FrequencyBlockStopTimeIndex>();
    int count = 0;
    for (List<BlockStopTimeEntry> stopTimes : stopTimesByKey.values()) {
        if (_verbose && count % 100 == 0)
            _log.info("groups processed: " + count + "/" + stopTimesByKey.size());
        count++;
        List<FrequencyBlockStopTimeEntry> frequencyStopTimes = getStopTimesAsFrequencyStopTimes(stopTimes);
        List<List<FrequencyBlockStopTimeEntry>> groupedStopTimes = BlockLibrary.createStrictlyOrderedGroups(frequencyStopTimes, _frequencyBlockStopTimeLooseComparator, _frequencyBlockStopTimeStrictComparator);
        for (List<FrequencyBlockStopTimeEntry> group : groupedStopTimes) {
            FrequencyBlockStopTimeIndex index = createFrequencyBlockStopTimeIndexForGroup(group);
            allIndices.add(index);
        }
    }
    return allIndices;
}
Also used : FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry) FrequencyBlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)

Aggregations

FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)10 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)5 ArrayList (java.util.ArrayList)4 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)4 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)4 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 FrequencyEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry)3 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)3 Cacheable (org.onebusaway.container.cache.Cacheable)2 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)2 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)2 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)2 InstanceState (org.onebusaway.transit_data_federation.services.blocks.InstanceState)2 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)2 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)2 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)2 HashMap (java.util.HashMap)1