From edd3e11f755b78c597e5e22dc5c6fac59f8fe4e2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Sun, 13 Dec 2020 13:34:19 -0800 Subject: [PATCH] Count the number of people in the isochrone. #393 --- fifteen_min/src/isochrone.rs | 14 +++++++++++++- fifteen_min/src/viewer.rs | 25 +++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/fifteen_min/src/isochrone.rs b/fifteen_min/src/isochrone.rs index 4bf6a051f2..5aef044016 100644 --- a/fifteen_min/src/isochrone.rs +++ b/fifteen_min/src/isochrone.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; use abstutil::MultiMap; use geom::{Duration, Polygon}; use map_gui::tools::{amenity_type, Grid}; -use map_model::{connectivity, BuildingID, Map, Path, PathConstraints, PathRequest}; +use map_model::{connectivity, BuildingID, BuildingType, Map, Path, PathConstraints, PathRequest}; use widgetry::{Color, Drawable, EventCtx, GeomBatch}; use crate::App; @@ -20,6 +20,9 @@ pub struct Isochrone { pub time_to_reach_building: HashMap, /// Per category of amenity (defined by helpers::amenity_type), what buildings have that? pub amenities_reachable: MultiMap<&'static str, BuildingID>, + /// How many people live in the returned area, according to estimates included in the map (from + /// city-specific parcel data, guesses from census, or a guess based on OSM tags) + pub population: usize, } impl Isochrone { @@ -34,6 +37,7 @@ impl Isochrone { let draw = draw_isochrone(app, &time_to_reach_building).upload(ctx); let mut amenities_reachable = MultiMap::new(); + let mut population = 0; for b in time_to_reach_building.keys() { let bldg = app.map.get_b(*b); for amenity in &bldg.amenities { @@ -41,6 +45,13 @@ impl Isochrone { amenities_reachable.insert(category, bldg.id); } } + match bldg.bldg_type { + BuildingType::Residential { num_residents, .. } + | BuildingType::ResidentialCommercial(num_residents, _) => { + population += num_residents; + } + _ => {} + } } Isochrone { @@ -49,6 +60,7 @@ impl Isochrone { draw, time_to_reach_building, amenities_reachable, + population, } } diff --git a/fifteen_min/src/viewer.rs b/fifteen_min/src/viewer.rs index 983b9af225..a3e34bf7d6 100644 --- a/fifteen_min/src/viewer.rs +++ b/fifteen_min/src/viewer.rs @@ -4,13 +4,15 @@ //! //! See https://github.com/dabreegster/abstreet/issues/393 for more context. +use abstutil::prettyprint_usize; use geom::{Distance, Pt2D}; use map_gui::tools::{amenity_type, nice_map_name, CityPicker, PopupMsg}; use map_gui::{Cached, ID}; use map_model::{Building, BuildingID, PathConstraints}; use widgetry::{ lctrl, Btn, Checkbox, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Key, - Line, Outcome, Panel, RewriteColor, State, Text, Transition, VerticalAlignment, Widget, + Line, Outcome, Panel, RewriteColor, State, Text, TextExt, Transition, VerticalAlignment, + Widget, }; use crate::isochrone::Isochrone; @@ -182,11 +184,14 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc Btn::close(ctx), ])); - rows.push(Widget::row(vec![Btn::pop_up( - ctx, - Some(nice_map_name(app.map.get_name())), - ) - .build(ctx, "change map", lctrl(Key::L))])); + rows.push(Widget::row(vec![ + "Map:".draw_text(ctx), + Btn::pop_up(ctx, Some(nice_map_name(app.map.get_name()))).build( + ctx, + "change map", + lctrl(Key::L), + ), + ])); rows.push( Text::from_all(vec![ @@ -196,6 +201,14 @@ fn build_panel(ctx: &mut EventCtx, app: &App, start: &Building, isochrone: &Isoc .draw(ctx), ); + rows.push( + Text::from_all(vec![ + Line("Estimated population: ").secondary(), + Line(prettyprint_usize(isochrone.population)), + ]) + .draw(ctx), + ); + for (amenity, buildings) in isochrone.amenities_reachable.borrow() { rows.push( Btn::text_fg(format!("{}: {}", amenity, buildings.len())).build(ctx, *amenity, None),