use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibrary method checkFirstAndLastStop.
/**
* Special check for an issue with start points where the first stop isn't all
* that near the start of the shape (the first stop being more of a layover
* point). If the shape is working against us, the closest point for the first
* stop can be a point further along the shape, which causes problems.
*/
private void checkFirstAndLastStop(List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments, ShapePoints shapePoints, UTMProjection projection, List<XYPoint> projectedShapePoints) {
if (possibleAssignments.size() >= 2) {
PointAndIndex first = possibleAssignments.get(0).get(0);
PointAndIndex second = possibleAssignments.get(1).get(0);
if (first.distanceAlongShape > second.distanceAlongShape) {
StopTimeEntryImpl firstStopTime = stopTimes.get(0);
_log.warn("snapping first stop time id=" + firstStopTime.getId() + " to start of shape");
XYPoint point = projectedShapePoints.get(0);
StopEntryImpl stop = firstStopTime.getStop();
XYPoint stopPoint = projection.forward(stop.getStopLocation());
double d = stopPoint.getDistance(point);
possibleAssignments.get(0).add(new PointAndIndex(point, 0, d, 0.0));
}
int n = possibleAssignments.size();
PointAndIndex prev = possibleAssignments.get(n - 2).get(0);
PointAndIndex last = possibleAssignments.get(n - 1).get(0);
if (prev.distanceAlongShape > last.distanceAlongShape) {
}
}
if (possibleAssignments.size() > 0) {
/**
* We snap the last stop to the end of the shape and add it to the set of
* possible assignments. In the worst case, it will be a higher-scoring
* assignment and ignored, but it can help in cases where the stop was
* weirdly assigned.
*/
PointAndIndex lastSnapped = getLastStopSnappedToEndOfShape(stopTimes, shapePoints, projection, projectedShapePoints);
possibleAssignments.get(possibleAssignments.size() - 1).add(lastSnapped);
}
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class StopTimeEntriesFactory method createInitialStopTimeEntries.
private List<StopTimeEntryImpl> createInitialStopTimeEntries(TransitGraphImpl graph, List<StopTime> stopTimes) {
List<StopTimeEntryImpl> stopTimeEntries = new ArrayList<StopTimeEntryImpl>(stopTimes.size());
int sequence = 0;
for (StopTime stopTime : stopTimes) {
if (stopTime == null) {
_log.error("Found null stopTime in stopTime=" + stopTimes);
continue;
}
Stop stop = stopTime.getStop();
if (stop == null) {
_log.error("Stop is null for stopTime" + stopTime.getId());
continue;
}
if (stop.getId() == null) {
_log.error("Stop id is null for stopTime" + stopTime + ", stop=" + stop);
continue;
}
AgencyAndId stopId = stop.getId();
StopEntryImpl stopEntry = graph.getStopEntryForId(stopId);
StopTimeEntryImpl stopTimeEntry = new StopTimeEntryImpl();
stopTimeEntry.setId(stopTime.getId());
stopTimeEntry.setSequence(sequence);
stopTimeEntry.setGtfsSequence(stopTime.getStopSequence());
stopTimeEntry.setDropOffType(stopTime.getDropOffType());
stopTimeEntry.setPickupType(stopTime.getPickupType());
stopTimeEntry.setStop(stopEntry);
stopTimeEntries.add(stopTimeEntry);
sequence++;
}
return stopTimeEntries;
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl 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.impl.transit_graph.StopEntryImpl in project onebusaway-application-modules by camsys.
the class BlockConfigurationEntryImplTest method test.
@Test
public void test() {
ServiceIdActivation serviceIds = serviceIds(lsids("sA"), lsids("sB"));
StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
StopEntryImpl stopB = stop("stopB", 47.1, -122.0);
BlockEntryImpl block = block("blockA");
TripEntryImpl tripA = trip("tripA", 1000);
TripEntryImpl tripB = trip("tripB", 2000);
TripEntryImpl tripC = trip("tripB", 1500);
List<TripEntry> trips = Arrays.asList((TripEntry) tripA, tripB, tripC);
StopTimeEntryImpl st1 = stopTime(1, stopA, tripA, time(6, 30), time(6, 35), 200);
StopTimeEntryImpl st2 = stopTime(2, stopB, tripA, time(7, 00), time(7, 10), 800);
StopTimeEntryImpl st3 = stopTime(3, stopB, tripB, time(7, 30), time(7, 35), 400);
StopTimeEntryImpl st4 = stopTime(4, stopA, tripB, time(8, 00), time(8, 07), 1600);
StopTimeEntryImpl st5 = stopTime(5, stopA, tripC, time(8, 30), time(8, 35), 300);
StopTimeEntryImpl st6 = stopTime(6, stopB, tripC, time(9, 00), time(9, 02), 1200);
Builder builder = BlockConfigurationEntryImpl.builder();
builder.setBlock(block);
builder.setTrips(trips);
builder.setServiceIds(serviceIds);
builder.setTripGapDistances(new double[] { 10.0, 20.0, 0.0 });
BlockConfigurationEntry entry = builder.create();
assertSame(block, entry.getBlock());
assertSame(serviceIds, entry.getServiceIds());
assertEquals(4530.0, entry.getTotalBlockDistance(), 0.0);
/**
**
* Trips
***
*/
List<BlockTripEntry> blockTrips = entry.getTrips();
assertEquals(3, blockTrips.size());
BlockTripEntry blockTrip = blockTrips.get(0);
assertEquals(0, blockTrip.getSequence());
assertEquals(0, blockTrip.getAccumulatedStopTimeIndex());
assertEquals(0, blockTrip.getAccumulatedSlackTime());
assertEquals(0.0, blockTrip.getDistanceAlongBlock(), 0.0);
assertSame(blockTrips.get(1), blockTrip.getNextTrip());
assertNull(blockTrip.getPreviousTrip());
blockTrip = blockTrips.get(1);
assertEquals(1, blockTrip.getSequence());
assertEquals(2, blockTrip.getAccumulatedStopTimeIndex());
assertEquals(15 * 60, blockTrip.getAccumulatedSlackTime());
assertEquals(1010.0, blockTrip.getDistanceAlongBlock(), 0.0);
assertSame(blockTrips.get(2), blockTrip.getNextTrip());
assertSame(blockTrips.get(0), blockTrip.getPreviousTrip());
blockTrip = blockTrips.get(2);
assertEquals(2, blockTrip.getSequence());
assertEquals(4, blockTrip.getAccumulatedStopTimeIndex());
assertEquals(35 * 60, blockTrip.getAccumulatedSlackTime());
assertEquals(3030.0, blockTrip.getDistanceAlongBlock(), 0.0);
assertNull(blockTrip.getNextTrip());
assertSame(blockTrips.get(1), blockTrip.getPreviousTrip());
/**
**
* Stop Times
***
*/
List<BlockStopTimeEntry> stopTimes = entry.getStopTimes();
assertEquals(6, stopTimes.size());
BlockStopTimeEntry bst = stopTimes.get(0);
assertEquals(0, bst.getAccumulatedSlackTime());
assertEquals(0, bst.getBlockSequence());
assertEquals(200, bst.getDistanceAlongBlock(), 0.0);
assertSame(st1, bst.getStopTime());
assertSame(blockTrips.get(0), bst.getTrip());
bst = stopTimes.get(1);
assertEquals(300, bst.getAccumulatedSlackTime());
assertEquals(1, bst.getBlockSequence());
assertEquals(800, bst.getDistanceAlongBlock(), 0.0);
assertSame(st2, bst.getStopTime());
assertSame(blockTrips.get(0), bst.getTrip());
bst = stopTimes.get(2);
assertEquals(15 * 60, bst.getAccumulatedSlackTime());
assertEquals(2, bst.getBlockSequence());
assertEquals(1410, bst.getDistanceAlongBlock(), 0.0);
assertSame(st3, bst.getStopTime());
assertSame(blockTrips.get(1), bst.getTrip());
bst = stopTimes.get(3);
assertEquals(20 * 60, bst.getAccumulatedSlackTime());
assertEquals(3, bst.getBlockSequence());
assertEquals(2610, bst.getDistanceAlongBlock(), 0.0);
assertSame(st4, bst.getStopTime());
assertSame(blockTrips.get(1), bst.getTrip());
bst = stopTimes.get(4);
assertEquals(35 * 60, bst.getAccumulatedSlackTime());
assertEquals(4, bst.getBlockSequence());
assertEquals(3330, bst.getDistanceAlongBlock(), 0.0);
assertSame(st5, bst.getStopTime());
assertSame(blockTrips.get(2), bst.getTrip());
bst = stopTimes.get(5);
assertEquals(40 * 60, bst.getAccumulatedSlackTime());
assertEquals(5, bst.getBlockSequence());
assertEquals(4230, bst.getDistanceAlongBlock(), 0.0);
assertSame(st6, bst.getStopTime());
assertSame(blockTrips.get(2), bst.getTrip());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl 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));
}
Aggregations