forked from a-b-street/ltn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdensity_buckets.rs
28 lines (24 loc) · 969 Bytes
/
density_buckets.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use data_prep::PopulationZoneInput;
/// Print the Quintile boundaries for all of Scotland's population zones
fn main() {
let mut population_zones = PopulationZoneInput::read_all_from_file().unwrap();
population_zones.sort_by(|zone_a, zone_b| {
zone_a
.density_per_km2()
.partial_cmp(&zone_b.density_per_km2())
.unwrap()
});
let buckets = 5;
let bucket_width = population_zones.len() / buckets;
let limits: Vec<_> = (0..=buckets)
.map(|bucket| {
let limit_idx = bucket * bucket_width;
population_zones[limit_idx]
.density_per_km2()
.round() as u64
})
.collect();
println!("most_dense: {}", population_zones.iter().rev().next().unwrap().density_per_km2());
// > Raw limits for Scotland density (/ km²): [0, 1324, 2940, 4247, 5858, 52389]
println!("Raw limits for Scotland density (/ km²): {limits:?}");
}