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()
)));
}
let (percent, unfinished, by_mode) = ui.primary.sim.num_trips();
txt.add(Line(format!("Percent of trips completed: {}", percent)));
let (finished, unfinished, by_mode) = ui.primary.sim.num_trips();
txt.add(Line(format!("Finished trips: {}", finished)));
txt.add(Line(format!("Unfinished trips: {}", unfinished)));
txt.add(Line(format!(
"Peds {}, Bikes {}, Cars {}, Buses {}",

View File

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

View File

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

View File

@ -492,8 +492,8 @@ impl TripManager {
}
}
// (percent of trips completed, unfinished trips, active trips by the trip's current mode)
pub fn num_trips(&self) -> (f64, usize, BTreeMap<TripMode, usize>) {
// (finished 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));
@ -502,13 +502,11 @@ impl TripManager {
.into_iter()
.map(|k| (k, cnt.get(k)))
.collect();
let percent = if self.trips.len() == 0 {
0.0
} else {
1.0 - ((self.unfinished_trips as f64) / (self.trips.len() as f64))
};
(percent, self.unfinished_trips, per_mode)
(
self.trips.len() - self.unfinished_trips,
self.unfinished_trips,
per_mode,
)
}
pub fn is_done(&self) -> bool {