Search in sources :

Example 11 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a loop route with a three trips and two stops in a block
 * Stop A is visited twice in a trip
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *    A           1             3
 *
 *    A           2             0
 *    B           2             1
 *    A           2             3
 *
 *    A           3             0
 *    B           3             1
 *    A           3             3
 *
 * @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> getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(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);
    stopTime(0, mStopA, mTrip2, time(14, 05), time(14, 10), 1000);
    stopTime(1, mStopB, mTrip2, time(14, 15), time(14, 20), 2000);
    stopTime(2, mStopA, mTrip2, time(14, 25), time(14, 25), 2000);
    stopTime(0, mStopA, mTrip3, time(14, 30), time(14, 35), 1000);
    stopTime(1, mStopB, mTrip3, time(14, 45), time(14, 50), 2000);
    stopTime(2, mStopA, mTrip3, time(14, 55), time(14, 55), 2000);
    BlockConfigurationEntry blockConfig = blockConfiguration(block, serviceIds(lsids("sA", "sB", "sC"), lsids()), mTrip1, mTrip2, mTrip3);
    BlockStopTimeEntry bstAA = blockConfig.getStopTimes().get(0);
    BlockStopTimeEntry bstAB = blockConfig.getStopTimes().get(1);
    BlockStopTimeEntry bstAC = blockConfig.getStopTimes().get(2);
    BlockStopTimeEntry bstBA = blockConfig.getStopTimes().get(3);
    BlockStopTimeEntry bstBB = blockConfig.getStopTimes().get(4);
    BlockStopTimeEntry bstBC = blockConfig.getStopTimes().get(5);
    BlockStopTimeEntry bstCA = blockConfig.getStopTimes().get(6);
    BlockStopTimeEntry bstCB = blockConfig.getStopTimes().get(7);
    BlockStopTimeEntry bstCC = blockConfig.getStopTimes().get(8);
    // Setup block location instance for trip B
    BlockInstance blockInstance = new BlockInstance(blockConfig, mServiceDate);
    BlockLocation blockLocationB = new BlockLocation();
    blockLocationB.setActiveTrip(bstBB.getTrip());
    blockLocationB.setBlockInstance(blockInstance);
    blockLocationB.setClosestStop(bstBC);
    blockLocationB.setDistanceAlongBlock(400);
    blockLocationB.setInService(true);
    blockLocationB.setNextStop(bstBC);
    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(bstAC, blockInstance.getState());
    ArrivalAndDepartureInstance in3 = new ArrivalAndDepartureInstance(sti3);
    in3.setBlockLocation(blockLocationB);
    in3.setPredictedArrivalTime((long) (in3.getScheduledArrivalTime()));
    in3.setPredictedDepartureTime((long) (in3.getScheduledDepartureTime()));
    StopTimeInstance sti4 = new StopTimeInstance(bstBA, blockInstance.getState());
    ArrivalAndDepartureInstance in4 = new ArrivalAndDepartureInstance(sti4);
    in4.setBlockLocation(blockLocationB);
    StopTimeInstance sti5 = new StopTimeInstance(bstBB, blockInstance.getState());
    ArrivalAndDepartureInstance in5 = new ArrivalAndDepartureInstance(sti5);
    in5.setBlockLocation(blockLocationB);
    StopTimeInstance sti6 = new StopTimeInstance(bstBC, blockInstance.getState());
    ArrivalAndDepartureInstance in6 = new ArrivalAndDepartureInstance(sti6);
    in6.setBlockLocation(blockLocationB);
    StopTimeInstance sti7 = new StopTimeInstance(bstCA, blockInstance.getState());
    ArrivalAndDepartureInstance in7 = new ArrivalAndDepartureInstance(sti7);
    in7.setBlockLocation(blockLocationB);
    StopTimeInstance sti8 = new StopTimeInstance(bstCB, blockInstance.getState());
    ArrivalAndDepartureInstance in8 = new ArrivalAndDepartureInstance(sti8);
    in8.setBlockLocation(blockLocationB);
    StopTimeInstance sti9 = new StopTimeInstance(bstCC, blockInstance.getState());
    ArrivalAndDepartureInstance in9 = new ArrivalAndDepartureInstance(sti9);
    in9.setBlockLocation(blockLocationB);
    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, sti4, sti5, sti6, sti7, sti8, sti9));
    // Create and add vehicle location record cache
    VehicleLocationRecordCacheImpl _cache = new VehicleLocationRecordCacheImpl();
    VehicleLocationRecord vlr = new VehicleLocationRecord();
    vlr.setBlockId(blockLocationB.getBlockInstance().getBlock().getBlock().getId());
    vlr.setTripId(mTrip2.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 12 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange07.

/**
 * This method tests loop routes (the same stop is visited more
 * than once in the same trip) when stop_sequence is missing in the real-time feed.
 * It applies the prediction if there is more than one prediction in the same trip
 * (i.e., the stop_id can be disambiguated).
 *
 * Test configuration: There is only one time point prediction for the first stop,
 * and there is only one trip in the block. But time point predictions do not have
 * stop_sequences. In this case getArrivalsAndDeparturesForStopInTimeRange() for
 * Stop A should return a predicted arrival time = 0, indicating that no
 * real-time information is available for Stop A (i.e., we drop the prediction,
 * because it is ambiguous and could refer to more than one stop instance - Stop A
 * appears twice).
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed      GTFS stop_sequence
 * Stop A   13:30            13:35                          0
 * Stop B   13:45            -----                          1
 * Stop A   13:55            -----                          2
 *
 * Since we
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange07() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point predictions for stop A
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprBTime = createPredictedTime(time(13, 35));
    tprA.setTimepointPredictedArrivalTime(tprBTime);
    tprA.setTripId(mTrip1.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprA), mStopA);
    /**
     * Make sure the predictedArrivalTime for stop A (first and the last stop) and stop B
     * is equals to 0 - in other words, we should show no real-time information for this trip
     * and use the scheduled time instead.
     */
    // 
    long predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 0);
    assertEquals(0, predictedArrivalTimeA);
    long predictedArrivalTimeB = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), 1);
    assertEquals(0, predictedArrivalTimeB);
    predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 2);
    assertEquals(0, predictedArrivalTimeA);
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 13 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord.

