mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-25 23:43:25 +03:00
also display estimated total number of cars in the tract
This commit is contained in:
parent
0f88e67a01
commit
28eb670bf9
@ -27,6 +27,7 @@ struct Tract {
|
||||
|
||||
num_bldgs: usize,
|
||||
num_parking_spots: usize,
|
||||
total_owned_cars: usize,
|
||||
}
|
||||
|
||||
impl DataVisualizer {
|
||||
@ -67,6 +68,10 @@ impl DataVisualizer {
|
||||
"{} parking spots ",
|
||||
prettyprint_usize(tract.num_parking_spots)
|
||||
));
|
||||
txt.add_line(format!(
|
||||
"{} total owned cars",
|
||||
prettyprint_usize(tract.total_owned_cars)
|
||||
));
|
||||
}
|
||||
self.menu.handle_event(ctx, Some(txt));
|
||||
ctx.canvas.handle_event(ctx.input);
|
||||
@ -189,6 +194,7 @@ fn clip(popdat: &PopDat, ui: &UI, timer: &mut Timer) -> BTreeMap<String, Tract>
|
||||
color: Color::WHITE,
|
||||
num_bldgs,
|
||||
num_parking_spots,
|
||||
total_owned_cars: tract.total_owned_cars(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -146,3 +146,22 @@ fn group_attribs(mut attribs: BTreeMap<String, String>) -> BTreeMap<String, Esti
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
impl TractData {
|
||||
// Nontrivial summary
|
||||
pub fn total_owned_cars(&self) -> usize {
|
||||
let mut sum = 0;
|
||||
for (name, est) in &self.household_vehicles {
|
||||
match name.as_str() {
|
||||
"1 vehicle avail." => sum += 1 * est.value,
|
||||
"2 vehicles avail." => sum += 2 * est.value,
|
||||
"3 vehicles avail." => sum += 3 * est.value,
|
||||
// Many more than 4 seems unrealistic
|
||||
"4 or more vehicles avail." => sum += 4 * est.value,
|
||||
"No vehicle avail." | "Total:" => {}
|
||||
_ => panic!("Unknown household_vehicles key {}", name),
|
||||
}
|
||||
}
|
||||
sum
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user