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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations