Consistenty expose TripID and PersonID in some of the APIs. #392

This commit is contained in:
Dustin Carlino 2021-01-23 10:08:53 -08:00
parent 1a3d1b4cdb
commit 6f91c801c3

View File

@ -297,6 +297,7 @@ fn handle_command(
};
trips.push(FinishedTrip {
id: *id,
person: sim.trip_to_person(*id).unwrap(),
duration: *maybe_duration,
distance_crossed,
mode: *mode,
@ -310,10 +311,12 @@ fn handle_command(
.get_unzoomed_agents(map)
.into_iter()
.map(|a| AgentPosition {
id: a.id,
trip: sim.agent_to_trip(a.id),
person: a.person,
vehicle_type: a.id.to_vehicle_type(),
pos: a.pos.to_gps(map.get_gps_bounds()),
distance_crossed: sim.agent_properties(map, a.id).dist_crossed,
person: a.person,
})
.collect(),
})),
@ -327,7 +330,16 @@ fn handle_command(
.collect(),
})),
"/data/get-blocked-by-graph" => Ok(abstutil::to_json(&BlockedByGraph {
blocked_by: sim.get_blocked_by_graph(map),
blocked_by: sim
.get_blocked_by_graph(map)
.into_iter()
.map(|(id, (delay, cause))| {
(
id,
(delay, cause, sim.agent_to_trip(id), sim.agent_to_person(id)),
)
})
.collect(),
})),
"/data/trip-time-lower-bound" => {
let id = TripID(get("id")?.parse::<usize>()?);
@ -378,6 +390,7 @@ fn handle_command(
#[derive(Serialize)]
struct FinishedTrip {
id: TripID,
person: PersonID,
duration: Option<Duration>,
distance_crossed: Distance,
mode: TripMode,
@ -403,6 +416,12 @@ struct AgentPositions {
#[derive(Serialize)]
struct AgentPosition {
/// The agent's ID
id: AgentID,
/// None for buses
trip: Option<TripID>,
/// None for buses
person: Option<PersonID>,
/// None for pedestrians
vehicle_type: Option<VehicleType>,
/// The agent's current position. For pedestrians, this is their center. For vehicles, this
@ -421,8 +440,6 @@ struct AgentPosition {
/// - At the very end of a driving trip, the agent may wind up crossing slightly more or less
/// than the total path length, due to where they park along that last road.
distance_crossed: Distance,
/// None for buses
person: Option<PersonID>,
}
#[derive(Serialize)]
@ -443,9 +460,10 @@ struct TrafficSignalState {
#[derive(Serialize)]
struct BlockedByGraph {
/// Each entry indicates that some agent has been stuck in one place for some amount of time,
/// due to being blocked by another agent or because they're waiting at an intersection.
/// due to being blocked by another agent or because they're waiting at an intersection. Unless
/// the agent is a bus, then the TripID and PersonID will also be filled out.
#[serde(serialize_with = "serialize_btreemap")]
blocked_by: BTreeMap<AgentID, (Duration, DelayCause)>,
blocked_by: BTreeMap<AgentID, (Duration, DelayCause, Option<TripID>, Option<PersonID>)>,
}
#[derive(Deserialize)]