mirror of
https://github.com/dylanbenzi/hurricane_normalization_app.git
synced 2026-07-30 05:08:57 +00:00
update growth map to use materialized county view
This commit is contained in:
+24
-36
@@ -418,41 +418,9 @@ get_normalized_metric_growth <- function(storm, full_lf_id) {
|
|||||||
) %>%
|
) %>%
|
||||||
select(state_fips, county_fips)
|
select(state_fips, county_fips)
|
||||||
|
|
||||||
baseline_metrics <- get_tbl("pop_and_housing", "metrics") %>%
|
query <- get_tbl("pop_housing_normalized_growth", "metrics") %>%
|
||||||
filter(
|
filter(base_year == storm$storm_year) %>%
|
||||||
year == storm$storm_year
|
|
||||||
) %>%
|
|
||||||
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
||||||
select(
|
|
||||||
state_fips,
|
|
||||||
county_fips,
|
|
||||||
baseline_population = population,
|
|
||||||
baseline_housing = housing_units
|
|
||||||
)
|
|
||||||
|
|
||||||
normalized_metrics <- get_tbl("pop_and_housing", "metrics") %>%
|
|
||||||
filter(
|
|
||||||
year >= storm$storm_year
|
|
||||||
) %>%
|
|
||||||
inner_join(affected_counties, by = c("state_fips", "county_fips")) %>%
|
|
||||||
inner_join(baseline_metrics, by = c("state_fips", "county_fips")) %>%
|
|
||||||
mutate(
|
|
||||||
normalized_population = as.numeric(population) /
|
|
||||||
as.numeric(baseline_population),
|
|
||||||
normalized_housing = as.numeric(housing_units) /
|
|
||||||
as.numeric(baseline_housing)
|
|
||||||
) %>%
|
|
||||||
select(
|
|
||||||
state_fips,
|
|
||||||
county_fips,
|
|
||||||
year,
|
|
||||||
population,
|
|
||||||
housing_units,
|
|
||||||
normalized_population,
|
|
||||||
normalized_housing
|
|
||||||
)
|
|
||||||
|
|
||||||
query <- normalized_metrics %>%
|
|
||||||
inner_join(
|
inner_join(
|
||||||
get_tbl("counties", "public"),
|
get_tbl("counties", "public"),
|
||||||
by = c("state_fips" = "statefp", "county_fips" = "countyfp")
|
by = c("state_fips" = "statefp", "county_fips" = "countyfp")
|
||||||
@@ -469,11 +437,31 @@ get_normalized_metric_growth <- function(storm, full_lf_id) {
|
|||||||
name,
|
name,
|
||||||
population,
|
population,
|
||||||
housing_units,
|
housing_units,
|
||||||
normalized_population,
|
base_year_population,
|
||||||
normalized_housing,
|
base_year_housing,
|
||||||
|
normalized_population = population_normalized,
|
||||||
|
normalized_housing = housing_units_normalized,
|
||||||
geom_wkt
|
geom_wkt
|
||||||
) %>%
|
) %>%
|
||||||
arrange(state_fips, county_fips, year)
|
arrange(state_fips, county_fips, year)
|
||||||
|
|
||||||
|
result <- query %>%
|
||||||
|
collect() %>%
|
||||||
|
mutate(
|
||||||
|
normalized_population = if_else(
|
||||||
|
is.na(base_year_population) | is.na(base_year_housing),
|
||||||
|
NA_real_,
|
||||||
|
normalized_population / 100
|
||||||
|
),
|
||||||
|
normalized_housing = if_else(
|
||||||
|
is.na(base_year_population) | is.na(base_year_housing),
|
||||||
|
NA_real_,
|
||||||
|
normalized_housing / 100
|
||||||
|
)
|
||||||
|
) %>%
|
||||||
|
select(-base_year_population, -base_year_housing)
|
||||||
|
|
||||||
|
return(result)
|
||||||
} else {
|
} else {
|
||||||
affected_state <- get_tbl("indirect_landfalls", "gis") %>%
|
affected_state <- get_tbl("indirect_landfalls", "gis") %>%
|
||||||
filter(
|
filter(
|
||||||
|
|||||||
Reference in New Issue
Block a user