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;
}
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;
}
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);
}
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);
}
}
}
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();
}
Aggregations