Skip to content

Commit

Permalink
Count the number of people in the isochrone. #393
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Dec 13, 2020
1 parent 7ffa7f7 commit edd3e11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
14 changes: 13 additions & 1 deletion fifteen_min/src/isochrone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +20,9 @@ pub struct Isochrone {
pub time_to_reach_building: HashMap<BuildingID, Duration>,
/// 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 {
Expand All @@ -34,13 +37,21 @@ 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 {
if let Some(category) = amenity_type(&amenity.amenity_type) {
amenities_reachable.insert(category, bldg.id);
}
}
match bldg.bldg_type {
BuildingType::Residential { num_residents, .. }
| BuildingType::ResidentialCommercial(num_residents, _) => {
population += num_residents;
}
_ => {}
}
}

Isochrone {
Expand All @@ -49,6 +60,7 @@ impl Isochrone {
draw,
time_to_reach_building,
amenities_reachable,
population,
}
}

Expand Down
25 changes: 19 additions & 6 deletions fifteen_min/src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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![
Expand All @@ -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),
Expand Down

0 comments on commit edd3e11

Please sign in to comment.