Search in sources :

Example 26 with StopEntry

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

the class GenerateNarrativesTaskTest method testGenerateStopNarratives.

@Test
public void testGenerateStopNarratives() {
    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.setCode("A");
    stop.setDesc("Stop A is the best");
    stop.setLat(stopEntry.getStopLat());
    stop.setLon(stopEntry.getStopLon());
    stop.setName("Stop A");
    stop.setUrl("http://agency.gov/stop-a");
    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(stop.getCode(), narrative.getCode());
    assertEquals(stop.getDesc(), narrative.getDescription());
    assertNull(narrative.getDirection());
    assertEquals(stop.getLocationType(), narrative.getLocationType());
    assertEquals(stop.getName(), narrative.getName());
    assertEquals(stop.getUrl(), narrative.getUrl());
}
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)

Example 27 with StopEntry

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

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

the class ScheduledServiceServiceImpl method stopHasUpcomingScheduledService.

@Override
public Boolean stopHasUpcomingScheduledService(String stopAgencyId, long time, 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(stopAgencyId, stopId);
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopAndId);
    if (stopEntry == null) {
        return null;
    }
    Date serviceStart = new Date(time - SCHEDULE_WINDOW_BEFORE);
    Date serviceEnd = new Date(time + SCHEDULE_WINDOW_AFTER);
    List<StopTimeInstance> stis = _stopTimeService.getStopTimeInstancesInTimeRange(stopEntry, serviceStart, serviceEnd, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED);
    if (stis.isEmpty()) {
        return false;
    }
    for (StopTimeInstance stopTime : stis) {
        BlockTripEntry blockTripEntry = stopTime.getTrip();
        TripEntry tripEntry = blockTripEntry.getTrip();
        if (tripEntry.getRoute().getId().toString().equals(routeId)) {
            if (tripEntry.getDirectionId() == null || tripEntry.getDirectionId().equals(directionId)) {
                return true;
            }
        }
    }
    return false;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) 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) Date(java.util.Date)

Example 29 with StopEntry

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

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

the class TransitGraphImpl method initialize.

public void initialize() {
    if (_stopLocationTree == null) {
        System.out.println("initializing transit graph...");
        if (_stops.size() == 0) {
            _log.warn("no stops found for graph");
        } else {
            _stopLocationTree = new STRtree(_stops.size());
            for (int i = 0; i < _stops.size(); i++) {
                StopEntry stop = _stops.get(i);
                double x = stop.getStopLon();
                double y = stop.getStopLat();
                Envelope r = new Envelope(x, x, y, y);
                _stopLocationTree.insert(r, stop);
            }
            _stopLocationTree.build();
        }
        System.out.println("  stops=" + _stops.size());
        System.out.println("  trips= " + _trips.size());
    }
    if (_agencyEntriesById == null || _agencyEntriesById.size() < _agencies.size()) {
        refreshAgencyMapping();
    }
    if (_tripEntriesById == null || _tripEntriesById.size() < _trips.size()) {
        refreshTripMapping();
    }
    if (_blockEntriesById == null || _blockEntriesById.size() < _blocks.size()) {
        refreshBlockMapping();
    }
    if (_stopEntriesById == null || _stopEntriesById.size() < _stops.size())
        refreshStopMapping();
    if (_routeCollectionEntriesById == null || _routeCollectionEntriesById.size() < _routeCollections.size())
        refreshRouteCollectionMapping();
    if (_routeEntriesById == null || _routeEntriesById.size() < _routes.size())
        refreshRouteMapping();
    int i = 0;
    for (StopEntryImpl stop : _stops) stop.setIndex(i++);
}
Also used : STRtree(com.vividsolutions.jts.index.strtree.STRtree) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) Envelope(com.vividsolutions.jts.geom.Envelope)

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