/**
 * Set up the BlockLocationServiceImpl for the test, using the given
 * timepointPredictions
 *
 * This method creates a normal route with a single trip and two stops in a block
 *
 * stop_id     trip_id    stop_sequence
 *    A           1             0
 *    B           1             1
 *
 * @param timepointPredictions real-time predictions to apply to the
 *          BlockLocationServiceImpl
 * @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> getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(List<TimepointPredictionRecord> timepointPredictions) {
    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);
    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(0);
    // 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(bstAB, blockInstance.getState());
    ArrivalAndDepartureInstance in1 = new ArrivalAndDepartureInstance(sti1);
    in1.setBlockLocation(blockLocationB);
    in1.setPredictedArrivalTime((long) (in1.getScheduledArrivalTime()));
    in1.setPredictedDepartureTime((long) (in1.getScheduledDepartureTime()));
    StopTimeInstance sti2 = new StopTimeInstance(bstBA, blockInstance.getState());
    ArrivalAndDepartureInstance in2 = new ArrivalAndDepartureInstance(sti2);
    in2.setBlockLocation(blockLocationB);
    Date fromTimeBuffered = new Date(stopTimeFrom - _blockStatusService.getRunningLateWindow() * 1000);
    Date toTimeBuffered = new Date(stopTimeTo + _blockStatusService.getRunningEarlyWindow() * 1000);
    Mockito.when(_stopTimeService.getStopTimeInstancesInTimeRange(mStopB, fromTimeBuffered, toTimeBuffered, EFrequencyStopTimeBehavior.INCLUDE_UNSPECIFIED)).thenReturn(Arrays.asList(sti1, sti2));
    // 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(mStopB, 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 14 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange14.

/**
 * This method tests loop routes (the same stop is visited more
 * than once in the same trip) when stop_sequence is missing in the real-time feed.
 * It applies the prediction if there is more than one prediction in the same trip
 * (i.e., the stop_id can be disambiguated).
 *
 * Test configuration: There are three different loop trips and each trip has 3 stops.
 * Time point predictions does not have stop sequences, and therefore the update for
 * each trip Stop A (in trip 2 and trip 3) is ambiguous and cannot be matched.  This
 * test also ensures the we aren't accidentally recognizing two adjacent updates in
 * the block as being part of the same trip.  As a result, the updates should be dropped
 * and schedule time should be provided.
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed   GTFS stop_sequence  trip_id
 * Stop A   13:30            -----                          0           t1
 * Stop B   13:45            -----                          1           t1
 * Stop A   13:55            -----                          2           t1
 *
 * Stop A   14:05            -----                          0           t2
 * Stop B   14:15            -----                          1           t2
 * Stop A   14:25            14:30                          2           t2
 *
 * Stop A   14:30            14:40                          0           t3
 * Stop B   14:45            -----                          1           t3
 * Stop A   14:55            -----                          2           t3
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange14() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point predictions for trip 2 stop A
    TimepointPredictionRecord tpr2A = new TimepointPredictionRecord();
    tpr2A.setTimepointId(mStopA.getId());
    long tprAATime = createPredictedTime(time(14, 30));
    tpr2A.setTimepointPredictedArrivalTime(tprAATime);
    tpr2A.setTripId(mTrip2.getId());
    // Set time point predictions for trip 3 stop A
    TimepointPredictionRecord tpr3A = new TimepointPredictionRecord();
    tpr3A.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(14, 40));
    tpr3A.setTimepointPredictedArrivalTime(tprATime);
    tpr3A.setTripId(mTrip3.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(Arrays.asList(tpr2A, tpr3A), mStopB);
    // First trip in block
    long predictedArrivalTimeStop1A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 0);
    long predictedArrivalTimeStop1B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip1.getId(), 1);
    long predictedArrivalTimeStop1C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 2);
    // Second trip in block
    long predictedArrivalTimeStop2A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 0);
    long predictedArrivalTimeStop2B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip2.getId(), 1);
    long predictedArrivalTimeStop2C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 2);
    // Third trip in block
    long predictedArrivalTimeStop3A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 0);
    long predictedArrivalTimeStop3B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip3.getId(), 1);
    long predictedArrivalTimeStop3C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 2);
    /**
     * Check the all stops and make sure no real-time information has been applied.
     */
    assertEquals(predictedArrivalTimeStop1A, 0);
    assertEquals(predictedArrivalTimeStop1B, 0);
    assertEquals(predictedArrivalTimeStop1C, 0);
    assertEquals(predictedArrivalTimeStop2A, 0);
    assertEquals(predictedArrivalTimeStop2B, 0);
    assertEquals(predictedArrivalTimeStop2C, 0);
    assertEquals(predictedArrivalTimeStop3A, 0);
    assertEquals(predictedArrivalTimeStop3B, 0);
    assertEquals(predictedArrivalTimeStop3C, 0);
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Example 15 with ArrivalAndDepartureInstance

