Search in sources :

Example 26 with StopEntryImpl

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);
    }
}
Also used : XYPoint(org.onebusaway.geospatial.model.XYPoint) PointAndIndex(org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) XYPoint(org.onebusaway.geospatial.model.XYPoint) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 27 with StopEntryImpl

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;
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) ArrayList(java.util.ArrayList) CoordinatePoint(org.onebusaway.geospatial.model.CoordinatePoint) StopTime(org.onebusaway.gtfs.model.StopTime) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)

Example 28 with StopEntryImpl

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")));
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopSearchServiceImpl(org.onebusaway.transit_data_federation.impl.StopSearchServiceImpl) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 29 with StopEntryImpl

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());
}
Also used : StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) Builder(org.onebusaway.transit_data_federation.impl.transit_graph.BlockConfigurationEntryImpl.Builder) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) Test(org.junit.Test)

Example 30 with StopEntryImpl

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));
}
Also used : GtfsRelationalDao(org.onebusaway.gtfs.services.GtfsRelationalDao) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) AgencyEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.AgencyEntryImpl) TransitGraphImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TransitGraphImpl) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopEntriesFactory(org.onebusaway.transit_data_federation.bundle.tasks.transit_graph.StopEntriesFactory) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Aggregations

StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)33 Test (org.junit.Test)23 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)22 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)16 StopTimeEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl)12 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)11 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)7 ArrayList (java.util.ArrayList)6 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)6 CoordinatePoint (org.onebusaway.geospatial.model.CoordinatePoint)5 Stop (org.onebusaway.gtfs.model.Stop)5 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5 XYPoint (org.onebusaway.geospatial.model.XYPoint)4 PointAndIndex (org.onebusaway.transit_data_federation.impl.shapes.PointAndIndex)4 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)4 FrequencyBlockTripIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex)4 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)4 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)4