start to display more detailed breakdown of active agents

This commit is contained in:
Dustin Carlino 2019-12-02 14:44:03 -08:00
parent 27213995e5
commit a0956995c9
4 changed files with 55 additions and 20 deletions

View File

@ -14,7 +14,7 @@ use ezgui::{
use geom::{Circle, Distance, Line, PolyLine}; use geom::{Circle, Distance, Line, PolyLine};
use map_model::{Map, LANE_THICKNESS}; use map_model::{Map, LANE_THICKNESS};
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use sim::{Sim, SimOptions, TripID}; use sim::{Sim, SimOptions, TripID, TripMode};
// TODO I took out speed controls // TODO I took out speed controls
pub struct ABTestMode { pub struct ABTestMode {
@ -100,9 +100,16 @@ impl State for ABTestMode {
diff.lines.len() diff.lines.len()
))); )));
} }
let (active, unfinished, buses) = ui.primary.sim.num_trips(); let (active, unfinished, by_mode) = ui.primary.sim.num_trips();
txt.add(Line(format!("{} active (+{} buses)", active, buses))); txt.add(Line(format!("Active trips: {}", active)));
txt.add(Line(format!("{} unfinished", unfinished))); txt.add(Line(format!("Unfinished trips: {}", unfinished)));
txt.add(Line(format!(
"Peds {}, Bikes {}, Cars {}, Buses {}",
by_mode[&TripMode::Walk],
by_mode[&TripMode::Bike],
by_mode[&TripMode::Drive],
by_mode[&TripMode::Transit]
)));
self.menu.set_info(ctx, txt); self.menu.set_info(ctx, txt);
} }
self.menu.event(ctx); self.menu.event(ctx);

View File

