just kidding, use two counters in meters panel

This commit is contained in:
Dustin Carlino 2020-01-19 15:34:53 -08:00
parent 7ce3d5dd24
commit e9d40fe494
4 changed files with 24 additions and 41 deletions

View File

@ -72,8 +72,8 @@ impl State for ABTestMode {
diff.lines.len() diff.lines.len()
))); )));
} }
let (percent, unfinished, by_mode) = ui.primary.sim.num_trips(); let (finished, unfinished, by_mode) = ui.primary.sim.num_trips();
txt.add(Line(format!("Percent of trips completed: {}", percent))); txt.add(Line(format!("Finished trips: {}", finished)));
txt.add(Line(format!("Unfinished trips: {}", unfinished))); txt.add(Line(format!("Unfinished trips: {}", unfinished)));
txt.add(Line(format!( txt.add(Line(format!(
"Peds {}, Bikes {}, Cars {}, Buses {}", "Peds {}, Bikes {}, Cars {}, Buses {}",

View File

@ -15,12 +15,12 @@ use crate::pregame::main_menu;
use crate::ui::{ShowEverything, UI}; use crate::ui::{ShowEverything, UI};
use abstutil::Timer; use abstutil::Timer;
use ezgui::{ use ezgui::{
hotkey, lctrl, Choice, Color, Composite, DrawBoth, EventCtx, EventLoopMode, GeomBatch, GfxCtx, hotkey, lctrl, Choice, Color, Composite, EventCtx, EventLoopMode, GfxCtx, HorizontalAlignment,
HorizontalAlignment, JustDraw, Key, Line, ManagedWidget, ScreenPt, Text, VerticalAlignment, Key, Line, ManagedWidget, Text, VerticalAlignment,
}; };
pub use gameplay::spawner::spawn_agents_around; pub use gameplay::spawner::spawn_agents_around;
pub use gameplay::GameplayMode; pub use gameplay::GameplayMode;
use geom::{Polygon, Time}; use geom::Time;
use map_model::MapEdits; use map_model::MapEdits;
use sim::TripMode; use sim::TripMode;
pub use speed::{SpeedControls, TimePanel}; pub use speed::{SpeedControls, TimePanel};
@ -289,7 +289,7 @@ struct AgentMeter {
impl AgentMeter { impl AgentMeter {
fn new(ctx: &mut EventCtx, ui: &UI) -> AgentMeter { fn new(ctx: &mut EventCtx, ui: &UI) -> AgentMeter {
let (percent, unfinished, by_mode) = ui.primary.sim.num_trips(); let (finished, unfinished, by_mode) = ui.primary.sim.num_trips();
let composite = Composite::new( let composite = Composite::new(
ManagedWidget::col(vec![ ManagedWidget::col(vec![
@ -305,25 +305,10 @@ impl AgentMeter {
]) ])
.centered(), .centered(),
{ {
// TODO Manaully tuned. :\ let mut txt = Text::new();
let width = 350.0; txt.add(Line(format!("Finished trips: {}", finished)));
let height = 30.0; txt.add(Line(format!("Unfinished trips: {}", unfinished)));
ManagedWidget::draw_text(ctx, txt)
let txt = Text::from(
Line(format!("Unfinished trips: {}", unfinished)).fg(Color::BLACK),
);
let mut batch =
GeomBatch::from(vec![(Color::WHITE, Polygon::rectangle(width, height))]);
if percent != 0.0 {
batch.push(Color::YELLOW, Polygon::rectangle(percent * width, height));
}
ManagedWidget::just_draw(JustDraw::wrap(DrawBoth::new(
ctx,
batch,
vec![(txt, ScreenPt::new(0.0, 0.0))],
)))
.margin(10)
}, },
// TODO The SVG button uses clip and doesn't seem to work // TODO The SVG button uses clip and doesn't seem to work
crate::managed::Composite::text_button( crate::managed::Composite::text_button(

View File

@ -660,11 +660,11 @@ impl Sim {
let dt_real = Duration::realtime_elapsed(last_print); let dt_real = Duration::realtime_elapsed(last_print);
if dt_real >= Duration::seconds(1.0) { if dt_real >= Duration::seconds(1.0) {
let (percent, unfinished, _) = self.num_trips(); let (finished, unfinished, _) = self.num_trips();
println!( println!(
"{}: {}% trips complete, {} unfinished, speed = {:.2}x, {}", "{}: {} trips finished, {} unfinished, speed = {:.2}x, {}",
self.time(), self.time(),
percent * 100.0, finished,
unfinished, unfinished,
(self.time() - last_sim_time) / dt_real, (self.time() - last_sim_time) / dt_real,
self.scheduler.describe_stats() self.scheduler.describe_stats()
@ -816,12 +816,12 @@ impl Sim {
self.time == Time::START_OF_DAY && self.is_done() self.time == Time::START_OF_DAY && self.is_done()
} }
// (percent of trips complete, number of unfinished trips, number of active by mode) // (number of finished trips, number of unfinished trips, number of active by mode)
// prettyprinted // prettyprinted
pub fn num_trips(&self) -> (f64, String, BTreeMap<TripMode, String>) { pub fn num_trips(&self) -> (String, String, BTreeMap<TripMode, String>) {
let (percent, unfinished, by_mode) = self.trips.num_trips(); let (finished, unfinished, by_mode) = self.trips.num_trips();
( (
percent, abstutil::prettyprint_usize(finished),
abstutil::prettyprint_usize(unfinished), abstutil::prettyprint_usize(unfinished),
by_mode by_mode
.into_iter() .into_iter()

View File

@ -492,8 +492,8 @@ impl TripManager {
} }
} }
// (percent of trips completed, unfinished trips, active trips by the trip's current mode) // (finished trips, unfinished trips, active trips by the trip's current mode)
pub fn num_trips(&self) -> (f64, usize, BTreeMap<TripMode, usize>) { pub fn num_trips(&self) -> (usize, usize, BTreeMap<TripMode, usize>) {
let mut cnt = Counter::new(); let mut cnt = Counter::new();
for a in self.active_trip_mode.keys() { for a in self.active_trip_mode.keys() {
cnt.inc(TripMode::from_agent(*a)); cnt.inc(TripMode::from_agent(*a));
@ -502,13 +502,11 @@ impl TripManager {
.into_iter() .into_iter()
.map(|k| (k, cnt.get(k))) .map(|k| (k, cnt.get(k)))
.collect(); .collect();
let percent = if self.trips.len() == 0 { (
0.0 self.trips.len() - self.unfinished_trips,
} else { self.unfinished_trips,
1.0 - ((self.unfinished_trips as f64) / (self.trips.len() as f64)) per_mode,
}; )
(percent, self.unfinished_trips, per_mode)
} }
pub fn is_done(&self) -> bool { pub fn is_done(&self) -> bool {