mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-29 01:13:53 +03:00
start to display more detailed breakdown of active agents
This commit is contained in:
parent
27213995e5
commit
a0956995c9
@ -14,7 +14,7 @@ use ezgui::{
|
||||
use geom::{Circle, Distance, Line, PolyLine};
|
||||
use map_model::{Map, LANE_THICKNESS};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use sim::{Sim, SimOptions, TripID};
|
||||
use sim::{Sim, SimOptions, TripID, TripMode};
|
||||
|
||||
// TODO I took out speed controls
|
||||
pub struct ABTestMode {
|
||||
@ -100,9 +100,16 @@ impl State for ABTestMode {
|
||||
diff.lines.len()
|
||||
)));
|
||||
}
|
||||
let (active, unfinished, buses) = ui.primary.sim.num_trips();
|
||||
txt.add(Line(format!("{} active (+{} buses)", active, buses)));
|
||||
txt.add(Line(format!("{} unfinished", unfinished)));
|
||||
let (active, unfinished, by_mode) = ui.primary.sim.num_trips();
|
||||
txt.add(Line(format!("Active trips: {}", active)));
|
||||
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.event(ctx);
|
||||
|
@ -22,7 +22,7 @@ pub use gameplay::spawner::spawn_agents_around;
|
||||
pub use gameplay::GameplayMode;
|
||||
use geom::Duration;
|
||||
use map_model::MapEdits;
|
||||
use sim::Sim;
|
||||
use sim::{Sim, TripMode};
|
||||
|
||||
pub struct SandboxMode {
|
||||
speed: speed::SpeedControls,
|
||||
@ -95,9 +95,16 @@ impl State for SandboxMode {
|
||||
fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> Transition {
|
||||
{
|
||||
let mut txt = Text::new();
|
||||
let (active, unfinished, buses) = ui.primary.sim.num_trips();
|
||||
txt.add(Line(format!("{} active (+{} buses)", active, buses)));
|
||||
txt.add(Line(format!("{} unfinished", unfinished)));
|
||||
let (active, unfinished, by_mode) = ui.primary.sim.num_trips();
|
||||
txt.add(Line(format!("Active trips: {}", active)));
|
||||
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(""));
|
||||
{
|
||||
let edits = ui.primary.map.get_edits();
|
||||
|
@ -2,7 +2,7 @@ use crate::{
|
||||
AgentID, AgentMetadata, Analytics, CarID, Command, CreateCar, DrawCarInput, DrawPedCrowdInput,
|
||||
DrawPedestrianInput, DrivingGoal, DrivingSimState, Event, FinishedTrips, GetDrawAgents,
|
||||
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,
|
||||
VehicleSpec, VehicleType, WalkingSimState, BUS_LENGTH,
|
||||
};
|
||||
@ -14,7 +14,7 @@ use map_model::{
|
||||
PathRequest, PathStep, Traversable,
|
||||
};
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::panic;
|
||||
use std::time::Instant;
|
||||
|
||||
@ -755,13 +755,16 @@ impl Sim {
|
||||
self.time == Time::START_OF_DAY && self.is_done()
|
||||
}
|
||||
|
||||
// (active, unfinished, buses) prettyprinted
|
||||
pub fn num_trips(&self) -> (String, String, String) {
|
||||
let (active, unfinished, buses) = self.trips.num_trips();
|
||||
// (active, unfinished, by mode) prettyprinted
|
||||
pub fn num_trips(&self) -> (String, String, BTreeMap<TripMode, String>) {
|
||||
let (active, unfinished, by_mode) = self.trips.num_trips();
|
||||
(
|
||||
abstutil::prettyprint_usize(active),
|
||||
abstutil::prettyprint_usize(unfinished),
|
||||
abstutil::prettyprint_usize(buses),
|
||||
by_mode
|
||||
.into_iter()
|
||||
.map(|(k, v)| (k, abstutil::prettyprint_usize(v)))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
use crate::{
|
||||
AgentID, CarID, Command, CreateCar, CreatePedestrian, DrivingGoal, Event, ParkingSimState,
|
||||
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 map_model::{
|
||||
BuildingID, BusRouteID, BusStopID, IntersectionID, Map, PathConstraints, PathRequest, Position,
|
||||
@ -490,12 +490,19 @@ impl TripManager {
|
||||
)]
|
||||
}
|
||||
|
||||
// (active not including buses, unfinished, buses)
|
||||
pub fn num_trips(&self) -> (usize, usize, usize) {
|
||||
// (total active trips, unfinished trips, active trips by the trip's current mode)
|
||||
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.num_bus_trips,
|
||||
TripMode::all()
|
||||
.into_iter()
|
||||
.map(|k| (k, cnt.get(k)))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -711,6 +718,17 @@ impl TripMode {
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user