Search in sources :

Example 26 with ServiceIdActivation

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

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

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

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

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

the class SiriLikeRealtimeSource method getEffectiveScheduleTime.

private long getEffectiveScheduleTime(TripEntry trip, double lat, double lon, long timestamp, long serviceDate) {
    ServiceIdActivation serviceIds = new ServiceIdActivation(trip.getServiceId());
    // todo!
    BlockConfigurationEntry blockConfig = blockConfiguration(trip.getBlock(), serviceIds, trip);
    BlockInstance block = new BlockInstance(blockConfig, serviceDate);
    CoordinatePoint location = new CoordinatePoint(lat, lon);
    ScheduledBlockLocation loc = _blockGeospatialService.getBestScheduledBlockLocationForLocation(block, location, timestamp, 0, trip.getTotalTripDistance());
    return loc.getScheduledTime();
}
Also used : CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)

Aggregations

ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)31 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)19 Test (org.junit.Test)17 Date (java.util.Date)16 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)8 HashSet (java.util.HashSet)7 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)7 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)7 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)7 ArrayList (java.util.ArrayList)6 LocalizedServiceId (org.onebusaway.gtfs.model.calendar.LocalizedServiceId)6 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)6 Set (java.util.Set)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)5 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)5 FactoryMap (org.onebusaway.collections.FactoryMap)4 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)4 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)4 TimeZone (java.util.TimeZone)3