use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange06.
/**
* This method tests to make sure upstream propagation isn't happening.
*
* Test configuration: Time point predictions are downstream of Stop A, which
* means that the bus is predicted to have already passed the bus stop. There
* only one bus stop (Stop B) which has a real time arrival time (time point
* prediction). 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.
*
* Current time = 14:00
* Schedule time Real-time from feed
* Stop A 13:30 -----
* Stop B 13:45 13:40
*
* Since the bus already passed the bus stop A, and no real-time information
* is available for Stop A, OBA should NOT propagate arrival estimate for Stop
* B upstream to Stop A.
*/
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange06() {
// 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 B
TimepointPredictionRecord tprB = new TimepointPredictionRecord();
tprB.setTimepointId(mStopB.getId());
long tprBTime = createPredictedTime(time(13, 40));
tprB.setTimepointPredictedArrivalTime(tprBTime);
tprB.setTripId(mTrip1.getId());
// Call ArrivalsAndDeparturesForStopInTimeRange method in
// ArrivalAndDepartureServiceImpl
List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForStopInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprB));
long predictedArrivalTimeStopB = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopB.getId());
/**
* Check if the predictedArrivalTime for stop B is exactly the same as
* TimepointPredictionRecord.
*/
assertEquals(tprB.getTimepointPredictedArrivalTime(), predictedArrivalTimeStopB);
/**
* Check predicted departure for Stop B too, to make sure its propagated
* from provided predicted arrival time
*/
long scheduledArrivalTimeForStopB = getScheduledArrivalTimeByStopId(mTrip1, mStopB.getId());
long scheduledDepartureTimeForStopB = getScheduledDepartureTimeByStopId(mTrip1, mStopB.getId());
long predictedDepartureTimeStopB = getPredictedDepartureTimeByStopId(arrivalsAndDepartures, mStopB.getId());
long deltaB = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStopB) - scheduledArrivalTimeForStopB;
assertEquals(scheduledDepartureTimeForStopB + deltaB, TimeUnit.MILLISECONDS.toSeconds(predictedDepartureTimeStopB));
/**
* Make sure the predictedArrivalTime for stop A is equals to 0 - in other
* words, we should show no real-time information for this stop and use the
* scheduled time instead.
*/
long predictedArrivalTimeA = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopA.getId());
assertEquals(0, predictedArrivalTimeA);
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange09.
/**
* 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 two time point predictions for the 2nd and the last stop.
* But time point predictions do not have stop_sequences. There is a single trip
* in the block. In this case getArrivalsAndDeparturesForStopInTimeRange() for the
* first instance of Stop A should not have any real-time data (i.e., the schedule time
* should be shown). The Stop B should return a predicted arrival time = 13:50 (the prediction
* for this stop). The last Stop A should return a predicted arrival time = 13:58
* (the estimate for the last Stop A instance).
*
* Current time = 14:00
* Schedule time Real-time from feed GTFS stop_sequence
* Stop A 13:30 ----- 0
* Stop B 13:45 13:50 1
* Stop A 13:55 13:58 2
*/
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange09() {
// 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 (last instance)
TimepointPredictionRecord tprA = new TimepointPredictionRecord();
tprA.setTimepointId(mStopA.getId());
long tprATime = createPredictedTime(time(13, 58));
tprA.setTimepointPredictedArrivalTime(tprATime);
tprA.setTripId(mTrip1.getId());
// Set time point predictions for stop B
TimepointPredictionRecord tprB = new TimepointPredictionRecord();
tprB.setTimepointId(mStopB.getId());
long tprBTime = createPredictedTime(time(13, 50));
tprB.setTimepointPredictedArrivalTime(tprBTime);
tprB.setTripId(mTrip1.getId());
// Call ArrivalsAndDeparturesForStopInTimeRange method in
// ArrivalAndDepartureServiceImpl
List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecord(Arrays.asList(tprB, tprA), mStopB);
long predictedArrivalTimeStopB = getPredictedArrivalTimeByStopId(arrivalsAndDepartures, mStopB.getId());
/**
* Make sure the predictedArrivalTime for stop A (the first stop) is equals to 0 - in other
* words, we should show no real-time information for this stop and use the
* scheduled time instead.
*/
long predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 0);
assertEquals(0, predictedArrivalTimeA);
/**
* Check if the predictedArrivalTime for stop B is exactly the same as
* TimepointPredictionRecord.
*/
assertEquals(tprB.getTimepointPredictedArrivalTime(), predictedArrivalTimeStopB);
/**
* Make sure the predictedArrivalTime for stop A (the last stop) is exactly the same as
* TimepointPredictionRecord.
*/
predictedArrivalTimeA = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), 2);
assertEquals(tprA.getTimepointPredictedArrivalTime(), predictedArrivalTimeA);
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange15.
/**
* 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 1 and trip 3) is ambiguous and cannot be matched. This
* test also ensures the we aren't accidentally recognizing two updates in the same 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 14:00 2 t1
*
* Stop A 14:05 ----- 0 t2
* Stop B 14:15 ----- 1 t2
* Stop A 14:25 ----- 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 testGetArrivalsAndDeparturesForStopInTimeRange15() {
// 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 1 stop A
TimepointPredictionRecord tpr1A = new TimepointPredictionRecord();
tpr1A.setTimepointId(mStopA.getId());
long tprAATime = createPredictedTime(time(14, 00));
tpr1A.setTimepointPredictedArrivalTime(tprAATime);
tpr1A.setTripId(mTrip1.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(tpr1A, 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);
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class ArrivalAndDepartureServiceImplTest method testGetArrivalsAndDeparturesForStopInTimeRange16.
/**
* 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 do not have stop sequences, and therefore the update for
* trip1 Stop A is ambiguous and cannot be matched. However, for trip 3, there are at least
* two updates, so we can infer that the update for Stop A should be applied to the first
* stop instance. This test also ensures the we aren't accidentally recognizing two updates
* in the same block as being part of the same trip (for trip 1). As a result, the update
* for trip 1 should be dropped, but the updates for trip 3 should be applied.
*
* 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 14:00 2 t1
*
* Stop A 14:05 ----- 0 t2
* Stop B 14:15 ----- 1 t2
* Stop A 14:25 ----- 2 t2
*
* Stop A 14:30 14:40 0 t3
* Stop B 14:45 14:50 1 t3
* Stop A 14:55 ----- 2 t3
*/
@Test
public void testGetArrivalsAndDeparturesForStopInTimeRange16() {
// Override the current time with a later time than the time point
// predictions
mCurrentTime = dateAsLong("2015-07-23 14:00");
// Set time point prediction for trip 1 stop A
TimepointPredictionRecord tpr1A = new TimepointPredictionRecord();
tpr1A.setTimepointId(mStopA.getId());
long tprAATime = createPredictedTime(time(14, 00));
tpr1A.setTimepointPredictedArrivalTime(tprAATime);
tpr1A.setTripId(mTrip1.getId());
// Set time point predictions for trip 3 stop A and stop B
TimepointPredictionRecord tpr3A = new TimepointPredictionRecord();
tpr3A.setTimepointId(mStopA.getId());
long tprATime = createPredictedTime(time(14, 40));
tpr3A.setTimepointPredictedArrivalTime(tprATime);
tpr3A.setTripId(mTrip3.getId());
TimepointPredictionRecord tpr3B = new TimepointPredictionRecord();
tpr3B.setTimepointId(mStopB.getId());
long tprBTime = createPredictedTime(time(14, 50));
tpr3B.setTimepointPredictedArrivalTime(tprBTime);
tpr3B.setTripId(mTrip3.getId());
// Call ArrivalsAndDeparturesForStopInTimeRange method in
// ArrivalAndDepartureServiceImpl
List<ArrivalAndDepartureInstance> arrivalsAndDepartures = getArrivalsAndDeparturesForLoopRouteInTimeRangeByTimepointPredictionRecordWithMultipleTrips(Arrays.asList(tpr1A, tpr3A, tpr3B), 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);
/**
* Make sure no real-time info is applied to trips 1 and 2
*/
assertEquals(predictedArrivalTimeStop1A, 0);
assertEquals(predictedArrivalTimeStop1B, 0);
assertEquals(predictedArrivalTimeStop1C, 0);
assertEquals(predictedArrivalTimeStop2A, 0);
assertEquals(predictedArrivalTimeStop2B, 0);
assertEquals(predictedArrivalTimeStop2C, 0);
/**
* Check last three predictions in trip 3. We should have predictions for these stops.
*/
assertEquals(predictedArrivalTimeStop3A, tpr3A.getTimepointPredictedArrivalTime());
assertEquals(predictedArrivalTimeStop3B, tpr3B.getTimepointPredictedArrivalTime());
long scheduledArrivalTime3B = getScheduledArrivalTimeByStopId(mTrip3, mStopB.getId(), 1);
// Calculate the delay of the last stop A in trip B
long delta = TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTimeStop3B) - scheduledArrivalTime3B;
long scheduledArrivalTimeStop3C = getScheduledArrivalTimeByStopId(mTrip3, mStopA.getId(), 2);
long predictedArrivalTime3C = getPredictedArrivalTimeByStopIdAndSequence(arrivalsAndDepartures, mStopA.getId(), mTrip3.getId(), 2);
// Check propagation of trip 3 Stop B to the last instance of Stop A
assertEquals(scheduledArrivalTimeStop3C + delta, TimeUnit.MILLISECONDS.toSeconds(predictedArrivalTime3C));
}
use of org.onebusaway.realtime.api.TimepointPredictionRecord in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_FutureDay.
// Ensure that if we get an update for a future day we propagate a prediction for that day.
// (This is equivalent to timestamp on feed being early incorrectly, since currentTime in
// GtfsRealtimeTripLibrary is set via the timestamp.)
@Test
public void testCreateVehicleLocationRecordForUpdate_FutureDay() {
final long day = TimeUnit.DAYS.toMillis(1);
StopTimeUpdate.Builder stopTimeUpdate = stopTimeUpdateWithDepartureDelay("stopA", 180);
TripUpdate.Builder tripUpdate = tripUpdate("tripA", (_library.getCurrentTime() + day) / 1000, 120, stopTimeUpdate);
TripEntryImpl tripA = trip("tripA");
stopTime(0, stop("stopA", 0, 0), tripA, time(7, 30), 0.0);
BlockEntryImpl blockA = block("blockA");
BlockConfigurationEntry blockConfigA = blockConfiguration(blockA, serviceIds("s1"), tripA);
BlockInstance blockInstanceA = new BlockInstance(blockConfigA, 0L);
BlockInstance blockInstanceB = new BlockInstance(blockConfigA, day);
Mockito.when(_entitySource.getTrip("tripA")).thenReturn(tripA);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.longThat(new ArgumentMatcher<Long>() {
@Override
public boolean matches(Object argument) {
return ((Long) argument) < day;
}
}))).thenReturn(Arrays.asList(blockInstanceA));
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.longThat(new ArgumentMatcher<Long>() {
@Override
public boolean matches(Object argument) {
return ((Long) argument) >= day;
}
}))).thenReturn(Arrays.asList(blockInstanceB));
FeedMessage.Builder TU = createFeed();
TU.addEntity(feed(tripUpdate));
FeedMessage.Builder VP = createFeed();
List<CombinedTripUpdatesAndVehiclePosition> updates = _library.groupTripUpdatesAndVehiclePositions(TU.build(), VP.build());
CombinedTripUpdatesAndVehiclePosition update = updates.get(0);
VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
TimepointPredictionRecord tpr = record.getTimepointPredictions().get(0);
long departure = tpr.getTimepointPredictedDepartureTime();
// 7:30 + 3 min delay + on next day
assertEquals(departure, time(7, 33) * 1000 + day);
}
Aggregations