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