Skip to content

Commit d455571

Browse files
committed
flu fully funcitonal
1 parent 20ebbf5 commit d455571

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

R/utils.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ data_substitutions <- function(dataset, disease, forecast_generation_date) {
172172
}
173173

174174
parse_prod_weights <- function(filename = here::here("covid_geo_exclusions.csv"),
175-
forecast_date) {
175+
forecast_date_int, forecaster_fns) {
176+
forecast_date <- as.Date(forecast_date_int)
176177
all_states <- c(
177178
unique(readr::read_csv("https://raw.githubusercontent.com/cmu-delphi/covidcast-indicators/refs/heads/main/_delphi_utils_python/delphi_utils/data/2020/state_pop.csv", show_col_types = FALSE)$state_id),
178179
"usa", "us"
@@ -196,7 +197,7 @@ parse_prod_weights <- function(filename = here::here("covid_geo_exclusions.csv")
196197
unnest_longer(forecaster) %>%
197198
group_by(forecast_date, forecaster, geo_value) %>%
198199
summarize(weight = min(weight), .groups = "drop") %>%
199-
mutate(forecast_date = as.Date(forecast_date)) %>%
200+
mutate(forecast_date = as.Date(forecast_date_int)) %>%
200201
group_by(forecast_date, geo_value) %>%
201202
mutate(weight = ifelse(near(weight, 0), 0, weight / sum(weight)))
202203
}

scripts/covid_hosp_prod.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ rlang::list2(
7878
tar_target(
7979
name = geo_forecasters_weights,
8080
command = {
81-
geo_forecasters_weights <- parse_prod_weights(here::here("covid_geo_exclusions.csv"), forecast_date_int)
82-
if (nrow(geo_forecasters_weights %>% filter(forecast_date == forecast_date_int)) == 0) {
81+
geo_forecasters_weights <- parse_prod_weights(here::here("covid_geo_exclusions.csv"), forecast_date_int, forecaster_fns)
82+
if (nrow(geo_forecasters_weights %>% filter(forecast_date == as.Date(forecast_date_int))) == 0) {
8383
cli_abort("there are no weights for the forecast date {forecast_date}")
8484
}
8585
geo_forecasters_weights

scripts/flu_hosp_prod.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ rlang::list2(
110110
) %>%
111111
filter(version == max(version)) %>%
112112
select(-version) %>%
113-
data_substitutions(disease = "flu")
113+
data_substitutions(disease = "flu") %>%
114+
as_epi_df(other_keys = "source", as_of = Sys.Date())
114115
}
115116
),
116117
tar_target(
@@ -129,8 +130,8 @@ rlang::list2(
129130
tar_target(
130131
name = geo_forecasters_weights,
131132
command = {
132-
geo_forecasters_weights <- parse_prod_weights(here::here("flu_geo_exclusions.csv"), forecast_date_int)
133-
if (nrow(geo_forecasters_weights %>% filter(forecast_date == forecast_date_int)) == 0) {
133+
geo_forecasters_weights <- parse_prod_weights(here::here("flu_geo_exclusions.csv"), forecast_date_int, forecaster_fns)
134+
if (nrow(geo_forecasters_weights %>% filter(forecast_date == as.Date(forecast_date_int))) == 0) {
134135
cli_abort("there are no weights for the forecast date {forecast_date}")
135136
}
136137
geo_forecasters_weights

0 commit comments

Comments
 (0)