use of org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance in project onebusaway-application-modules by camsys.

the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange12.

/**
 * This method tests loop routes (the same stop is visited more
 * than once in the same trip) when stop_sequence is missing in the real-time feed.
 * It applies the prediction if there is more than one prediction in the same trip
 * (i.e., the stop_id can be disambiguated).
 *
 * Test configuration: There are three different loop trips and each trip has 3 stops
 * Time point predictions does not have stop sequences.  There is only one prediction
 * for the first or the last stop in a loop route, and there it is ambiguous and
 * should be dropped.  As a result, all stops should show scheduled time.
 *
 * Current time = 14:00
 *          Schedule time    Real-time from feed      GTFS stop_sequence  trip_id
 * Stop A   13:30            -----                          0           t1
 * Stop B   13:45            -----                          1           t1
 * Stop A   13:55            -----                          2           t1
 *
 * Stop A   14:05            14:10                          0           t2
 * Stop B   14:15            -----                          1           t2
 * Stop A   14:25            -----                          2           t2
 *
 * Stop A   14:30            -----                          0           t3
 * Stop B   14:45            -----                          1           t3
 * Stop A   14:55            -----                          2           t3
 */
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange12() {
    // Override the current time with a later time than the time point
    // predictions
    mCurrentTime = dateAsLong("2015-07-23 14:00");
    // Set time point predictions for trip 2 stop A
    TimepointPredictionRecord tprA = new TimepointPredictionRecord();
    tprA.setTimepointId(mStopA.getId());
    long tprATime = createPredictedTime(time(14, 10));
    tprA.setTimepointPredictedArrivalTime(tprATime);
    tprA.setTripId(mTrip2.getId());
    // Call ArrivalsAndDeparturesForStopInTimeRange method in
    // ArrivalAndDepartureServiceImpl
    List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(Arrays.asList(tprA), mStopB);
    // First trip in block
    long predictedArrivalTimeStop1A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 0);
    long predictedArrivalTimeStop1B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip1.getId(), 1);
    long predictedArrivalTimeStop1C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip1.getId(), 2);
    // Second trip in block
    long predictedArrivalTimeStop2A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 0);
    long predictedArrivalTimeStop2B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip2.getId(), 1);
    long predictedArrivalTimeStop2C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip2.getId(), 2);
    // Third trip in block
    long predictedArrivalTimeStop3A = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 0);
    long predictedArrivalTimeStop3B = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopB.getId(), mTrip3.getId(), 1);
    long predictedArrivalTimeStop3C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 2);
    /**
     * Check the all stops and make sure no propagation happening.
     */
    assertEquals(predictedArrivalTimeStop1A, 0);
    assertEquals(predictedArrivalTimeStop1B, 0);
    assertEquals(predictedArrivalTimeStop1C, 0);
    assertEquals(predictedArrivalTimeStop2A, 0);
    assertEquals(predictedArrivalTimeStop2B, 0);
    assertEquals(predictedArrivalTimeStop2C, 0);
    assertEquals(predictedArrivalTimeStop3A, 0);
    assertEquals(predictedArrivalTimeStop3B, 0);
    assertEquals(predictedArrivalTimeStop3C, 0);
}
Also used : TimepointPredictionRecord(org.onebusaway.realtime.api.TimepointPredictionRecord) ArrivalAndDepartureInstance(org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance) Test(org.junit.Test)

