Skip to content

Commit e64b984

Browse files
committed
using archive for older generation dates
1 parent a6de31a commit e64b984

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

scripts/flu_hosp_prod.R

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,22 @@ rlang::list2(
9898
},
9999
cue = tar_cue(mode = "always")
100100
),
101+
tar_target(
102+
name = nhsn_archive_data,
103+
command = {
104+
qs::qread(here::here("cache/nhsn_archive.parquet")) %>%
105+
add_season_info() %>%
106+
mutate(
107+
source = "nhsn",
108+
geo_value = ifelse(geo_value == "usa", "us", geo_value),
109+
value = nhsn_flu,
110+
time_value = time_value - 3
111+
) %>%
112+
select(geo_value, time_value, version, value, epiweek, epiyear, season, season_week, source) %>%
113+
drop_na() %>%
114+
as_epi_archive(other_keys = "source", compactify = TRUE)
115+
}
116+
),
101117
tar_map(
102118
values = tidyr::expand_grid(tibble(forecast_generation_date = forecast_generation_date)),
103119
names = "forecast_generation_date",
@@ -121,9 +137,15 @@ rlang::list2(
121137
tar_target(
122138
forecast_res,
123139
command = {
124-
nhsn_latest_data %>%
140+
forecast_date <- as.Date(forecast_generation_date)
141+
if (forecast_date < Sys.Date()) {
142+
train_data <- nhsn_archive_data %>% epix_as_of(forecast_date)
143+
} else {
144+
train_data <- nhsn_latest_data
145+
}
146+
train_data %>%
125147
bind_rows(joined_latest_extra_data) %>%
126-
as_epi_df(other_keys = "source", as_of = round_date(as.Date(forecast_generation_date), "weeks", week_start = 3)) %>%
148+
as_epi_df(other_keys = "source", as_of = round_date(forecast_date, "weeks", week_start = 3)) %>%
127149
forecaster_fns[[forecasters]](ahead = aheads) %>%
128150
mutate(
129151
forecaster = names(forecaster_fns[forecasters]),
@@ -215,7 +237,8 @@ rlang::list2(
215237
if (submission_directory != "cache") {
216238
validation <- validate_submission(
217239
submission_directory,
218-
file_path = sprintf("CMU-climatological-baseline/%s-CMU-climatological-baseline.csv", get_forecast_reference_date(as.Date(forecast_generation_date))))
240+
file_path = sprintf("CMU-climatological-baseline/%s-CMU-climatological-baseline.csv", get_forecast_reference_date(as.Date(forecast_generation_date)))
241+
)
219242
} else {
220243
validation <- "not validating when there is no hub (set submission_directory)"
221244
}

0 commit comments

Comments
 (0)