Search in sources :

Example 26 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a loop route with a single trip and two stops in a block
 * Stop A is visited twice in the route
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *    A           1             2
 *
 * @param timepointPredictions real-time predictions to apply to the
 *          BlockLocationServiceImpl
 * @param stop stop_id for this stop is used to call getArrivalsAndDeparturesForStopInTimeRange()
 * @return a list of ArrivalAndDepartureInstances which is used to access
 *         predicted arrival/departure times for a stop, for comparison
 *         against the expected values
 */
private List<ArrivalAndDepartureInstance> getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions, StopEntryImpl stop) {
    TargetTime target = new TargetTime(mCurrentTime, mCurrentTime);
    // Setup block
    BlockEntryImpl block = block("blockA");
    stopTime(0, mStopA, mTrip1, time(13, 30), time(13, 35), 1000);
    stopTime(1, mStopB, mTrip1, time(13, 45), time(13, 50), 2000);
    stopTime(2, mStopA, mTrip1, time(13, 55), time(13, 55), 2000);
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA"), lsids()), mTrip1);
    BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
    BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(2);
    // Setup block location instance for trip B
    BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstance);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    blockLocationB.setTimepointPredictions(timepointPredictions);
    // Mock StopTimeInstance with time frame
    long stopTimeFrom = dateAsLong("2015-07-23 00:00");
    long stopTimeTo = dateAsLong("2015-07-24 00:00");
    StopTimeInstance sti1 = new StopTimeInstance(bstAA, blockInstance.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationB);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstAB, blockInstance.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    StopTimeInstance sti3 = new StopTimeInstance(bstBA, blockInstance.getState());
    ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
    in3.setBlockLocation(blockLocationB);
    in3.setPredictedArrivalTime((long) (in3.getScheduledArrivalTime()));
    in3.setPredictedDepartureTime((long) (in3.getScheduledDepartureTime()));
    Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
    Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
    Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(stop, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2, sti3));
    // Create and add vehicle location record cache
    VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
    VehicleLocationRecord vlr = new VehicleLocationRecord();
    vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
    vlr.setTripId(mTrip1.getId());
    vlr.setTimepointPredictions(blockLocationB.getTimepointPredictions());
    vlr.setTimeOfRecord(mCurrentTime);
    vlr.setVehicleId(new AgencyAndId("1", "123"));
    // Create ScheduledBlockLocation for cache
    ScheduledBlockLocation sbl = new ScheduledBlockLocation();
    sbl.setActiveTrip(blockLocationB.getActiveTrip());
    // Add data to cache
    _cache.addRecord(blockInstance, vlr, sbl, null);
    _blockLocationService.setVehicleLocationRecordCache(_cache);
    ScheduledBlockLocationServiceImpl scheduledBlockLocationServiceImpl = new ScheduledBlockLocationServiceImpl();
    _blockLocationService.setScheduledBlockLocationService(scheduledBlockLocationServiceImpl);
    // Call ArrivalAndDepartureService
    return _service.getArrivalsAndDeparturesForStopInTimeRange(stop, target, stopTimeFrom, stopTimeTo);
}
Also used : AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) VehicleLocationRecordCacheImpl(org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) Date(java.util.Date) ScheduledBlockLocation(org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) VehicleLocationRecord(org.onebusaway.realtime.api.VehicleLocationRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) ScheduledBlockLocationServiceImpl(org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl) 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)

Example 27 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class ArrivalsAndDeparturesBeanServiceImplTest method test.