@ -22,7 +22,7 @@ pub use gameplay::spawner::spawn_agents_around;
pub use gameplay::GameplayMode; pub use gameplay::GameplayMode;
use geom::Duration; use geom::Duration;
use map_model::MapEdits; use map_model::MapEdits;
use sim::Sim; use sim::{Sim, TripMode};
pub struct SandboxMode { pub struct SandboxMode {
speed: speed::SpeedControls, speed: speed::SpeedControls,
@ -95,9 +95,16 @@ impl State for SandboxMode {
fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> Transition { fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> Transition {
{ {
let mut txt = Text::new(); let mut txt = Text::new();
let (active, unfinished, buses) = ui.primary.sim.num_trips(); let (active, unfinished, by_mode) = ui.primary.sim.num_trips();
txt.add(Line(format!("{} active (+{} buses)", active, buses))); txt.add(Line(format!("Active trips: {}", active)));
txt.add(Line(format!("{} unfinished", unfinished))); txt.add(Line(format!("Unfinished trips: {}", unfinished)));
txt.add(Line(format!(
"Peds {}, Bikes {}, Cars {}, Buses {}",
by_mode[&TripMode::Walk],
by_mode[&TripMode::Bike],
by_mode[&TripMode::Drive],
by_mode[&TripMode::Transit]
)));
txt.add(Line("")); txt.add(Line(""));
{ {
let edits = ui.primary.map.get_edits(); let edits = ui.primary.map.get_edits();

View File

@ -2,7 +2,7 @@ use crate::{
AgentID, AgentMetadata, Analytics, CarID, Command, CreateCar, DrawCarInput, DrawPedCrowdInput, AgentID, AgentMetadata, Analytics, CarID, Command, CreateCar, DrawCarInput, DrawPedCrowdInput,
DrawPedestrianInput, DrivingGoal, DrivingSimState, Event, FinishedTrips, GetDrawAgents, DrawPedestrianInput, DrivingGoal, DrivingSimState, Event, FinishedTrips, GetDrawAgents,
IntersectionSimState, ParkedCar, ParkingSimState, ParkingSpot, PedestrianID, Router, Scheduler, IntersectionSimState, ParkedCar, ParkingSimState, ParkingSpot, PedestrianID, Router, Scheduler,
SidewalkPOI, SidewalkSpot, TransitSimState, TripCount, TripID, TripLeg, TripManager, SidewalkPOI, SidewalkSpot, TransitSimState, TripCount, TripID, TripLeg, TripManager, TripMode,
TripPositions, TripResult, TripSpawner, TripSpec, TripStart, TripStatus, UnzoomedAgent, TripPositions, TripResult, TripSpawner, TripSpec, TripStart, TripStatus, UnzoomedAgent,
VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH, VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH,
}; };
@ -14,7 +14,7 @@ use map_model::{
PathRequest, PathStep, Traversable, PathRequest, PathStep, Traversable,
}; };
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::collections::HashSet; use std::collections::{BTreeMap, HashSet};
use std::panic; use std::panic;
use std::time::Instant; use std::time::Instant;
@ -755,13 +755,16 @@ impl Sim {
self.time == Time::START_OF_DAY && self.is_done() self.time == Time::START_OF_DAY && self.is_done()
} }
// (active, unfinished, buses) prettyprinted // (active, unfinished, by mode) prettyprinted
pub fn num_trips(&self) -> (String, String, String) { pub fn num_trips(&self) -> (String, String, BTreeMap<TripMode, String>) {
let (active, unfinished, buses) = self.trips.num_trips(); let (active, unfinished, by_mode) = self.trips.num_trips();
( (
abstutil::prettyprint_usize(active), abstutil::prettyprint_usize(active),
abstutil::prettyprint_usize(unfinished), abstutil::prettyprint_usize(unfinished),
abstutil::prettyprint_usize(buses), by_mode
.into_iter()
.map(|(k, v)| (k, abstutil::prettyprint_usize(v)))
.collect(),
) )
} }

View File

@ -1,9 +1,9 @@
use crate::{ use crate::{
AgentID, CarID, Command, CreateCar, CreatePedestrian, DrivingGoal, Event, ParkingSimState, AgentID, CarID, Command, CreateCar, CreatePedestrian, DrivingGoal, Event, ParkingSimState,
ParkingSpot, PedestrianID, Scheduler, SidewalkPOI, SidewalkSpot, TransitSimState, TripID, ParkingSpot, PedestrianID, Scheduler, SidewalkPOI, SidewalkSpot, TransitSimState, TripID,
Vehicle, WalkingSimState, Vehicle, VehicleType, WalkingSimState,
}; };
use abstutil::{deserialize_btreemap, serialize_btreemap}; use abstutil::{deserialize_btreemap, serialize_btreemap, Counter};
use geom::{Duration, Speed, Time}; use geom::{Duration, Speed, Time};
use map_model::{ use map_model::{
BuildingID, BusRouteID, BusStopID, IntersectionID, Map, PathConstraints, PathRequest, Position, BuildingID, BusRouteID, BusStopID, IntersectionID, Map, PathConstraints, PathRequest, Position,
@ -490,12 +490,19 @@ impl TripManager {
)] )]
} }
// (active not including buses, unfinished, buses) // (total active trips, unfinished trips, active trips by the trip's current mode)
pub fn num_trips(&self) -> (usize, usize, usize) { pub fn num_trips(&self) -> (usize, usize, BTreeMap<TripMode, usize>) {
let mut cnt = Counter::new();
for a in self.active_trip_mode.keys() {
cnt.inc(TripMode::from_agent(*a));
}
( (
self.active_trip_mode.len() - self.num_bus_trips, self.active_trip_mode.len(),
self.unfinished_trips, self.unfinished_trips,
self.num_bus_trips, TripMode::all()
.into_iter()
.map(|k| (k, cnt.get(k)))
.collect(),
) )
} }
@ -711,6 +718,17 @@ impl TripMode {
TripMode::Drive, TripMode::Drive,
] ]
} }
fn from_agent(id: AgentID) -> TripMode {
match id {
AgentID::Pedestrian(_) => TripMode::Walk,
AgentID::Car(id) => match id.1 {
VehicleType::Car => TripMode::Drive,
VehicleType::Bike => TripMode::Bike,
VehicleType::Bus => TripMode::Transit,
},
}
}
} }
impl std::fmt::Display for TripMode { impl std::fmt::Display for TripMode {