use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class ArrivalsAndDeparturesBeanServiceImpl method getArrivalsAndDeparturesByStopId.
/**
**
* {@link ArrivalsAndDeparturesBeanService} Interface
***
*/
@Override
public List<ArrivalAndDepartureBean> getArrivalsAndDeparturesByStopId(AgencyAndId stopId, ArrivalsAndDeparturesQueryBean query) {
StopEntry stop = _transitGraphDao.getStopEntryForId(stopId, true);
long time = query.getTime();
int minutesBefore = Math.max(query.getMinutesBefore(), query.getFrequencyMinutesBefore());
int minutesAfter = Math.max(query.getMinutesAfter(), query.getFrequencyMinutesAfter());
long fromTime = time - minutesBefore * 60 * 1000;
long toTime = time + minutesAfter * 60 * 1000;
long nonFrequencyFromTime = time - query.getMinutesBefore() * 60 * 1000;
long nonFrequencyToTime = time + query.getMinutesAfter() * 60 * 1000;
long frequencyFromTime = time - query.getFrequencyMinutesBefore() * 60 * 1000;
long frequencyToTime = time + query.getFrequencyMinutesAfter() * 60 * 1000;
TargetTime target = new TargetTime(time, time);
List<ArrivalAndDepartureInstance> instances = _arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stop, target, fromTime, toTime);
List<ArrivalAndDepartureBean> beans = new ArrayList<ArrivalAndDepartureBean>();
Map<AgencyAndId, StopBean> stopBeanCache = new HashMap<AgencyAndId, StopBean>();
for (ArrivalAndDepartureInstance instance : instances) {
FrequencyEntry frequency = instance.getFrequency();
long from = frequency != null ? frequencyFromTime : nonFrequencyFromTime;
long to = frequency != null ? frequencyToTime : nonFrequencyToTime;
if (!isArrivalAndDepartureInRange(instance, from, to))
continue;
ArrivalAndDepartureBean bean = getStopTimeInstanceAsBean(time, instance, stopBeanCache);
applyBlockLocationToBean(instance, bean, time);
Boolean isNegativeScheduledArrivalsEnabled = _gtfsRealtimeNegativeArrivals.getShowNegativeScheduledArrivalByAgencyId(instance.getBlockTrip().getTrip().getId().getAgencyId());
if (isNegativeScheduledArrivalsEnabled != null && !isNegativeScheduledArrivalsEnabled && bean.getNumberOfStopsAway() < 0 && bean.getPredictedArrivalTime() <= 0)
continue;
applySituationsToBean(time, instance, bean);
beans.add(bean);
}
Collections.sort(beans, new ArrivalAndDepartureComparator());
return beans;
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class GenerateStopSearchIndexTaskTest method testGenerateStopSearchIndex.
@Test
public void testGenerateStopSearchIndex() throws CorruptIndexException, IOException, ParseException {
StopEntryImpl stopA = stop("111", 0, 0);
StopEntryImpl stopB = stop("222", 0, 0);
StopEntryImpl stopC = stop("333", 0, 0);
StopNarrative.Builder stopNarrativeA = StopNarrative.builder();
stopNarrativeA.setCode("111");
stopNarrativeA.setName("AAA Station");
StopNarrative.Builder stopNarrativeB = StopNarrative.builder();
stopNarrativeB.setName("BBB Station");
StopNarrative.Builder stopNarrativeC = StopNarrative.builder();
stopNarrativeC.setCode("444");
stopNarrativeC.setName("CCC Station");
Mockito.when(_transitGraphDao.getAllStops()).thenReturn(Arrays.asList((StopEntry) stopA, stopB, stopC));
Mockito.when(_narrativeService.getStopForId(stopA.getId())).thenReturn(stopNarrativeA.create());
Mockito.when(_narrativeService.getStopForId(stopB.getId())).thenReturn(stopNarrativeB.create());
Mockito.when(_narrativeService.getStopForId(stopC.getId())).thenReturn(stopNarrativeC.create());
_task.run();
StopSearchServiceImpl searchService = new StopSearchServiceImpl();
searchService.setBundle(_bundle);
searchService.initialize();
SearchResult<AgencyAndId> ids = searchService.searchForStopsByCode("111", 10, MIN_SCORE);
assertEquals(1, ids.size());
assertEquals(new AgencyAndId("1", "111"), ids.getResult(0));
ids = searchService.searchForStopsByCode("222", 10, MIN_SCORE);
assertEquals(1, ids.size());
assertTrue(ids.getResults().contains(new AgencyAndId("1", "222")));
ids = searchService.searchForStopsByCode("333", 10, MIN_SCORE);
assertEquals(0, ids.size());
ids = searchService.searchForStopsByCode("444", 10, MIN_SCORE);
assertEquals(1, ids.size());
assertTrue(ids.getResults().contains(new AgencyAndId("1", "333")));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class ShapeGeospatialIndexTaskTest method test.
@Test
public void test() throws IOException, ClassNotFoundException {
ShapeGeospatialIndexTask task = new ShapeGeospatialIndexTask();
File path = File.createTempFile(ShapeGeospatialIndexTaskTest.class.getName(), ".tmp");
path.delete();
path.deleteOnExit();
FederatedTransitDataBundle bundle = Mockito.mock(FederatedTransitDataBundle.class);
Mockito.when(bundle.getShapeGeospatialIndexDataPath()).thenReturn(path);
task.setBundle(bundle);
RefreshService refreshService = Mockito.mock(RefreshService.class);
task.setRefreshService(refreshService);
ShapePointHelper shapePointHelper = Mockito.mock(ShapePointHelper.class);
task.setShapePointHelper(shapePointHelper);
TransitGraphDao transitGraphDao = Mockito.mock(TransitGraphDao.class);
task.setTransitGraphDao(transitGraphDao);
StopEntry stopA = stop("stopA", 47.65, -122.32);
StopEntry stopB = stop("stopB", 47.67, -122.30);
Mockito.when(transitGraphDao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
TripEntryImpl tripA = trip("tripA");
AgencyAndId shapeIdA = aid("shapeA");
tripA.setShapeId(shapeIdA);
TripEntryImpl tripB = trip("tripB");
AgencyAndId shapeIdB = aid("shapeB");
tripB.setShapeId(shapeIdB);
Mockito.when(transitGraphDao.getAllTrips()).thenReturn(Arrays.asList((TripEntry) tripA, tripB));
ShapePointsFactory factory = new ShapePointsFactory();
factory.addPoint(47.652300128129454, -122.30622018270873);
factory.addPoint(47.653181844549394, -122.30523312979125);
factory.addPoint(47.654265901710744, -122.30511511259459);
ShapePoints shapeA = factory.create();
factory = new ShapePointsFactory();
factory.addPoint(47.661275594717026, -122.31189573698424);
factory.addPoint(47.661347854692465, -122.3240622370758);
factory.addPoint(47.661368177792546, -122.32508885257624);
factory.addPoint(47.66496659665593, -122.32501375072383);
ShapePoints shapeB = factory.create();
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdA)).thenReturn(shapeA);
Mockito.when(shapePointHelper.getShapePointsForShapeId(shapeIdB)).thenReturn(shapeB);
task.run();
Mockito.verify(refreshService).refresh(RefreshableResources.SHAPE_GEOSPATIAL_INDEX);
Map<CoordinateBounds, List<AgencyAndId>> shapeIdsByBounds = ObjectSerializationLibrary.readObject(path);
assertEquals(5, shapeIdsByBounds.size());
CoordinateBounds b = new CoordinateBounds(47.65048049686506, -122.30767397879845, 47.654977097836735, -122.300997795721);
assertEquals(Arrays.asList(shapeIdA), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.65947369880841, -122.32102634495334, 47.66397029978009, -122.3143501618759);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.66397029978009, -122.32770252803078, 47.66846690075177, -122.32102634495334);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.65947369880841, -122.3143501618759, 47.66397029978009, -122.30767397879845);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
b = new CoordinateBounds(47.65947369880841, -122.32770252803078, 47.66397029978009, -122.32102634495334);
assertEquals(Arrays.asList(shapeIdB), shapeIdsByBounds.get(b));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class StopEntriesFactoryTest method test.
@Test
public void test() {
Stop stopA = new Stop();
stopA.setId(new AgencyAndId("1", "stopA"));
stopA.setCode("A");
stopA.setDesc("Stop A Description");
stopA.setLat(47.0);
stopA.setLon(-122.0);
stopA.setLocationType(0);
stopA.setName("Stop A");
Stop stopB = new Stop();
stopB.setId(new AgencyAndId("1", "stopB"));
stopB.setCode("B");
stopB.setDesc("Stop B Description");
stopB.setLat(47.1);
stopB.setLon(-122.1);
stopB.setLocationType(0);
stopB.setName("Stop B");
GtfsRelationalDao dao = Mockito.mock(GtfsRelationalDao.class);
Mockito.when(dao.getAllStops()).thenReturn(Arrays.asList(stopA, stopB));
StopEntriesFactory factory = new StopEntriesFactory();
factory.setGtfsDao(dao);
TransitGraphImpl graph = new TransitGraphImpl();
AgencyEntryImpl agency = new AgencyEntryImpl();
agency.setId("1");
graph.putAgencyEntry(agency);
graph.refreshAgencyMapping();
factory.processStops(graph);
StopEntryImpl stopEntryA = graph.getStopEntryForId(stopA.getId());
assertEquals(stopA.getId(), stopEntryA.getId());
assertEquals(stopA.getLat(), stopEntryA.getStopLat(), 0);
assertEquals(stopA.getLon(), stopEntryA.getStopLon(), 0);
StopEntryImpl stopEntryB = graph.getStopEntryForId(stopB.getId());
assertEquals(stopB.getId(), stopEntryB.getId());
assertEquals(stopB.getLat(), stopEntryB.getStopLat(), 0);
assertEquals(stopB.getLon(), stopEntryB.getStopLon(), 0);
List<StopEntry> stops = graph.getAllStops();
assertEquals(2, stops.size());
assertTrue(stops.contains(stopEntryA));
assertTrue(stops.contains(stopEntryB));
stops = agency.getStops();
assertTrue(stops.contains(stopEntryA));
assertTrue(stops.contains(stopEntryB));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.StopEntry in project onebusaway-application-modules by camsys.
the class StopGraphComparator method getMaxDistance.
private double getMaxDistance(StopEntry stop, Set<StopEntry> visited) {
Double d = _maxDistance.get(stop);
if (d != null)
return d;
if (!visited.add(stop))
throw new IllegalStateException("cycle");
double dMax = 0.0;
for (StopEntry next : _graph.getOutboundNodes(stop)) {
double potential = SphericalGeometryLibrary.distance(stop.getStopLat(), stop.getStopLon(), next.getStopLat(), next.getStopLon()) + getMaxDistance(next, visited);
if (potential > dMax)
dMax = potential;
}
_maxDistance.put(stop, dMax);
return dMax;
}
Aggregations