@Test
public void test() {
    long t = dateAsLong("2010-10-05 16:30");
    long serviceDate = dateAsLong("2010-10-05 00:00");
    int minutesBefore = 5;
    int minutesAfter = 30;
    StopEntryImpl stopA = stop("stopA", 47.0, -122.0);
    StopEntryImpl stopB = stop("stopB", 47.0, -122.0);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopA.getId(), true)).thenReturn(stopA);
    Mockito.when(_transitGraphDao.getStopEntryForId(stopB.getId(), true)).thenReturn(stopB);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("blockA");
    TripEntryImpl tripA = trip("tripA", "sA", 3000);
    stopTime(0, stopA, tripA, time(16, 30), time(16, 35), 1000);
    StopTimeEntryImpl stopTimeAB = stopTime(1, stopB, tripA, time(16, 40), time(16, 45), 2000);
    BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds(lsids("sA"), lsids()), tripA);
    BlockStopTimeEntry bstAA = blockConfigA.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfigA.getStopTimes().get(1);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("blockB");
    TripEntryImpl tripB = trip("tripB", "sA", 3000);
    stopTime(2, stopA, tripB, time(16, 40), time(16, 45), 1000);
    StopTimeEntryImpl stopTimeBB = stopTime(3, stopB, tripB, time(16, 50), time(16, 55), 2000);
    BlockConfigurationEntry blockConfigB = blockConfiguration(blockB, serviceIds(lsids("sA"), lsids()), tripB);
    BlockStopTimeEntry bstBA = blockConfigB.getStopTimes().get(0);
    BlockStopTimeEntry bstBB = blockConfigB.getStopTimes().get(1);
    /**
     **
     *
     ***
     */
    BlockInstance blockInstanceA = new BlockInstance(blockConfigA, serviceDate);
    long lastUpdateTime = dateAsLong("2010-10-05 16:15");
    BlockLocation blockLocationA = new BlockLocation();
    blockLocationA.setActiveTrip(bstAA.getTrip());
    blockLocationA.setBlockInstance(blockInstanceA);
    blockLocationA.setClosestStop(bstAA);
    blockLocationA.setDistanceAlongBlock(500);
    blockLocationA.setInService(true);
    blockLocationA.setLastUpdateTime(lastUpdateTime);
    blockLocationA.setNextStop(bstAA);
    blockLocationA.setPredicted(true);
    blockLocationA.setScheduledDistanceAlongBlock(600);
    blockLocationA.setScheduleDeviation(10 * 60);
    blockLocationA.setVehicleId(aid("vehicle"));
    /**
     **
     *
     ***
     */
    BlockInstance blockInstanceB = new BlockInstance(blockConfigB, serviceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBA.getTrip());
    blockLocationB.setBlockInstance(blockInstanceA);
    blockLocationB.setClosestStop(bstBA);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstAA);
    blockLocationB.setPredicted(false);
    blockLocationB.setScheduledDistanceAlongBlock(400);
    /**
     **
     *
     ***
     */
    long stopTimeFrom = t - minutesBefore * 60 * 1000;
    long stopTimeTo = t + minutesAfter * 60 * 1000;
    StopTimeInstance sti1 = new StopTimeInstance(bstAB, blockInstanceA.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationA);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime() + 5 * 60 * 1000));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstBB, blockInstanceB.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    TargetTime target = new TargetTime(t, t);
    Mockito.when(_arrivalAndDepartureService.getArrivalsAndDeparturesForStopInTimeRange(stopB, target, stopTimeFrom, stopTimeTo)).thenReturn(Arrays.asList(in1, in2));
    /**
     **
     *
     ***
     */
    Builder stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setStopHeadsign("Downtown");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeAB)).thenReturn(stopTimeNarrative.create());
    stopTimeNarrative = StopTimeNarrative.builder();
    stopTimeNarrative.setRouteShortName("XX");
    Mockito.when(_narrativeService.getStopTimeForEntry(stopTimeBB)).thenReturn(stopTimeNarrative.create());
    /**
     **
     *
     ***
     */
    StopBean stopABean = new StopBean();
    stopABean.setId("1_stopA");
    Mockito.when(_stopBeanService.getStopForId(stopA.getId())).thenReturn(stopABean);
    StopBean stopBBean = new StopBean();
    stopBBean.setId("1_stopB");
    Mockito.when(_stopBeanService.getStopForId(stopB.getId())).thenReturn(stopBBean);
    /**
     **
     *
     ***
     */
    TripBean tripABean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripA"))).thenReturn(tripABean);
    TripBean tripBBean = new TripBean();
    Mockito.when(_tripBeanService.getTripForId(aid("tripB"))).thenReturn(tripBBean);
    /**
     **
     *
     ***
     */
    TripStatusBean tripStatusBeanA = new TripStatusBean();
    TripStatusBean tripStatusBeanB = new TripStatusBean();
    Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationA, t)).thenReturn(tripStatusBeanA);
    Mockito.when(_tripDetailsBeanService.getBlockLocationAsStatusBean(blockLocationB, t)).thenReturn(tripStatusBeanB);
    /**
     **
     *
     ***
     */
    ArrivalsAndDeparturesQueryBean query = new ArrivalsAndDeparturesQueryBean();
    query.setTime(t);
    query.setMinutesBefore(minutesBefore);
    query.setMinutesAfter(minutesAfter);
    query.setFrequencyMinutesBefore(minutesBefore);
    query.setFrequencyMinutesAfter(minutesAfter);
    List<ArrivalAndDepartureBean> arrivalsAndDepartures = _service.getArrivalsAndDeparturesByStopId(stopB.getId(), query);
    assertEquals(2, arrivalsAndDepartures.size());
    ArrivalAndDepartureBean bean = arrivalsAndDepartures.get(0);
    assertEquals(1500, bean.getDistanceFromStop(), 0.0);
    assertEquals(lastUpdateTime, bean.getLastUpdateTime().longValue());
    assertEquals(1, bean.getNumberOfStopsAway());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getPredictedDepartureTime());
    assertNull(bean.getRouteShortName());
    assertEquals(dateAsLong("2010-10-05 16:40"), bean.getScheduledArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:45"), bean.getScheduledDepartureTime());
    assertEquals(serviceDate, bean.getServiceDate());
    assertEquals("default", bean.getStatus());
    assertSame(stopBBean, bean.getStop());
    assertSame(tripABean, bean.getTrip());
    assertSame(tripStatusBeanA, bean.getTripStatus());
    assertEquals("Downtown", bean.getTripHeadsign());
    assertEquals("1_vehicle", bean.getVehicleId());
    bean = arrivalsAndDepartures.get(1);
    assertEquals(1600, bean.getDistanceFromStop(), 0.0);
    assertNull(bean.getLastUpdateTime());
    assertEquals(1, bean.getNumberOfStopsAway());
    assertEquals(0L, bean.getPredictedArrivalTime());
    assertEquals(0L, bean.getPredictedDepartureTime());
    assertEquals("XX", bean.getRouteShortName());
    assertEquals(dateAsLong("2010-10-05 16:50"), bean.getScheduledArrivalTime());
    assertEquals(dateAsLong("2010-10-05 16:55"), bean.getScheduledDepartureTime());
    assertEquals(serviceDate, bean.getServiceDate());
    assertEquals("default", bean.getStatus());
    assertSame(stopBBean, bean.getStop());
    assertSame(tripBBean, bean.getTrip());
    assertSame(tripStatusBeanB, bean.getTripStatus());
    assertNull(bean.getTripHeadsign());
    assertNull(bean.getVehicleId());
}
Also used : StopTimeInstance(org.onebusaway.transit_data_federation.model.StopTimeInstance) StopTimeEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopTimeEntryImpl) Builder(org.onebusaway.transit_data_federation.model.narrative.StopTimeNarrative.Builder) TripBean(org.onebusaway.transit_data.model.trips.TripBean) ArrivalsAndDeparturesQueryBean(org.onebusaway.transit_data.model.ArrivalsAndDeparturesQueryBean) BlockLocation(org.onebusaway.transit_data_federation.services.realtime.BlockLocation) TargetTime(org.onebusaway.transit_data_federation.model.TargetTime) TripEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl) ArrivalAndDepartureBean(org.onebusaway.transit_data.model.ArrivalAndDepartureBean) StopEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl) BlockInstance(org.onebusaway.transit_data_federation.services.blocks.BlockInstance) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) StopBean(org.onebusaway.transit_data.model.StopBean) TripStatusBean(org.onebusaway.transit_data.model.trips.TripStatusBean) 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 28 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImplTest method testFrequencies.

