update queries to include more getters

This commit is contained in:
2025-12-20 20:03:35 -05:00
parent b8f07643c8
commit 295d349d78
+67
View File
@@ -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)
}