Search in sources :

Example 1 with StopCalendarDaysBean

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

the class ScheduleAction method execute.

@Override
@Actions({ @Action(value = "/where/schedule") })
public String execute() throws Exception {
    if (_date == null)
        _date = new Date();
    if (_id == null)
        return INPUT;
    _result = _service.getScheduleForStop(_id, _date);
    if (_result == null)
        throw new NoSuchStopServiceException(_id);
    StopCalendarDaysBean days = _result.getCalendarDays();
    String tzName = days.getTimeZone();
    _timeZone = TimeZone.getTimeZone(tzName);
    if (_timeZone == null)
        _timeZone = TimeZone.getDefault();
    filterResults();
    return SUCCESS;
}
Also used : StopCalendarDaysBean(org.onebusaway.transit_data.model.StopCalendarDaysBean) NoSuchStopServiceException(org.onebusaway.exceptions.NoSuchStopServiceException) Date(java.util.Date) Actions(org.apache.struts2.convention.annotation.Actions)

Example 2 with StopCalendarDaysBean

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

Aggregations

Date (java.util.Date)2 StopCalendarDaysBean (org.onebusaway.transit_data.model.StopCalendarDaysBean)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 SortedMap (java.util.SortedMap)1 TimeZone (java.util.TimeZone)1 TreeMap (java.util.TreeMap)1 Actions (org.apache.struts2.convention.annotation.Actions)1 Counter (org.onebusaway.collections.Counter)1 FactoryMap (org.onebusaway.collections.FactoryMap)1 Cacheable (org.onebusaway.container.cache.Cacheable)1 NoSuchStopServiceException (org.onebusaway.exceptions.NoSuchStopServiceException)1 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)1 StopCalendarDayBean (org.onebusaway.transit_data.model.StopCalendarDayBean)1 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)1 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)1 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)1