Search in sources :

Example 1 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative in project onebusaway-application-modules by camsys.

the class GenerateStopSearchIndexTask method buildIndex.

private void buildIndex() throws IOException, ParseException {
    IndexWriter writer = new IndexWriter(_bundle.getStopSearchIndexPath(), new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
    for (StopEntry stopEntry : _transitGraphDao.getAllStops()) {
        StopNarrative narrative = _narrativeService.getStopForId(stopEntry.getId());
        Document document = getStopAsDocument(stopEntry, narrative);
        writer.addDocument(document);
    }
    writer.optimize();
    writer.close();
    _refreshService.refresh(RefreshableResources.STOP_SEARCH_DATA);
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) Document(org.apache.lucene.document.Document)

Example 2 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative 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 3 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative 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)

Example 4 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative 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 5 with StopNarrative

use of org.onebusaway.transit_data_federation.model.narrative.StopNarrative 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)

Aggregations

StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)7 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)6 Test (org.junit.Test)5 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)4 Stop (org.onebusaway.gtfs.model.Stop)4 BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)4 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)3 StopBean (org.onebusaway.transit_data.model.StopBean)2 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)2 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)2 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)2 ShapePointsFactory (org.onebusaway.transit_data_federation.model.ShapePointsFactory)2 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)2 HashSet (java.util.HashSet)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 Document (org.apache.lucene.document.Document)1 IndexWriter (org.apache.lucene.index.IndexWriter)1 Cacheable (org.onebusaway.container.cache.Cacheable)1 NoSuchStopServiceException (org.onebusaway.exceptions.NoSuchStopServiceException)1 RouteBean (org.onebusaway.transit_data.model.RouteBean)1