Search in sources :

Example 6 with BlockStopTimeIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex in project onebusaway-application-modules by camsys.

the class BlockStopTimeIndicesFactoryTest method test.

@Test
public void test() {
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    StopEntryImpl stopC = stop("c", 47.2, -122.2);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    // 1
    TripEntryImpl tripA1 = trip("a1", "s1");
    TripEntryImpl tripA2 = trip("a2", "s1");
    TripEntryImpl tripA3 = trip("a3", "s1");
    stopTime(0, stopA, tripA1, 0, 10, 0);
    stopTime(0, stopB, tripA1, 20, 20, 0);
    stopTime(0, stopC, tripA2, 30, 30, 0);
    stopTime(0, stopA, tripA2, 40, 40, 0);
    stopTime(0, stopA, tripA3, 50, 50, 0);
    stopTime(0, stopB, tripA3, 60, 70, 0);
    BlockConfigurationEntry bcA = linkBlockTrips(blockA, tripA1, tripA2, tripA3);
    /**
     **
     * Block B - Same trip/stop sequence as A
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB1 = trip("b1", "s1");
    TripEntryImpl tripB2 = trip("b2", "s1");
    TripEntryImpl tripB3 = trip("b3", "s1");
    stopTime(0, stopA, tripB1, 20, 30, 0);
    stopTime(0, stopB, tripB1, 50, 50, 0);
    stopTime(0, stopC, tripB2, 60, 60, 0);
    stopTime(0, stopA, tripB2, 70, 70, 0);
    stopTime(0, stopA, tripB3, 80, 80, 0);
    stopTime(0, stopB, tripB3, 90, 100, 0);
    BlockConfigurationEntry bcB = linkBlockTrips(blockB, tripB1, tripB2, tripB3);
    /**
     **
     * Block C - Same stop sequence, but runs a little bit faster
     ***
     */
    BlockEntryImpl blockC = block("c");
    TripEntryImpl tripC1 = trip("c1", "s1");
    TripEntryImpl tripC2 = trip("c2", "s1");
    TripEntryImpl tripC3 = trip("c3", "s1");
    stopTime(0, stopA, tripC1, 40, 50, 0);
    stopTime(0, stopB, tripC1, 60, 60, 0);
    stopTime(0, stopC, tripC2, 70, 70, 0);
    stopTime(0, stopA, tripC2, 80, 80, 0);
    stopTime(0, stopA, tripC3, 85, 85, 0);
    stopTime(0, stopB, tripC3, 90, 95, 0);
    BlockConfigurationEntry bcC = linkBlockTrips(blockC, tripC1, tripC2, tripC3);
    /**
     **
     * Block D - Same stop sequence, but with different service id
     ***
     */
    BlockEntryImpl blockD = block("d");
    TripEntryImpl tripD1 = trip("d1", "s1");
    TripEntryImpl tripD2 = trip("d2", "s1");
    TripEntryImpl tripD3 = trip("d3", "s2");
    stopTime(0, stopA, tripD1, 40, 50, 0);
    stopTime(0, stopB, tripD1, 70, 70, 0);
    stopTime(0, stopC, tripD2, 80, 80, 0);
    stopTime(0, stopA, tripD2, 90, 90, 0);
    stopTime(0, stopA, tripD3, 100, 100, 0);
    stopTime(0, stopB, tripD3, 110, 120, 0);
    BlockConfigurationEntry bcD = linkBlockTrips(blockD, tripD1, tripD2, tripD3);
    /**
     **
     * Block E - One less stop
     ***
     */
    BlockEntryImpl blockE = block("e");
    TripEntryImpl tripE1 = trip("e1", "s1");
    TripEntryImpl tripE2 = trip("e2", "s1");
    TripEntryImpl tripE3 = trip("e3", "s1");
    stopTime(0, stopA, tripE1, 50, 60, 0);
    stopTime(0, stopB, tripE1, 80, 80, 0);
    stopTime(0, stopC, tripE2, 90, 90, 0);
    stopTime(0, stopA, tripE2, 100, 100, 0);
    stopTime(0, stopA, tripE3, 110, 110, 0);
    BlockConfigurationEntry bcE = linkBlockTrips(blockE, tripE1, tripE2, tripE3);
    /**
     **
     * Block F - Another to group with E, but earlier
     ***
     */
    BlockEntryImpl blockF = block("f");
    TripEntryImpl tripF1 = trip("f1", "s1");
    TripEntryImpl tripF2 = trip("f2", "s1");
    TripEntryImpl tripF3 = trip("f3", "s1");
    stopTime(0, stopA, tripF1, 40, 50, 0);
    stopTime(0, stopB, tripF1, 70, 70, 0);
    stopTime(0, stopC, tripF2, 80, 80, 0);
    stopTime(0, stopA, tripF2, 90, 90, 0);
    stopTime(0, stopA, tripF3, 100, 100, 0);
    BlockConfigurationEntry bcF = linkBlockTrips(blockF, tripF1, tripF2, tripF3);
    BlockStopTimeIndicesFactory factory = new BlockStopTimeIndicesFactory();
    List<BlockStopTimeIndex> allIndices = factory.createIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
    assertEquals(6, allIndices.size());
    List<BlockStopTimeIndex> indices = grep(allIndices, aid("a"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    BlockStopTimeIndex index = indices.get(0);
    assertEquals(15, index.getStopTimes().size());
    assertEquals(bcA.getStopTimes().get(0), index.getStopTimes().get(0));
    assertEquals(bcB.getStopTimes().get(0), index.getStopTimes().get(1));
    assertEquals(bcA.getStopTimes().get(3), index.getStopTimes().get(2));
    assertEquals(bcF.getStopTimes().get(0), index.getStopTimes().get(3));
    assertEquals(bcC.getStopTimes().get(0), index.getStopTimes().get(4));
    assertEquals(bcA.getStopTimes().get(4), index.getStopTimes().get(5));
    assertEquals(bcE.getStopTimes().get(0), index.getStopTimes().get(6));
    assertEquals(bcB.getStopTimes().get(3), index.getStopTimes().get(7));
    assertEquals(bcC.getStopTimes().get(3), index.getStopTimes().get(8));
    assertEquals(bcB.getStopTimes().get(4), index.getStopTimes().get(9));
    assertEquals(bcC.getStopTimes().get(4), index.getStopTimes().get(10));
    assertEquals(bcF.getStopTimes().get(3), index.getStopTimes().get(11));
    assertEquals(bcF.getStopTimes().get(4), index.getStopTimes().get(12));
    assertEquals(bcE.getStopTimes().get(3), index.getStopTimes().get(13));
    assertEquals(bcE.getStopTimes().get(4), index.getStopTimes().get(14));
    indices = grep(allIndices, aid("a"), serviceIds(lsids("s1", "s2"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(3, index.getStopTimes().size());
    assertEquals(bcD.getStopTimes().get(0), index.getStopTimes().get(0));
    assertEquals(bcD.getStopTimes().get(3), index.getStopTimes().get(1));
    assertEquals(bcD.getStopTimes().get(4), index.getStopTimes().get(2));
    indices = grep(allIndices, aid("b"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(8, index.getStopTimes().size());
    assertEquals(bcA.getStopTimes().get(1), index.getStopTimes().get(0));
    assertEquals(bcB.getStopTimes().get(1), index.getStopTimes().get(1));
    assertEquals(bcC.getStopTimes().get(1), index.getStopTimes().get(2));
    assertEquals(bcA.getStopTimes().get(5), index.getStopTimes().get(3));
    assertEquals(bcF.getStopTimes().get(1), index.getStopTimes().get(4));
    assertEquals(bcE.getStopTimes().get(1), index.getStopTimes().get(5));
    assertEquals(bcC.getStopTimes().get(5), index.getStopTimes().get(6));
    assertEquals(bcB.getStopTimes().get(5), index.getStopTimes().get(7));
    indices = grep(allIndices, aid("b"), serviceIds(lsids("s1", "s2"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(2, index.getStopTimes().size());
    assertEquals(bcD.getStopTimes().get(1), index.getStopTimes().get(0));
    assertEquals(bcD.getStopTimes().get(5), index.getStopTimes().get(1));
    indices = grep(allIndices, aid("c"), serviceIds(lsids("s1"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(5, index.getStopTimes().size());
    assertEquals(bcA.getStopTimes().get(2), index.getStopTimes().get(0));
    assertEquals(bcB.getStopTimes().get(2), index.getStopTimes().get(1));
    assertEquals(bcC.getStopTimes().get(2), index.getStopTimes().get(2));
    assertEquals(bcF.getStopTimes().get(2), index.getStopTimes().get(3));
    assertEquals(bcE.getStopTimes().get(2), index.getStopTimes().get(4));
    indices = grep(allIndices, aid("c"), serviceIds(lsids("s1", "s2"), lsids()));
    assertEquals(1, indices.size());
    index = indices.get(0);
    assertEquals(1, index.getStopTimes().size());
    assertEquals(bcD.getStopTimes().get(2), index.getStopTimes().get(0));
}
Also used : BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) AbstractBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.AbstractBlockStopTimeIndex) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockConfigurationEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 7 with BlockStopTimeIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex in project onebusaway-application-modules by camsys.

the class RouteServiceImpl method getRouteCollectionIdsForStop.

@Override
@Cacheable
public Set<AgencyAndId> getRouteCollectionIdsForStop(AgencyAndId stopId) {
    StopEntry stopEntry = _transitGraphDao.getStopEntryForId(stopId);
    if (stopEntry == null)
        throw new InternalErrorServiceException("no such stop: id=" + stopId);
    Set<AgencyAndId> routeCollectionIds = new HashSet<AgencyAndId>();
    List<BlockStopTimeIndex> indices = _blockIndexService.getStopTimeIndicesForStop(stopEntry);
    for (BlockStopTimeIndex blockStopTimeIndex : indices) {
        for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
            TripEntry trip = blockTrip.getTrip();
            routeCollectionIds.add(trip.getRouteCollection().getId());
        }
    }
    List<FrequencyBlockStopTimeIndex> frequencyIndices = _blockIndexService.getFrequencyStopTimeIndicesForStop(stopEntry);
    for (FrequencyBlockStopTimeIndex blockStopTimeIndex : frequencyIndices) {
        for (BlockTripEntry blockTrip : blockStopTimeIndex.getTrips()) {
            TripEntry trip = blockTrip.getTrip();
            routeCollectionIds.add(trip.getRouteCollection().getId());
        }
    }
    return routeCollectionIds;
}
Also used : InternalErrorServiceException(org.onebusaway.exceptions.InternalErrorServiceException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) FrequencyBlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) TripEntry(org.onebusaway.transit_data_federation.services.transit_graph.TripEntry) BlockTripEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry) HashSet(java.util.HashSet) Cacheable(org.onebusaway.container.cache.Cacheable)

Example 8 with BlockStopTimeIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex 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());
}
Also used : ShapePoints(org.onebusaway.transit_data_federation.model.ShapePoints) ShapePointsFactory(org.onebusaway.transit_data_federation.model.ShapePointsFactory) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) Stop(org.onebusaway.gtfs.model.Stop) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) BlockStopTimeEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) Test(org.junit.Test)

Example 9 with BlockStopTimeIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex 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());
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) Test(org.junit.Test)

Example 10 with BlockStopTimeIndex

use of org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex 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());
}
Also used : Stop(org.onebusaway.gtfs.model.Stop) BlockStopTimeIndex(org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex) StopEntry(org.onebusaway.transit_data_federation.services.transit_graph.StopEntry) StopNarrative(org.onebusaway.transit_data_federation.model.narrative.StopNarrative) Test(org.junit.Test)

Aggregations

BlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.BlockStopTimeIndex)18 FrequencyBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockStopTimeIndex)10 StopEntry (org.onebusaway.transit_data_federation.services.transit_graph.StopEntry)10 ArrayList (java.util.ArrayList)7 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)7 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)7 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 Stop (org.onebusaway.gtfs.model.Stop)4 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)4 StopNarrative (org.onebusaway.transit_data_federation.model.narrative.StopNarrative)4 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)4 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)4 TripEntry (org.onebusaway.transit_data_federation.services.transit_graph.TripEntry)4 Date (java.util.Date)3 ServiceDate (org.onebusaway.gtfs.model.calendar.ServiceDate)3 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)3 ShapePoints (org.onebusaway.transit_data_federation.model.ShapePoints)3 AbstractBlockStopTimeIndex (org.onebusaway.transit_data_federation.services.blocks.AbstractBlockStopTimeIndex)3 FrequencyBlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.FrequencyBlockStopTimeEntry)3