Aggregations

ArrivalAndDepartureInstance (org.onebusaway.transit_data_federation.services.realtime.ArrivalAndDepartureInstance)37 Test (org.junit.Test)18 TimepointPredictionRecord (org.onebusaway.realtime.api.TimepointPredictionRecord)17 StopTimeInstance (org.onebusaway.transit_data_federation.model.StopTimeInstance)12 BlockInstance (org.onebusaway.transit_data_federation.services.blocks.BlockInstance)10 BlockLocation (org.onebusaway.transit_data_federation.services.realtime.BlockLocation)10 AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)9 BlockStopTimeEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockStopTimeEntry)9 BlockConfigurationEntry (org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry)8 Date (java.util.Date)7 TargetTime (org.onebusaway.transit_data_federation.model.TargetTime)7 BlockEntryImpl (org.onebusaway.transit_data_federation.impl.transit_graph.BlockEntryImpl)6 ArrayList (java.util.ArrayList)5 VehicleLocationRecord (org.onebusaway.realtime.api.VehicleLocationRecord)5 ScheduledBlockLocationServiceImpl (org.onebusaway.transit_data_federation.impl.blocks.ScheduledBlockLocationServiceImpl)5 VehicleLocationRecordCacheImpl (org.onebusaway.transit_data_federation.impl.realtime.VehicleLocationRecordCacheImpl)5 ScheduledBlockLocation (org.onebusaway.transit_data_federation.services.blocks.ScheduledBlockLocation)5 HashMap (java.util.HashMap)3 ArrivalAndDepartureBean (org.onebusaway.transit_data.model.ArrivalAndDepartureBean)3 StopBean (org.onebusaway.transit_data.model.StopBean)3