diff --git a/editor/src/mission/trips.rs b/editor/src/mission/trips.rs index d523d47a60..7e9f972b46 100644 --- a/editor/src/mission/trips.rs +++ b/editor/src/mission/trips.rs @@ -1,7 +1,7 @@ use crate::common::CommonState; use crate::helpers::ID; use crate::ui::{ShowEverything, UI}; -use abstutil::Timer; +use abstutil::{prettyprint_usize, Timer}; use ezgui::{Color, EventCtx, GfxCtx, Key, ModalMenu, Text}; use geom::{Circle, Distance, Duration, Pt2D, Speed}; use map_model::BuildingID; @@ -40,7 +40,11 @@ impl TripsVisualizer { // Returns true if the we're done pub fn event(&mut self, ctx: &mut EventCtx, ui: &mut UI) -> bool { let mut txt = Text::prompt("Trips Visualizer"); - txt.add_line(format!("Trip {}", self.current)); + txt.add_line(format!( + "Trip {}/{}", + prettyprint_usize(self.current), + prettyprint_usize(self.trips.len()) + )); let trip = &self.trips[self.current]; txt.add_line(format!("Leave at {}", trip.depart_at)); txt.add_line(format!("Purpose: {}", trip.purpose)); diff --git a/popdat/src/main.rs b/popdat/src/main.rs index dac4e6d79d..b0725e126a 100644 --- a/popdat/src/main.rs +++ b/popdat/src/main.rs @@ -1,14 +1,19 @@ fn main() { - let mut popdat = popdat::PopDat::import_all(&mut abstutil::Timer::new("importing popdat")); + let mut timer = abstutil::Timer::new("creating popdat"); + let mut popdat = popdat::PopDat::import_all(&mut timer); // TODO Productionize this. let parcels = popdat::psrc::import_parcels( "/home/dabreegster/Downloads/psrc/2014/landuse/parcels_urbansim.txt", + &mut timer, + ) + .unwrap(); + popdat.trips = popdat::psrc::import_trips( + "/home/dabreegster/Downloads/psrc/trips_2014.csv", + parcels, + &mut timer, ) .unwrap(); - popdat.trips = - popdat::psrc::import_trips("/home/dabreegster/Downloads/psrc/trips_2014.csv", parcels) - .unwrap(); abstutil::write_binary("../data/shapes/popdat", &popdat).unwrap(); } diff --git a/popdat/src/psrc.rs b/popdat/src/psrc.rs index ca53400665..437148212a 100644 --- a/popdat/src/psrc.rs +++ b/popdat/src/psrc.rs @@ -1,3 +1,4 @@ +use abstutil::{prettyprint_usize, FileWithProgress, Timer}; use geom::{Distance, Duration, GPSBounds, LonLat}; use serde_derive::{Deserialize, Serialize}; use std::collections::HashMap; @@ -28,9 +29,11 @@ pub enum TripMode { pub fn import_trips( path: &str, parcels: HashMap, + timer: &mut Timer, ) -> Result, failure::Error> { let mut trips = Vec::new(); - for rec in csv::Reader::from_reader(BufReader::new(File::open(path)?)).records() { + let (reader, done) = FileWithProgress::new(path)?; + for rec in csv::Reader::from_reader(reader).records() { let rec = rec?; // opcl @@ -73,37 +76,39 @@ pub fn import_trips( trip_time, trip_dist, }); - // TODO Read all trips - if trips.len() == 1_000 { - break; - } } + done(timer); Ok(trips) } // TODO Do we also need the zone ID, or is parcel ID globally unique? -pub fn import_parcels(path: &str) -> Result, failure::Error> { +pub fn import_parcels( + path: &str, + timer: &mut Timer, +) -> Result, failure::Error> { let mut coords = BufWriter::new(File::create("/tmp/parcels")?); let mut parcel_ids = Vec::new(); - // TODO Timer + + let (reader, done) = FileWithProgress::new(path)?; for rec in csv::ReaderBuilder::new() .delimiter(b' ') - .from_reader(File::open(path)?) + .from_reader(reader) .records() { let rec = rec?; parcel_ids.push(rec[15].to_string()); coords.write_fmt(format_args!("{} {}\n", &rec[25], &rec[26]))?; - // TODO convert it all - if parcel_ids.len() == 1_000_000 { - break; - } } + done(timer); coords.flush()?; // TODO Ideally we could just do the conversion directly without any dependencies, but the // formats are documented quite confusingly. Couldn't get the Rust crate for proj or GDAL // bindings to build. So just do this hack. + timer.start(&format!( + "run cs2cs on {} points", + prettyprint_usize(parcel_ids.len()) + )); let output = std::process::Command::new("cs2cs") // cs2cs +init=esri:102748 +to +init=epsg:4326 -f '%.5f' foo .args(vec![ @@ -116,11 +121,17 @@ pub fn import_parcels(path: &str) -> Result, failure::Er ]) .output()?; assert!(output.status.success()); + timer.stop(&format!( + "run cs2cs on {} points", + prettyprint_usize(parcel_ids.len()) + )); let bounds = GPSBounds::seattle_bounds(); let reader = BufReader::new(output.stdout.as_slice()); let mut result = HashMap::new(); + timer.start_iter("read cs2cs output", parcel_ids.len()); for (line, id) in reader.lines().zip(parcel_ids.into_iter()) { + timer.next(); let line = line?; let pieces: Vec<&str> = line.split_whitespace().collect(); let lon: f64 = pieces[0].parse()?;