use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class BlockLocationRecordCacheImplTest method testConcurrentOperations.
@Test
public void testConcurrentOperations() {
BlockLocationRecordCacheImpl cache = new BlockLocationRecordCacheImpl();
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.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class BlockLocationServiceImplTest method testWithShapeInfo.
@Test
public void testWithShapeInfo() {
StopEntryImpl stopA = stop("a", 47.5, -122.5);
StopEntryImpl stopB = stop("b", 47.6, -122.4);
StopEntryImpl stopC = stop("c", 47.5, -122.3);
BlockEntryImpl block = block("block");
TripEntryImpl tripA = trip("tripA", "serviceId");
TripEntryImpl tripB = trip("tripB", "serviceId");
stopTime(0, stopA, tripA, 30, 90, 0);
stopTime(1, stopB, tripA, 120, 120, 100);
stopTime(2, stopC, tripA, 180, 210, 200);
stopTime(3, stopC, tripB, 240, 240, 300);
stopTime(4, stopB, tripB, 270, 270, 400);
stopTime(5, stopA, tripB, 300, 300, 500);
BlockConfigurationEntry blockConfig = linkBlockTrips(block, tripA, tripB);
long serviceDate = 1000 * 1000;
double epsilon = 0.001;
TargetTime target = new TargetTime(t(serviceDate, 0, 0), System.currentTimeMillis());
BlockInstance blockInstance = new BlockInstance(blockConfig, serviceDate);
BlockLocation location = _service.getLocationForBlockInstance(blockInstance, target);
assertNull(location);
ScheduledBlockLocation p = new ScheduledBlockLocation();
p.setActiveTrip(blockConfig.getTrips().get(0));
p.setClosestStop(blockConfig.getStopTimes().get(0));
p.setClosestStopTimeOffset(0);
p.setDistanceAlongBlock(0);
p.setLocation(new CoordinatePoint(stopA.getStopLat(), stopA.getStopLon()));
p.setInService(true);
Mockito.when(_blockLocationService.getScheduledBlockLocationFromScheduledTime(blockConfig, 1800)).thenReturn(p);
target = new TargetTime(t(serviceDate, 0, 30), System.currentTimeMillis());
location = _service.getLocationForBlockInstance(blockInstance, target);
assertTrue(location.isInService());
assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
assertEquals(0, location.getClosestStopTimeOffset());
assertEquals(stopA.getStopLocation(), location.getLocation());
assertFalse(location.isScheduleDeviationSet());
assertTrue(Double.isNaN(location.getScheduleDeviation()));
assertFalse(location.isDistanceAlongBlockSet());
assertTrue(Double.isNaN(location.getDistanceAlongBlock()));
assertEquals(blockInstance, location.getBlockInstance());
assertEquals(0, location.getLastUpdateTime());
assertEquals(blockConfig.getTrips().get(0), location.getActiveTrip());
assertNull(location.getVehicleId());
assertEquals(47.5, location.getLocation().getLat(), epsilon);
assertEquals(-122.5, location.getLocation().getLon(), epsilon);
assertEquals(blockConfig.getStopTimes().get(0), location.getClosestStop());
assertEquals(0, location.getClosestStopTimeOffset());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class VehicleLocationRecordCacheImplTest method testSimpleOperations.
@Test
public void testSimpleOperations() {
long serviceDate = System.currentTimeMillis();
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, serviceDate);
VehicleLocationRecordCacheImpl cache = new VehicleLocationRecordCacheImpl();
cache.setBlockLocationRecordCacheWindowSize(20);
List<VehicleLocationCacheElements> records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(0, records.size());
VehicleLocationCacheElements cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
assertNull(cacheRecord);
cache.addRecord(blockInstance, record(20, "blockA", serviceDate, "vehicleA", 10.0), null, null);
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
cacheRecord = records.get(0);
VehicleLocationRecord record = cacheRecord.getLastElement().getRecord();
assertEquals(20, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleA"), record.getVehicleId());
VehicleLocationCacheElements cacheRecord2 = cache.getRecordForVehicleId(aid("vehicleA"));
assertSame(cacheRecord, cacheRecord2);
cache.addRecord(blockInstance, record(30, "blockA", serviceDate, "vehicleA", 20.0), null, null);
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
cacheRecord = records.get(0);
record = cacheRecord.getLastElement().getRecord();
assertEquals(30, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleA"), record.getVehicleId());
cacheRecord2 = cache.getRecordForVehicleId(aid("vehicleA"));
assertSame(cacheRecord, cacheRecord2);
cache.addRecord(blockInstance, record(40, "blockA", serviceDate, "vehicleB", 5.0), null, null);
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(2, records.size());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
record = cacheRecord.getLastElement().getRecord();
assertEquals(30, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleA"), record.getVehicleId());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
record = cacheRecord.getLastElement().getRecord();
assertEquals(40, record.getTimeOfRecord());
assertEquals(blockInstance, cacheRecord.getBlockInstance());
assertEquals(aid("vehicleB"), record.getVehicleId());
cache.clearRecordsForVehicleId(aid("vehicleA"));
records = cache.getRecordsForBlockInstance(blockInstance);
assertEquals(1, records.size());
cacheRecord = cache.getRecordForVehicleId(aid("vehicleA"));
assertNull(cacheRecord);
cacheRecord = cache.getRecordForVehicleId(aid("vehicleB"));
assertEquals(aid("vehicleB"), cacheRecord.getLastElement().getRecord().getVehicleId());
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class BlockEntriesFactory method processBlockTrips.
/**
* We loop over blocks of trips, removing any trip that has no stop times,
* sorting the remaining trips into the proper order, setting the 'nextTrip'
* property for trips in the block, and setting the 'nextStop' property for
* stops in the block.
*
* @return
*/
private void processBlockTrips(TransitGraphImpl graph, Map<AgencyAndId, List<TripEntryImpl>> tripsByBlockId) {
int blockIndex = 0;
int logInterval = LoggingIntervalUtil.getAppropriateLoggingInterval(tripsByBlockId.keySet().size());
for (Map.Entry<AgencyAndId, List<TripEntryImpl>> entry : tripsByBlockId.entrySet()) {
if (blockIndex % logInterval == 0)
_log.info("block: " + blockIndex + "/" + tripsByBlockId.size());
blockIndex++;
AgencyAndId blockId = entry.getKey();
List<TripEntryImpl> tripsInBlock = entry.getValue();
if (tripsInBlock.isEmpty()) {
_log.warn("no trips for block=" + blockId);
continue;
}
BlockEntryImpl blockEntry = new BlockEntryImpl();
blockEntry.setId(blockId);
_blockConfigurationEntriesFactory.processBlockConfigurations(blockEntry, tripsInBlock);
graph.putBlockEntry(blockEntry);
// Wire up the trip to block link
for (TripEntryImpl trip : tripsInBlock) trip.setBlock(blockEntry);
}
}
use of org.onebusaway.transit_data_federation.impl.transit_graph.TripEntryImpl in project onebusaway-application-modules by camsys.
the class DistanceAlongShapeLibrary method constructError.
private void constructError(ShapePoints shapePoints, List<StopTimeEntryImpl> stopTimes, List<List<PointAndIndex>> possibleAssignments, UTMProjection projection) throws InvalidStopToShapeMappingException {
StopTimeEntryImpl first = stopTimes.get(0);
StopTimeEntryImpl last = stopTimes.get(stopTimes.size() - 1);
_log.error("We were attempting to compute the distance along a particular trip for each stop time of that trip by " + "snapping them to the shape for that trip. However, we could not find an assignment for each stop time " + "where the distance traveled along the shape for each stop time was strictly increasing (aka a stop time " + "seemed to travel backwards). For more information on errors of this kind, see:\n" + " https://github.com/OneBusAway/onebusaway-application-modules/wiki/Stop-to-Shape-Matching");
TripEntryImpl trip = first.getTrip();
_log.error("error constructing stop-time distances along shape for trip=" + trip.getId() + " shape=" + trip.getShapeId() + " firstStopTime=" + first.getId() + " lastStopTime=" + last.getId());
StringBuilder b = new StringBuilder();
int index = 0;
b.append("# potential assignments:\n");
b.append("# stopLat stopLon stopId\n");
b.append("# locationOnShapeLat locationOnShapeLon distanceAlongShape distanceFromShape shapePointIndex\n");
b.append("# ...\n");
double prevMaxDistanceAlongShape = Double.NEGATIVE_INFINITY;
for (List<PointAndIndex> possible : possibleAssignments) {
StopTimeEntryImpl stopTime = stopTimes.get(index);
StopEntryImpl stop = stopTime.getStop();
b.append(stop.getStopLat());
b.append(' ');
b.append(stop.getStopLon());
b.append(' ');
b.append(index);
b.append(' ');
b.append(stop.getId());
b.append('\n');
double maxDistanceAlongShape = Double.NEGATIVE_INFINITY;
double minDistanceAlongShape = Double.POSITIVE_INFINITY;
for (PointAndIndex pindex : possible) {
b.append(" ");
b.append(projection.reverse(pindex.point));
b.append(' ');
b.append(_errorFormatter.format(pindex.distanceAlongShape));
b.append(' ');
b.append(_errorFormatter.format(pindex.distanceFromTarget));
b.append(' ');
b.append(pindex.index);
b.append("\n");
maxDistanceAlongShape = Math.max(maxDistanceAlongShape, pindex.distanceAlongShape);
minDistanceAlongShape = Math.min(minDistanceAlongShape, pindex.distanceAlongShape);
}
if (minDistanceAlongShape < prevMaxDistanceAlongShape) {
b.append(" ^ potential problem here ^\n");
}
prevMaxDistanceAlongShape = maxDistanceAlongShape;
index++;
}
_log.error(b.toString());
if (_shapeIdsWeHavePrinted.add(trip.getShapeId())) {
b = new StringBuilder();
index = 0;
for (int i = 0; i < shapePoints.getSize(); i++) {
b.append(shapePoints.getLatForIndex(i));
b.append(' ');
b.append(shapePoints.getLonForIndex(i));
b.append(' ');
b.append(shapePoints.getDistTraveledForIndex(i));
b.append('\n');
}
_log.error("shape points:\n" + b.toString());
}
throw new InvalidStopToShapeMappingException(first.getTrip());
}
Aggregations