modify all R code with air and quarto formatting

This commit is contained in:
2025-07-21 16:56:03 -04:00
parent f5dd9e88d2
commit c5a0b2e373
3 changed files with 778 additions and 406 deletions
+3 -1
View File
@@ -1,6 +1,8 @@
library(profvis)
setwd("/home/dylan/Personal/Projects/Hurricane Normalization/R/dataScripts/restructured/app")
setwd(
"/home/dylan/Personal/Projects/Hurricane Normalization/R/dataScripts/restructured/app"
)
profvis({
rmarkdown::render("dashboard.Rmd")
+523 -179
View File
File diff suppressed because it is too large Load Diff
+38 -12
View File
@@ -9,7 +9,9 @@ macdir <- "~/Desktop/Personal/Projects/Hurricane Normalization/"
#baseDir <- macdir
baseDir <- linuxdir
config <- config::get(file = paste0(baseDir, "R/dataScripts/restructured/app/config.yml"))
config <- config::get(
file = paste0(baseDir, "R/dataScripts/restructured/app/config.yml")
)
# SUPABASE CON
con <- dbConnect(
@@ -132,7 +134,12 @@ get_unique_lf_ids <- function(storm) {
full_lf_id
) %>%
select(
storm_basin, storm_year, storm_name, lf_type, lf_id, full_lf_id
storm_basin,
storm_year,
storm_name,
lf_type,
lf_id,
full_lf_id
)
result <- query %>% collect()
@@ -153,7 +160,9 @@ get_normalized_cost_index <- function(storm, full_lf_id) {
lf_id == lf_id_parts$lf_id
) %>%
select(
normalization_year, mmh, mmp
normalization_year,
mmh,
mmp
)
result <- query %>% collect()
@@ -162,7 +171,9 @@ get_normalized_cost_index <- function(storm, full_lf_id) {
}
test_query <- function() {
result <- dbGetQuery(con, "WITH yearly_totals AS (
result <- dbGetQuery(
con,
"WITH yearly_totals AS (
SELECT
year,
SUM(population) as total_population,
@@ -188,14 +199,17 @@ SELECT
ROUND(total_housing_units / base_housing, 4) as housing_index
FROM yearly_totals
CROSS JOIN base_year
ORDER BY year;")
ORDER BY year;"
)
result <- result %>%
mutate(
year = as.Date(paste0(year, "-01-01"))
) %>%
select(
year, population_index, housing_index
year,
population_index,
housing_index
)
result_ts <- result %>%
@@ -217,7 +231,12 @@ get_all_normalized_cost_index <- function(storm) {
full_lf_id = paste0(lf_type, lf_id)
) %>%
select(
normalization_year, mmh_index, mmp_index, mmh_loss = mmh, mmp_loss = mmp, full_lf_id
normalization_year,
mmh_index,
mmp_index,
mmh_loss = mmh,
mmp_loss = mmp,
full_lf_id
)
result <- query %>% collect()
@@ -345,7 +364,7 @@ get_normalized_metric_growth <- function(storm, full_lf_id) {
county_fips,
baseline_population = population,
baseline_housing = housing_units
)
)
normalized_metrics <- metrics.pop_and_housing %>%
filter(
@@ -354,8 +373,10 @@ get_normalized_metric_growth <- function(storm, full_lf_id) {
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)
normalized_population = as.numeric(population) /
as.numeric(baseline_population),
normalized_housing = as.numeric(housing_units) /
as.numeric(baseline_housing)
) %>%
select(
state_fips,
@@ -368,9 +389,14 @@ get_normalized_metric_growth <- function(storm, full_lf_id) {
)
query <- normalized_metrics %>%
inner_join(public.counties, by = c("state_fips" = "statefp", "county_fips" = "countyfp")) %>%
inner_join(
public.counties,
by = c("state_fips" = "statefp", "county_fips" = "countyfp")
) %>%
mutate(
geom_wkt = sql("ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(geom, 4326), .001))")
geom_wkt = sql(
"ST_AsText(ST_SimplifyPreserveTopology(ST_Transform(geom, 4326), .001))"
)
) %>%
select(
state_fips,