@Test
public void testFrequencies() {
    BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    TripEntryImpl tripA = trip("a", "s1");
    stopTime(0, stopA, tripA, 0, 10, 0);
    stopTime(0, stopB, tripA, 20, 20, 0);
    FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
    FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
    List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
    linkBlockTrips(blockA, freqsA, tripA);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB = trip("b", "s1");
    stopTime(0, stopA, tripB, 20, 30, 0);
    stopTime(0, stopB, tripB, 50, 50, 0);
    FrequencyEntry freqB1 = frequency(time(9, 00), time(15, 00), 20, 0);
    FrequencyEntry freqB2 = frequency(time(18, 00), time(21, 00), 20, 0);
    List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
    linkBlockTrips(blockB, freqsB, tripB);
    List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(1, allIndices.size());
    List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
    assertEquals(1, indices.size());
    FrequencyBlockTripIndex index = indices.get(0);
    List<TripEntry> trips = trips(index.getTrips());
    assertEquals(4, trips.size());
    assertEquals(tripA, trips.get(0));
    assertEquals(tripB, trips.get(1));
    assertEquals(tripA, trips.get(2));
    assertEquals(tripB, trips.get(3));
    List<FrequencyEntry> freqs = index.getFrequencies();
    assertEquals(Arrays.asList(freqA1, freqB1, freqA2, freqB2), freqs);
    ServiceIdActivation serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { time(6, 0), time(9, 0), time(15, 0), time(18, 0) }, intervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { time(9, 0), time(15, 0), time(18, 0), time(21, 0) }, intervalBlock.getEndTimes()));
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) 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) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Test(org.junit.Test)

