do a/b test setup in one loading screen timer

This commit is contained in:
Dustin Carlino 2019-06-07 10:59:13 -07:00
parent a59c120e00
commit 7d4df3df8e
3 changed files with 61 additions and 58 deletions

View File

@ -88,45 +88,56 @@ fn pick_ab_test(map: &Map, mut wizard: WrappedWizard) -> Option<ABTest> {
}
fn launch_test(test: &ABTest, ui: &mut UI, ctx: &mut EventCtx) -> Mode {
println!("Launching A/B test {}...", test.test_name);
let load = PathBuf::from(format!(
"../data/scenarios/{}/{}",
test.map_name, test.scenario_name
));
let current_flags = &ui.primary.current_flags;
let rng_seed = if current_flags.sim_flags.rng_seed.is_some() {
current_flags.sim_flags.rng_seed
} else {
Some(42)
};
let (primary, secondary) = ctx.loading_screen(
&format!("Launching A/B test {}", test.test_name),
|ctx, mut timer| {
let load = PathBuf::from(format!(
"../data/scenarios/{}/{}",
test.map_name, test.scenario_name
));
let current_flags = &ui.primary.current_flags;
let rng_seed = if current_flags.sim_flags.rng_seed.is_some() {
current_flags.sim_flags.rng_seed
} else {
Some(42)
};
// TODO Cheaper to load the edits for the map and then instantiate the scenario for the
// primary.
let primary = PerMapUI::new(
Flags {
sim_flags: SimFlags {
load: load.clone(),
rng_seed,
run_name: Some(format!("{} with {}", test.test_name, test.edits1_name)),
edits_name: test.edits1_name.clone(),
},
..current_flags.clone()
// TODO Cheaper to load the edits for the map and then instantiate the scenario for the
// primary.
timer.start("load primary");
let primary = PerMapUI::new(
Flags {
sim_flags: SimFlags {
load: load.clone(),
rng_seed,
run_name: Some(format!("{} with {}", test.test_name, test.edits1_name)),
edits_name: test.edits1_name.clone(),
},
..current_flags.clone()
},
&ui.cs,
ctx,
&mut timer,
);
timer.stop("load primary");
timer.start("load secondary");
let secondary = PerMapUI::new(
Flags {
sim_flags: SimFlags {
load,
rng_seed,
run_name: Some(format!("{} with {}", test.test_name, test.edits2_name)),
edits_name: test.edits2_name.clone(),
},
..current_flags.clone()
},
&ui.cs,
ctx,
&mut timer,
);
timer.stop("load secondary");
(primary, secondary)
},
&ui.cs,
ctx,
);
let secondary = PerMapUI::new(
Flags {
sim_flags: SimFlags {
load,
rng_seed,
run_name: Some(format!("{} with {}", test.test_name, test.edits2_name)),
edits_name: test.edits2_name.clone(),
},
..current_flags.clone()
},
&ui.cs,
ctx,
);
ui.primary = primary;

View File

@ -4,7 +4,7 @@ use crate::render::{
MIN_ZOOM_FOR_DETAIL,
};
use abstutil;
use abstutil::MeasureMemory;
use abstutil::{MeasureMemory, Timer};
use ezgui::{Color, EventCtx, GeomBatch, GfxCtx, Prerender};
use geom::{Bounds, Circle, Distance, Duration};
use map_model::{Map, Traversable};
@ -21,10 +21,10 @@ pub struct UI {
impl UI {
pub fn new(flags: Flags, ctx: &mut EventCtx) -> UI {
let cs = ColorScheme::load().unwrap();
UI {
primary: PerMapUI::new(flags, &cs, ctx),
cs,
}
let primary = ctx.loading_screen("load map", |ctx, mut timer| {
PerMapUI::new(flags, &cs, ctx, &mut timer)
});
UI { primary, cs }
}
pub fn draw(
@ -407,19 +407,15 @@ pub struct PerMapUI {
}
impl PerMapUI {
pub fn new(flags: Flags, cs: &ColorScheme, ctx: &mut EventCtx) -> PerMapUI {
let (map, sim, draw_map) = ctx.loading_screen("load map", |ctx, timer| {
let mut mem = MeasureMemory::new();
let (map, sim, _) = flags.sim_flags.load(Some(Duration::minutes(30)), timer);
mem.reset("Map and Sim", timer);
pub fn new(flags: Flags, cs: &ColorScheme, ctx: &mut EventCtx, timer: &mut Timer) -> PerMapUI {
let mut mem = MeasureMemory::new();
let (map, sim, _) = flags.sim_flags.load(Some(Duration::minutes(30)), timer);
mem.reset("Map and Sim", timer);
timer.start("draw_map");
let draw_map = DrawMap::new(&map, &flags, cs, ctx.prerender, timer);
timer.stop("draw_map");
mem.reset("DrawMap", timer);
(map, sim, draw_map)
});
timer.start("draw_map");
let draw_map = DrawMap::new(&map, &flags, cs, ctx.prerender, timer);
timer.stop("draw_map");
mem.reset("DrawMap", timer);
PerMapUI {
map,

View File

@ -214,10 +214,6 @@ impl Sim {
) {
self.trips.agent_starting_trip_leg(AgentID::Car(id), trip);
self.transit.bus_created(id, route.id, next_stop_idx);
timer.note(format!(
"Spawned bus {} for route {} ({})",
id, route.name, route.id
));
results.push(id);
} else {
timer.warn(format!(