From 295d349d7835fd35b129cf9078aa2ffa3eba8a37 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Sat, 20 Dec 2025 20:03:35 -0500 Subject: [PATCH] update queries to include more getters --- app/queries.R | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/app/queries.R b/app/queries.R index 329ea88..a339afc 100644 --- a/app/queries.R +++ b/app/queries.R @@ -36,6 +36,7 @@ hurdat.hurdat_storms <- tbl(con, I("hurdat.hurdat_storms")) metrics.geo_attributes <- tbl(con, I("metrics.geo_attributes")) metrics.pop_and_housing <- tbl(con, I("metrics.pop_and_housing")) +metrics.usa_pop_hu <- tbl(con, I("metrics.usa_pop_hu")) public.counties <- tbl(con, I("public.counties")) @@ -98,6 +99,33 @@ split_full_lf_id <- function(full_lf_id) { # DB getters +get_yearly_economics <- function(year) { + query <- econ.usa_yearly %>% + filter(year == year) + + result <- query %>% collect() + + return(result) +} + +get_latest_normalization_year <- function() { + query <- view.yearly_normalized_losses %>% + summarize(latest_year = max(normalization_year)) + + result <- query %>% collect() + + return(result) +} + +get_yearly_usa_pop_hu <- function(year) { + query <- metrics.usa_pop_hu %>% + filter(year == year) + + result <- query %>% collect() + + return(result) +} + get_best_track_summary <- function(storm) { query <- view.best_track_summary %>% filter( @@ -512,3 +540,42 @@ get_lf_type_factors <- function(storm) { return(result) } + +get_county_and_state <- function(df) { + unique_state_fips <- unique(df$state_fips) + unique_county_fips <- unique(df$county_fips) + + counties <- public.counties %>% + filter( + statefp %in% !!unique_state_fips, + countyfp %in% !!unique_county_fips + ) %>% + select( + statefp, + countyfp, + name, + namelsad + ) %>% + collect() + + states <- fips.states %>% + filter(state_fips %in% !!unique_state_fips) %>% + select( + state_fips, + state_name, + state_abbreviation + ) %>% + collect() + + result <- df %>% + left_join( + counties, + by = c("state_fips" = "statefp", "county_fips" = "countyfp") + ) %>% + left_join( + states, + by = "state_fips" + ) + + return(result) +}