Example 29 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImplTest method testOverlappingFrequencies.

@Test
public void testOverlappingFrequencies() {
    BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
    StopEntryImpl stopA = stop("a", 47.0, -122.0);
    StopEntryImpl stopB = stop("b", 47.1, -122.1);
    /**
     **
     * Block A
     ***
     */
    BlockEntryImpl blockA = block("a");
    TripEntryImpl tripA = trip("a", "s1");
    stopTime(0, stopA, tripA, 0, 10, 0);
    stopTime(0, stopB, tripA, 20, 20, 0);
    FrequencyEntry freqA1 = frequency(time(6, 00), time(9, 00), 10, 0);
    FrequencyEntry freqA2 = frequency(time(15, 00), time(18, 00), 10, 0);
    List<FrequencyEntry> freqsA = Arrays.asList(freqA1, freqA2);
    linkBlockTrips(blockA, freqsA, tripA);
    /**
     **
     * Block B
     ***
     */
    BlockEntryImpl blockB = block("b");
    TripEntryImpl tripB = trip("b", "s1");
    stopTime(0, stopA, tripB, 20, 30, 0);
    stopTime(0, stopB, tripB, 50, 50, 0);
    FrequencyEntry freqB1 = frequency(time(8, 00), time(14, 00), 20, 0);
    FrequencyEntry freqB2 = frequency(time(17, 00), time(20, 00), 20, 0);
    List<FrequencyEntry> freqsB = Arrays.asList(freqB1, freqB2);
    linkBlockTrips(blockB, freqsB, tripB);
    List<FrequencyBlockTripIndex> allIndices = factory.createFrequencyTripIndices(Arrays.asList((BlockEntry) blockB, blockA));
    assertEquals(2, allIndices.size());
    List<FrequencyBlockTripIndex> indices = grep(allIndices, aid("a"));
    assertEquals(1, indices.size());
    FrequencyBlockTripIndex index = indices.get(0);
    List<TripEntry> trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripA, trips.get(0));
    assertEquals(tripA, trips.get(1));
    List<FrequencyEntry> freqs = index.getFrequencies();
    assertEquals(Arrays.asList(freqA1, freqA2), freqs);
    ServiceIdActivation serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    FrequencyServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { time(6, 0), time(15, 0) }, intervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { time(9, 0), time(18, 0) }, intervalBlock.getEndTimes()));
    /**
     **
     *
     ***
     */
    indices = grep(allIndices, aid("b"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripB, trips.get(0));
    assertEquals(tripB, trips.get(1));
    freqs = index.getFrequencies();
    assertEquals(Arrays.asList(freqB1, freqB2), freqs);
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { time(8, 0), time(17, 0) }, intervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { time(14, 0), time(20, 0) }, intervalBlock.getEndTimes()));
}
Also used : FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) FrequencyEntry(org.onebusaway.transit_data_federation.services.transit_graph.FrequencyEntry) 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) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) Test(org.junit.Test)

