Search in sources :

Example 21 with StopEntry

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

the class StopEntriesFactory method processStops.

/**
 * Iterate over each stop, generating a StopEntry for the graph.
 *
 * @param graph
 */
public void processStops(TransitGraphImpl graph) {
    int stopIndex = 0;
    Collection<Stop> stops = _gtfsDao.getAllStops();
    int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(stops.size());
    Map<String, ArrayList<StopEntry>> stopEntriesByAgencyId = new FactoryMap<String, ArrayList<StopEntry>>(new ArrayList<StopEntry>());
    for (Stop stop : stops) {
        if (stopIndex % logInterval == 0)
            _log.info("stops: " + stopIndex + "/" + stops.size());
        stopIndex++;
        StopEntryImpl stopEntry = new StopEntryImpl(stop.getId(), stop.getLat(), stop.getLon());
        stopEntry.setWheelchairBoarding(getWheelchairBoardingAccessibilityForStop(stop));
        graph.putStopEntry(stopEntry);
        stopEntriesByAgencyId.get(stop.getId().getAgencyId()).add(stopEntry);
    }
    for (Map.Entry<String, ArrayList<StopEntry>> entry : stopEntriesByAgencyId.entrySet()) {
        String agencyId = entry.getKey();
        ArrayList<StopEntry> stopEntries = entry.getValue();
        stopEntries.trimToSize();
        AgencyEntryImpl agency = graph.getAgencyForId(agencyId);
        if (agency == null) {
            String msg = null;
            if (stopEntries.size() > 0) {
                msg = "no agency found for agencyId=" + agencyId + " of stop entry " + stopEntries.get(0).getId();
            } else {
                msg = "no agency found for agencyId=" + agencyId + " of empty stop entry list.";
            }
            _log.error(msg);
            throw new IllegalStateException(msg);
        }
        agency.setStops(stopEntries);
    }
    graph.refreshStopMapping();
}
Also used : FactoryMap(org.onebusaway.collections.FactoryMap) Stop(org.onebusaway.gtfs.model.Stop) ArrayList(java.util.ArrayList) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Map(java.util.Map) FactoryMap(org.onebusaway.collections.FactoryMap)

Example 22 with StopEntry

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

the class ArrivalAndDepartureServiceImpl method isMatch.

private boolean isMatch(List<StopTimeEntry> stopTimes, AgencyAndId stopId, int index) {
    if (index < 0 || index >= stopTimes.size())
        return false;
    StopTimeEntry stopTime = stopTimes.get(index);
    StopEntry stop = stopTime.getStop();
    return stop.getId().equals(stopId);
}
Also used : StopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)

Example 23 with StopEntry

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

the class RouteServiceImpl method getRouteCollectionIdsForStop.

@Override
@Cacheable
public Set<AgencyAndId> getRouteCollectionIdsForStop(AgencyAndId stopId) {
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopId);
    if (stopEntry == null)
        throw new InternalErrorServiceException("no such stop: id=" + stopId);
    Set<AgencyAndId> routeCollectionIds = new HashSet<AgencyAndId>();
    List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
    for (BlockStopTimeIndex blockStopTimeIndex : indices) {
        for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
            TripEntry trip = blockTrip.getTrip();
            routeCollectionIds.add(trip.getRouteCollection().getId());
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex blockStopTimeIndex : frequencyIndices) {
        for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
            TripEntry trip = blockTrip.getTrip();
            routeCollectionIds.add(trip.getRouteCollection().getId());
        }
    }
    return routeCollectionIds;
}
Also used : InternalErrorServiceException(org.onebusaway.exceptions.InternalErrorServiceException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) 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) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 24 with StopEntry

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

the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithConflictingDirections.

@Test
public void testGenerateStopNarrativesWithConflictingDirections() {
    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));
    /**
     * Two shapes heading in opposite directions
     */
    AgencyAndId shapeIdA = aid("shapeA");
    ShapePointsFactory factoryA = new ShapePointsFactory();
    factoryA.addPoint(47.661225, -122.3009201);
    factoryA.addPoint(47.664375, -122.3008986);
    ShapePoints shapePointsA = factoryA.create();
    _provider.setShapePointsForId(shapeIdA, shapePointsA);
    AgencyAndId shapeIdB = aid("shapeB");
    ShapePointsFactory factoryB = new ShapePointsFactory();
    factoryB.addPoint(47.664375, -122.3008986);
    factoryB.addPoint(47.661225, -122.3009201);
    ShapePoints shapePointsB = factoryB.create();
    _provider.setShapePointsForId(shapeIdB, shapePointsB);
    TripEntryImpl tripA = trip("tripA");
    tripA.setShapeId(shapeIdA);
    TripEntryImpl tripB = trip("tripB");
    tripB.setShapeId(shapeIdB);
    StopTimeEntryImpl stopTimeA = stopTime(0, stopEntry, tripA, 0, 0.0);
    stopTimeA.setShapePointIndex(0);
    StopTimeEntryImpl stopTimeB = stopTime(0, stopEntry, tripB, 0, 0.0);
    stopTimeB.setShapePointIndex(0);
    BlockStopTimeEntry blockStopTimeA = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeA.getStopTime()).thenReturn(stopTimeA);
    BlockStopTimeEntry blockStopTimeB = Mockito.mock(BlockStopTimeEntry.class);
    Mockito.when(blockStopTimeB.getStopTime()).thenReturn(stopTimeB);
    BlockStopTimeIndex index = Mockito.mock(BlockStopTimeIndex.class);
    Mockito.when(index.getStopTimes()).thenReturn(Arrays.asList(blockStopTimeA, blockStopTimeB));
    List<BlockStopTimeIndex> indices = Arrays.asList(index);
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
    _task.generateStopNarratives(_provider);
    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertNull(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 25 with StopEntry

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

the class GenerateNarrativesTaskTest method testGenerateStopNarrativesWithHardCodedDirection.

@Test
public void testGenerateStopNarrativesWithHardCodedDirection() {
    StopEntry stopEntry = stop("stopA", 47.0, -122.0);
    Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopEntry));
    Stop stop = new Stop();
    stop.setId(stopEntry.getId());
    stop.setDirection("west");
    Mockito.when(_gtfsDao.getAllStops()).thenReturn(Arrays.asList(stop));
    List<BlockStopTimeIndex> indices = Collections.emptyList();
    Mockito.when(_blockIndexService.getStopTimeIndicesForStop(stopEntry)).thenReturn(indices);
    _task.generateStopNarratives(_provider);
    StopNarrative narrative = _provider.getNarrativeForStopId(stopEntry.getId());
    assertEquals("W", narrative.getDirection());
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) 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) Test(org.junit.Test)

Aggregations

StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)54 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)28 ArrayList (java.util.ArrayList)15 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)14 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)12 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)12 StopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopTimeEntry)12 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)10 List (java.util.List)9 FactoryMap (org.onebusaway.collections.FactoryMap)9 HashMap (java.util.HashMap)8 Map (java.util.Map)8 Test (org.junit.Test)8 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)8 HashSet (java.util.HashSet)7 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)7 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)7 Cacheable (org.onebusaway.container.cache.Cacheable)6 Stop (org.onebusaway.gtfs.model.Stop)6 StopBean (org.onebusaway.transit_data.model.StopBean)4