Expose continuous distance crossed for vehicles. #392

This commit is contained in:
Dustin Carlino 2020-12-16 15:29:55 -08:00
parent b39aa2a45f
commit 7c973ecacf
2 changed files with 26 additions and 9 deletions

View File

@ -386,10 +386,13 @@ struct AgentPosition {
/// The distance crossed so far by the agent, in meters. There are some caveats to this value:
/// - The distance along driveways between buildings/parking lots and the road doesn't count
/// here.
/// - The distance will not change while an agent is travelling along a lane; it'll only
/// increment when they completely cross one step of their path.
/// - The distance only represents the current leg of the trip. If somebody walks to a car, the
/// distance will reset when they begin driving, and also vehicle_type will change.
/// - No meaning for bus passengers currently.
/// - For buses and trains, the value will reset every time the vehicle reaches the next
/// transit stop.
/// - The value might be slightly undercounted or overcounted if the path crosses into or out
/// of an access-restricted or capped zone.
distance_crossed: Distance,
/// None for buses
person: Option<PersonID>,

View File

@ -1017,11 +1017,21 @@ impl DrivingSimState {
let path = car.router.get_path();
let time_spent_waiting = car.state.time_spent_waiting(now);
// In all cases, we can figure out exactly where we are along the current queue, then
// assume we've travelled from the start of that, unless it's the very first step.
let front = self.get_car_front(now, car);
let current_state_dist =
if car.router.head() == Traversable::Lane(path.get_req().start.lane()) {
front - path.get_req().start.dist_along()
} else {
front
};
AgentProperties {
total_time: now - car.started_at,
waiting_here: time_spent_waiting,
total_waiting: car.total_blocked_time + time_spent_waiting,
dist_crossed: path.crossed_so_far(),
dist_crossed: path.crossed_so_far() + current_state_dist,
total_dist: path.total_length(),
}
}
@ -1045,12 +1055,7 @@ impl DrivingSimState {
dist_ahead: Option<Distance>,
) -> Option<PolyLine> {
let car = self.cars.get(&id)?;
let front = self.queues[&car.router.head()]
.get_car_positions(now, &self.cars, &self.queues)
.into_iter()
.find(|(c, _)| *c == id)
.unwrap()
.1;
let front = self.get_car_front(now, car);
car.router.get_path().trace(map, front, dist_ahead)
}
@ -1161,6 +1166,15 @@ impl DrivingSimState {
intersections.populate_blocked_by(now, &mut graph, map, &self.cars, &self.queues);
graph
}
fn get_car_front(&self, now: Time, car: &Car) -> Distance {
self.queues[&car.router.head()]
.get_car_positions(now, &self.cars, &self.queues)
.into_iter()
.find(|(c, _)| *c == car.vehicle.id)
.unwrap()
.1
}
}
impl IndexableKey for CarID {