Example 30 with BlockEntryImpl

use of org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl in project onebusaway-application-modules by camsys.

the class BlockIndexFactoryServiceImplTest method test.

@Test
public void test() {
    BlockIndexFactoryServiceImpl factory = new BlockIndexFactoryServiceImpl();
    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);
    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);
    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);
    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);
    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);
    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);
    linkBlockTrips(blockF, tripF1, tripF2, tripF3);
    List<BlockTripIndex> allIndices = factory.createTripIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
    assertEquals(6, allIndices.size());
    List<BlockTripIndex> indices = grep(allIndices, aid("a1"));
    assertEquals(1, indices.size());
    BlockTripIndex index = indices.get(0);
    List<TripEntry> trips = trips(index.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA1, trips.get(0));
    assertEquals(tripB1, trips.get(1));
    assertEquals(tripF1, trips.get(2));
    assertEquals(tripE1, trips.get(3));
    assertEquals(tripB3, trips.get(4));
    ServiceIdActivation serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    ServiceIntervalBlock intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 0, 20, 40, 50, 80 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 10, 30, 50, 60, 80 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 20, 50, 70, 80, 90 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 20, 50, 70, 80, 100 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("a2"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA2, trips.get(0));
    assertEquals(tripB2, trips.get(1));
    assertEquals(tripC2, trips.get(2));
    assertEquals(tripF2, trips.get(3));
    assertEquals(tripE2, trips.get(4));
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 30, 60, 70, 80, 90 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 30, 60, 70, 80, 90 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 40, 70, 80, 90, 100 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 40, 70, 80, 90, 100 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("c1"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(3, trips.size());
    assertEquals(tripC1, trips.get(0));
    assertEquals(tripA3, trips.get(1));
    assertEquals(tripC3, trips.get(2));
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 40, 50, 85 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 50, 50, 85 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 60, 60, 90 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 60, 70, 95 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("d1"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripD1, trips.get(0));
    assertEquals(tripD3, trips.get(1));
    serviceIds = index.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 40, 100 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 50, 100 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 70, 110 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 70, 120 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("d2"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(1, trips.size());
    assertEquals(tripD2, trips.get(0));
    serviceIds = index.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 80 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 80 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 90 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 90 }, intervalBlock.getMaxDepartures()));
    indices = grep(allIndices, aid("e3"));
    assertEquals(1, indices.size());
    index = indices.get(0);
    trips = trips(index.getTrips());
    assertEquals(2, trips.size());
    assertEquals(tripF3, trips.get(0));
    assertEquals(tripE3, trips.get(1));
    serviceIds = index.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    intervalBlock = index.getServiceIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMinArrivals()));
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMinDepartures()));
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMaxArrivals()));
    assertTrue(Arrays.equals(new int[] { 100, 110 }, intervalBlock.getMaxDepartures()));
    /**
     **
     * Test Layover Indices
     ***
     */
    List<BlockLayoverIndex> allLayoverIndices = factory.createLayoverIndices(Arrays.asList((BlockEntry) blockF, blockE, blockD, blockC, blockB, blockA));
    List<BlockLayoverIndex> layoverIndices = grep(allLayoverIndices, aid("a2"));
    assertEquals(1, layoverIndices.size());
    BlockLayoverIndex layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA2, trips.get(0));
    assertEquals(tripB2, trips.get(1));
    assertEquals(tripC2, trips.get(2));
    assertEquals(tripF2, trips.get(3));
    assertEquals(tripE2, trips.get(4));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    LayoverIntervalBlock layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 20, 50, 60, 70, 80 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 30, 60, 70, 80, 90 }, layoverIntervalBlock.getEndTimes()));
    layoverIndices = grep(allLayoverIndices, aid("a3"));
    assertEquals(1, layoverIndices.size());
    layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(5, trips.size());
    assertEquals(tripA3, trips.get(0));
    assertEquals(tripB3, trips.get(1));
    assertEquals(tripC3, trips.get(2));
    assertEquals(tripF3, trips.get(3));
    assertEquals(tripE3, trips.get(4));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(1, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 40, 70, 80, 90, 100 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 50, 80, 85, 100, 110 }, layoverIntervalBlock.getEndTimes()));
    layoverIndices = grep(allLayoverIndices, aid("d2"));
    assertEquals(1, layoverIndices.size());
    layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(1, trips.size());
    assertEquals(tripD2, trips.get(0));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 70 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 80 }, layoverIntervalBlock.getEndTimes()));
    layoverIndices = grep(allLayoverIndices, aid("d3"));
    assertEquals(1, layoverIndices.size());
    layoverIndiex = layoverIndices.get(0);
    trips = trips(layoverIndiex.getTrips());
    assertEquals(1, trips.size());
    assertEquals(tripD3, trips.get(0));
    serviceIds = layoverIndiex.getServiceIds();
    assertEquals(2, serviceIds.getActiveServiceIds().size());
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s1")));
    assertTrue(serviceIds.getActiveServiceIds().contains(lsid("s2")));
    layoverIntervalBlock = layoverIndiex.getLayoverIntervalBlock();
    assertTrue(Arrays.equals(new int[] { 90 }, layoverIntervalBlock.getStartTimes()));
    assertTrue(Arrays.equals(new int[] { 100 }, layoverIntervalBlock.getEndTimes()));
}
Also used : ServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.ServiceIntervalBlock) FrequencyServiceIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.FrequencyServiceIntervalBlock) LayoverIntervalBlock(org.onebusaway.transit_data_federation.services.blocks.LayoverIntervalBlock) 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) BlockLayoverIndex(org.onebusaway.transit_data_federation.services.blocks.BlockLayoverIndex) BlockEntry(org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry) ServiceIdActivation(org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation) BlockEntryImpl(org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl) BlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.BlockTripIndex) FrequencyBlockTripIndex(org.onebusaway.transit_data_federation.services.blocks.FrequencyBlockTripIndex) Test(org.junit.Test)

Aggregations

BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)43 TripEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl)34 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)34 Test (org.junit.Test)33 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)25 StopEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.StopEntryImpl)16 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)15 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)11 TripUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)8 StopTimeUpdate (com.google.transit.realtime.GtfsRealtime.TripUpdate.StopTimeUpdate)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)7 Date (java.util.Date)6 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)6 ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)6 ServiceIdActivation (org.onebusaway.transit_data_federation.services.transit_graph.ServiceIdActivation)6 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 BlockEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockEntry)5 BlockTripEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockTripEntry)5