Search in sources :

Example 11 with BlockStopTimeIndex

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

the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithCalculatedDirection.

@Test
public void testGenerateStopNarrativesWithCalculatedDirection() {
    StopEntryImpl stopEntry = stop("stopA", 47.663146, -122.300928);
    Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopEntry));
    Stop stop = new Stop();
    stop.setId(stopEntry.getId());
    Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
    AgencyAndId shapeId = aid("shapeA");
    ShapePointsFactory factory = new ShapePointsFactory();
    factory.addPoint(47.661225, -122.3009201);
    factory.addPoint(47.664375, -122.3008986);
    ShapePoints shapePoints = factory.create();
    _provider.setShapePointsForId(shapeId, shapePoints);
    TripEntryImpl trip = trip("trip");
    trip.setShapeId(shapeId);
    StopTimeEntryImpl stopTime = stopTime(0, stopEntry, trip, 0, 0.0);
    stopTime.setShapePointIndex(0);
    BlockStopTimeEntry blockStopTime = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTime.getStopTime()).thenReturn(stopTime);
    BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
    Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTime));
    List<BlockStopTimeIndex> indices = Arrays.asList(index);
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
    _task.generateStopNarratives(_provider);
    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertEquals("N", narrative.getDirection());
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 12 with BlockStopTimeIndex

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

the class ScheduledServiceServiceImpl method stopHasRevenueServiceOnRoute.

@Override
public Boolean stopHasRevenueServiceOnRoute(String agencyId, String stopId, String routeId, String directionId) {
    AgencyAndId stopAndId = null;
    if (stopId != null && stopId.contains("_"))
        stopAndId = AgencyAndIdLibrary.convertFromString(stopId);
    else if (stopId != null)
        stopAndId = new AgencyAndId(agencyId, stopId);
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
    List<BlockStopTimeIndex> stopTimeIndicesForStop = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
    for (BlockStopTimeIndex bsti : stopTimeIndicesForStop) {
        List<BlockStopTimeEntry> stopTimes = bsti.getStopTimes();
        for (BlockStopTimeEntry bste : stopTimes) {
            StopTimeEntry stopTime = bste.getStopTime();
            TripEntry theTrip = stopTime.getTrip();
            if (routeId != null && !theTrip.getRoute().getId().toString().equals(routeId)) {
                continue;
            }
            if (directionId != null && theTrip.getDirectionId() != null) {
                if (!theTrip.getDirectionId().equals(directionId)) {
                    continue;
                }
            }
            /*
               * If at least one stoptime on one trip (subject to the
               * route and direction filters above) permits unrestricted
               * pick-up or drop-off at this stop (type=0), then it is
               * considered a 'revenue' stop.
               */
            if (stopTime.getDropOffType() == 0 || stopTime.getPickupType() == 0) {
                return true;
            }
        }
    }
    return false;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 13 with BlockStopTimeIndex

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

the class GenerateNarrativesTask method getAllOrientationsForStop.

private Collection<PointAndOrientation> getAllOrientationsForStop(NarrativeProviderImpl provider, StopEntry stop) {
    List<BlockStopTimeIndex> stopTimeIndices = _blockIndexService.getStopTimeIndicesForStop(stop);
    List<PointAndOrientation> pos = new ArrayList<PointAndOrientation>();
    Map<ShapeIdAndDistance, PointAndOrientation> orientationsByKey = new HashMap<ShapeIdAndDistance, PointAndOrientation>();
    for (BlockStopTimeIndex stopTimeIndex : stopTimeIndices) {
        for (BlockStopTimeEntry blockStopTime : stopTimeIndex.getStopTimes()) {
            StopTimeEntry stopTime = blockStopTime.getStopTime();
            TripEntry trip = stopTime.getTrip();
            AgencyAndId shapeId = trip.getShapeId();
            if (shapeId == null)
                continue;
            ShapePoints shapePoints = provider.getShapePointsForId(shapeId);
            if (shapePoints == null)
                continue;
            int shapePointIndex = stopTime.getShapePointIndex();
            if (shapePointIndex == -1)
                continue;
            ShapeIdAndDistance key = new ShapeIdAndDistance(shapeId, stopTime.getShapeDistTraveled());
            PointAndOrientation orientation = orientationsByKey.get(key);
            if (orientation == null) {
                int indexFrom = Math.max(0, shapePointIndex - 5);
                int indexTo = Math.min(shapePoints.getSize(), shapePointIndex + 5);
                ShapePointIndex shapePointIndexMethod = new DistanceTraveledShapePointIndex(stopTime.getShapeDistTraveled(), indexFrom, indexTo);
                orientation = shapePointIndexMethod.getPointAndOrientation(shapePoints);
                if (orientation == null)
                    continue;
                orientationsByKey.put(key, orientation);
            }
            pos.add(orientation);
        }
    }
    return orientationsByKey.values();
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) HashMap(java.util.HashMap) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) DoubleArrayList(cern.colt.list.DoubleArrayList) ArrayList(java.util.ArrayList) PointAndOrientation(org.onebusaway.transit_data_federation.impl.shapes.PointAndOrientation) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) ShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.ShapePointIndex) DistanceTraveledShapePointIndex(org.onebusaway.transit_data_federation.impl.shapes.DistanceTraveledShapePointIndex) ProjectedPoint(org.onebusaway.transit_data_federation.model.ProjectedPoint) ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)

Example 14 with BlockStopTimeIndex

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

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

BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)18 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 ArrayList (java.util.ArrayList)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)7 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)7 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Stop (org.onebusaway.gtfs.model.Stop)4 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)4 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)4 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)4 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 Date (java.util.Date)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)3 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)3 AbstractBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.AbstractBlockStopTimeIndex)3 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)3