use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class BlockLocationRecordCollectionTest method test01.
@Test
public void test01() {
BlockEntryImpl block = block("blockA");
TripEntryImpl trip = trip("tripA", "serviceId");
stopTime(0, null, trip, time(9, 00), 0);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
BlockInstance blockInstance = new BlockInstance(blockConfig, System.currentTimeMillis());
SortedMap<Long, BlockLocationRecord> records = new TreeMap<Long, BlockLocationRecord>();
CoordinatePoint p1 = new CoordinatePoint(47.0, -122.0);
CoordinatePoint p2 = new CoordinatePoint(47.1, -122.1);
CoordinatePoint p3 = new CoordinatePoint(47.2, -122.2);
EVehiclePhase inProgress = EVehiclePhase.IN_PROGRESS;
EVehiclePhase layover = EVehiclePhase.LAYOVER_DURING;
addRecord(records, record(t(4, 10), 10.0, 100.0, p1, 0.0, inProgress, "ok"));
addRecord(records, record(t(8, 20), 18.0, 200.0, p2, 90.0, layover, "not ok"));
addRecord(records, record(t(12, 30), 15.0, 300.0, p3, 45.0, inProgress, "ok"));
BlockLocationRecordCollection entry = new BlockLocationRecordCollection(t(3, 20), t(13, 20), records);
assertEquals(t(3, 20), entry.getFromTime());
assertEquals(t(13, 20), entry.getToTime());
assertEquals(10, entry.getScheduleDeviationForTargetTime(t(3, 20)), 0.0);
assertEquals(10, entry.getScheduleDeviationForTargetTime(t(4, 10)), 0.0);
assertEquals(12, entry.getScheduleDeviationForTargetTime(t(5, 12)), 0.0);
assertEquals(14, entry.getScheduleDeviationForTargetTime(t(6, 15)), 0.0);
assertEquals(16, entry.getScheduleDeviationForTargetTime(t(7, 18)), 0.0);
assertEquals(18, entry.getScheduleDeviationForTargetTime(t(8, 20)), 0.0);
assertEquals(17, entry.getScheduleDeviationForTargetTime(t(10, 0)), 0.0);
assertEquals(15, entry.getScheduleDeviationForTargetTime(t(12, 30)), 0.0);
assertEquals(15, entry.getScheduleDeviationForTargetTime(t(13, 20)), 0.0);
assertEquals(80, entry.getDistanceAlongBlockForTargetTime(t(3, 20)), 0.0);
assertEquals(100, entry.getDistanceAlongBlockForTargetTime(t(4, 10)), 0.0);
assertEquals(124.8, entry.getDistanceAlongBlockForTargetTime(t(5, 12)), 0.0);
assertEquals(150, entry.getDistanceAlongBlockForTargetTime(t(6, 15)), 0.0);
assertEquals(175.2, entry.getDistanceAlongBlockForTargetTime(t(7, 18)), 0.0);
assertEquals(200, entry.getDistanceAlongBlockForTargetTime(t(8, 20)), 0.0);
assertEquals(240, entry.getDistanceAlongBlockForTargetTime(t(10, 0)), 0.0);
assertEquals(300, entry.getDistanceAlongBlockForTargetTime(t(12, 30)), 0.0);
assertEquals(320, entry.getDistanceAlongBlockForTargetTime(t(13, 20)), 0.0);
assertNull(entry.getLastLocationForTargetTime(t(3, 20)));
assertNull(entry.getLastLocationForTargetTime(t(4, 9)));
assertEquals(p1, entry.getLastLocationForTargetTime(t(4, 10)));
assertEquals(p1, entry.getLastLocationForTargetTime(t(5, 12)));
assertEquals(p1, entry.getLastLocationForTargetTime(t(8, 19)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(8, 20)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(10, 0)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(12, 29)));
assertEquals(p3, entry.getLastLocationForTargetTime(t(12, 30)));
assertEquals(p3, entry.getLastLocationForTargetTime(t(16, 40)));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(3, 20))));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(4, 9))));
assertEquals(0.0, entry.getLastOrientationForTargetTime(t(4, 10)), 0.0);
assertEquals(0.0, entry.getLastOrientationForTargetTime(t(5, 12)), 0.0);
assertEquals(0.0, entry.getLastOrientationForTargetTime(t(8, 19)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(8, 20)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(10, 0)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(12, 29)), 0.0);
assertEquals(45.0, entry.getLastOrientationForTargetTime(t(12, 30)), 0.0);
assertEquals(45.0, entry.getLastOrientationForTargetTime(t(16, 40)), 0.0);
assertNull(entry.getPhaseForTargetTime(t(3, 20)));
assertNull(entry.getPhaseForTargetTime(t(4, 9)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(4, 10)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(5, 12)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(8, 19)));
assertEquals(layover, entry.getPhaseForTargetTime(t(8, 20)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 0)));
assertEquals(layover, entry.getPhaseForTargetTime(t(12, 29)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(12, 30)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(16, 40)));
assertNull(entry.getStatusForTargetTime(t(3, 20)));
assertNull(entry.getStatusForTargetTime(t(4, 9)));
assertEquals("ok", entry.getStatusForTargetTime(t(4, 10)));
assertEquals("ok", entry.getStatusForTargetTime(t(5, 12)));
assertEquals("ok", entry.getStatusForTargetTime(t(8, 19)));
assertEquals("not ok", entry.getStatusForTargetTime(t(8, 20)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 0)));
assertEquals("not ok", entry.getStatusForTargetTime(t(12, 29)));
assertEquals("ok", entry.getStatusForTargetTime(t(12, 30)));
assertEquals("ok", entry.getStatusForTargetTime(t(16, 40)));
CoordinatePoint p4 = new CoordinatePoint(47.15, -122.15);
entry = entry.addRecord(blockInstance, record(t(10, 0), 20, 220, p4, 270.0, layover, "not ok"), t(5, 0));
assertEquals(t(6, 40), entry.getFromTime());
assertEquals(t(11, 40), entry.getToTime());
assertEquals(18, entry.getScheduleDeviationForTargetTime(t(6, 40)), 0.0);
assertEquals(18, entry.getScheduleDeviationForTargetTime(t(8, 20)), 0.0);
assertEquals(19, entry.getScheduleDeviationForTargetTime(t(9, 10)), 0.0);
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(10, 00)), 0.0);
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(10, 50)), 0.0);
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(11, 40)), 0.0);
assertEquals(180, entry.getDistanceAlongBlockForTargetTime(t(6, 40)), 0.0);
assertEquals(200, entry.getDistanceAlongBlockForTargetTime(t(8, 20)), 0.0);
assertEquals(210, entry.getDistanceAlongBlockForTargetTime(t(9, 10)), 0.0);
assertEquals(220, entry.getDistanceAlongBlockForTargetTime(t(10, 00)), 0.0);
assertEquals(230, entry.getDistanceAlongBlockForTargetTime(t(10, 50)), 0.0);
assertEquals(240, entry.getDistanceAlongBlockForTargetTime(t(11, 40)), 0.0);
assertNull(entry.getLastLocationForTargetTime(t(6, 40)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(8, 20)));
assertEquals(p2, entry.getLastLocationForTargetTime(t(9, 10)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 00)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 50)));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(6, 40))));
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(8, 20)), 0.0);
assertEquals(90.0, entry.getLastOrientationForTargetTime(t(9, 10)), 0.0);
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 00)), 0.0);
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 50)), 0.0);
assertNull(entry.getPhaseForTargetTime(t(6, 40)));
assertEquals(layover, entry.getPhaseForTargetTime(t(8, 20)));
assertEquals(layover, entry.getPhaseForTargetTime(t(9, 10)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 00)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 50)));
assertNull(entry.getStatusForTargetTime(t(6, 40)));
assertEquals("not ok", entry.getStatusForTargetTime(t(8, 20)));
assertEquals("not ok", entry.getStatusForTargetTime(t(9, 10)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 00)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 50)));
CoordinatePoint p5 = new CoordinatePoint(47.4, -122.4);
entry = entry.addRecord(blockInstance, record(t(16, 40), 14, 500, p5, 180.0, inProgress, "ok"), t(6, 40));
assertEquals(t(10, 00), entry.getFromTime());
assertEquals(t(16, 40), entry.getToTime());
assertEquals(20, entry.getScheduleDeviationForTargetTime(t(9, 10)), 0.0);
assertEquals(17, entry.getScheduleDeviationForTargetTime(t(13, 20)), 0.0);
assertEquals(14, entry.getScheduleDeviationForTargetTime(t(16, 40)), 0.0);
assertEquals(220, entry.getDistanceAlongBlockForTargetTime(t(10, 00)), 0.0);
assertEquals(360, entry.getDistanceAlongBlockForTargetTime(t(13, 20)), 0.0);
assertEquals(500, entry.getDistanceAlongBlockForTargetTime(t(16, 40)), 0.0);
assertEquals(640, entry.getDistanceAlongBlockForTargetTime(t(20, 00)), 0.0);
assertNull(entry.getLastLocationForTargetTime(t(6, 40)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(10, 00)));
assertEquals(p4, entry.getLastLocationForTargetTime(t(13, 20)));
assertEquals(p5, entry.getLastLocationForTargetTime(t(16, 40)));
assertEquals(p5, entry.getLastLocationForTargetTime(t(20, 00)));
assertTrue(Double.isNaN(entry.getLastOrientationForTargetTime(t(6, 40))));
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(10, 00)), 0.0);
assertEquals(270.0, entry.getLastOrientationForTargetTime(t(13, 20)), 0.0);
assertEquals(180.0, entry.getLastOrientationForTargetTime(t(16, 40)), 0.0);
assertEquals(180.0, entry.getLastOrientationForTargetTime(t(20, 00)), 0.0);
assertNull(entry.getPhaseForTargetTime(t(6, 40)));
assertEquals(layover, entry.getPhaseForTargetTime(t(10, 00)));
assertEquals(layover, entry.getPhaseForTargetTime(t(13, 20)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(16, 40)));
assertEquals(inProgress, entry.getPhaseForTargetTime(t(20, 00)));
assertNull(entry.getStatusForTargetTime(t(6, 40)));
assertEquals("not ok", entry.getStatusForTargetTime(t(10, 00)));
assertEquals("not ok", entry.getStatusForTargetTime(t(13, 20)));
assertEquals("ok", entry.getStatusForTargetTime(t(16, 40)));
assertEquals("ok", entry.getStatusForTargetTime(t(20, 00)));
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class VehicleLocationRecordCacheImplTest method testClearCache.
@Test
public void testClearCache() throws InterruptedException {
long serviceDate = System.currentTimeMillis();
BlockEntryImpl blockA = block("blockA");
TripEntryImpl tripA = trip("tripA", "serviceId");
stopTime(0, null, tripA, time(9, 00), 0);
BlockConfigurationEntry blockConfigA = linkBlockTrips(blockA, tripA);
BlockInstance instanceA = new BlockInstance(blockConfigA, serviceDate);
BlockEntryImpl blockB = block("blockB");
TripEntryImpl tripB = trip("tripB", "serviceId");
stopTime(0, null, tripB, time(9, 00), 0);
BlockConfigurationEntry blockConfigB = linkBlockTrips(blockB, tripB);
BlockInstance instanceB = new BlockInstance(blockConfigB, serviceDate);
VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
cache.setBlockLocationRecordCacheWindowSize(20);
cache.addRecord(instanceA, record(20, "blockA", serviceDate, "vehicleA", 10.0), null, null);
Thread.sleep(100);
cache.addRecord(instanceB, record(30, "blockB", serviceDate, "vehicleB", 20.0), null, null);
Thread.sleep(100);
cache.addRecord(instanceA, record(40, "blockA", serviceDate, "vehicleC", 20.0), null, null);
Thread.sleep(100);
cache.addRecord(instanceB, record(50, "blockB", serviceDate, "vehicleD", 20.0), null, null);
cache.clearStaleRecords(System.currentTimeMillis() - 150);
VehicleLocationCacheElements cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
assertNull(cacheRecord);
cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
assertNull(cacheRecord);
cacheRecord = cache.getRecordForVehicleId(aid("vehicleC"));
assertEquals(aid("vehicleC"), cacheRecord.getLastElement().getRecord().getVehicleId());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleD"));
assertEquals(aid("vehicleD"), cacheRecord.getLastElement().getRecord().getVehicleId());
List<VehicleLocationCacheElements> records = cache.getRecordsForBlockInstance(instanceA);
assertEquals(1, records.size());
records = cache.getRecordsForBlockInstance(instanceB);
assertEquals(1, records.size());
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class VehicleLocationRecordCacheImplTest method testConcurrentOperations.
@Test
public void testConcurrentOperations() {
VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
cache.setBlockLocationRecordCacheWindowSize(2);
long serviceDate = System.currentTimeMillis();
int vid = 0;
for (int i = 0; i < 20; i++) {
BlockEntryImpl block = block(Integer.toString(i));
TripEntryImpl trip = trip(Integer.toString(i), "serviceId");
stopTime(0, null, trip, time(9, 00), 0);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, trip);
BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
for (int j = 0; j < 5; j++) {
AgencyAndId vehicleId = new AgencyAndId("1", Integer.toString(vid++));
RecordSource source = new RecordSource(blockInstance, vehicleId, cache);
Thread thread = new Thread(source);
thread.run();
}
}
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry 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);
}
use of org.onebusaway.transit_data_federation.services.transit_graph.BlockConfigurationEntry in project onebusaway-application-modules by camsys.
the class GtfsRealtimeTripLibraryTest method testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates.
@Test
public void testCreateVehicleLocationRecordForUpdate_NoStopTimeUpdates() {
TripUpdate tripUpdate = TripUpdate.newBuilder().setTrip(TripDescriptor.newBuilder().setTripId("tripA")).setDelay(120).setTimestamp(123456789).build();
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);
Mockito.when(_blockCalendarService.getActiveBlocks(Mockito.eq(blockA.getId()), Mockito.anyLong(), Mockito.anyLong())).thenReturn(Arrays.asList(blockInstanceA));
CombinedTripUpdatesAndVehiclePosition update = new CombinedTripUpdatesAndVehiclePosition();
update.block = new BlockDescriptor();
update.block.setBlockInstance(blockInstanceA);
update.tripUpdates = Arrays.asList(tripUpdate);
VehicleLocationRecord record = _library.createVehicleLocationRecordForUpdate(update);
assertEquals(123456789000L, record.getTimeOfRecord());
assertEquals(120, record.getScheduleDeviation(), 0.0);
}
Aggregations