Skip to content

Commit 3f88516

Browse files
committed
fix
1 parent c00036c commit 3f88516

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

scripts/flu_hosp_prod.R

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ end_date <- Sys.Date()
1616
# today, which is a Wednesday. Sometimes, if we're doing a delayed forecast,
1717
# it's a Thursday. It's used for stamping the data and for determining the
1818
# appropriate as_of when creating the forecast.
19-
forecast_generation_date <- Sys.Date()
19+
forecast_generation_dates <- Sys.Date()
2020
# Usually, the forecast_date is the same as the generation date, but you can
2121
# override this. It should be a Wednesday.
22-
forecast_date <- round_date(forecast_generation_date, "weeks", week_start = 3)
22+
forecast_dates <- round_date(forecast_generation_dates, "weeks", week_start = 3)
2323
# If doing backfill, you can set the forecast_date to a sequence of dates.
24-
# forecast_date <- seq.Date(as.Date("2024-11-20"), Sys.Date(), by = 7L)
24+
# forecast_dates <- seq.Date(as.Date("2024-11-20"), Sys.Date(), by = 7L)
2525
# forecast_generation_date needs to follow suit, but it's more complicated
2626
# because sometimes we forecast on Thursday.
27-
# forecast_generation_date <- c(as.Date(c("2024-11-21", "2024-11-27", "2024-12-04", "2024-12-11", "2024-12-18", "2024-12-26", "2025-01-02")), seq.Date(as.Date("2025-01-08"), Sys.Date(), by = 7L))
27+
# forecast_generation_dates <- c(as.Date(c("2024-11-21", "2024-11-27", "2024-12-04", "2024-12-11", "2024-12-18", "2024-12-26", "2025-01-02")), seq.Date(as.Date("2025-01-08"), Sys.Date(), by = 7L))
2828

2929
# Whether we're running in backtest mode.
3030
# If TRUE, we don't run the report notebook, which is (a) slow and (b) should be
@@ -167,15 +167,15 @@ rlang::list2(
167167
tar_map(
168168
# Because targets relies on R metaprogramming, it loses the Date class.
169169
values = tibble(
170-
forecast_date_int = forecast_date,
171-
forecast_generation_date_int = forecast_generation_date,
172-
forecast_date_chr = as.character(forecast_date_int)
170+
forecast_date_int = forecast_dates,
171+
forecast_generation_date_int = forecast_generation_dates,
172+
forecast_date_chr = as.character(forecast_dates)
173173
),
174174
names = "forecast_date_chr",
175175
tar_change(
176176
name = geo_forecasters_weights,
177177
command = {
178-
geo_forecasters_weights <- parse_prod_weights(here::here("flu_geo_exclusions.csv"), forecast_date_int, forecaster_fns)
178+
geo_forecasters_weights <- parse_prod_weights(here::here("flu_geo_exclusions.csv"), forecast_date_int, names(forecaster_fns))
179179
if (nrow(geo_forecasters_weights %>% filter(forecast_date == as.Date(forecast_date_int))) == 0) {
180180
cli_abort("there are no weights for the forecast date {forecast_date}")
181181
}
@@ -342,25 +342,27 @@ rlang::list2(
342342
tar_target(
343343
name = make_submission_csv,
344344
command = {
345-
if (!backtest_mode) {
345+
if (!backtest_mode && submission_directory != "cache") {
346346
combo_ens_climate_linear_window_season %>%
347347
format_flusight(disease = "flu") %>%
348348
write_submission_file(
349349
get_forecast_reference_date(forecast_date_int),
350350
file.path(submission_directory, "model-output/CMU-TimeSeries")
351351
)
352+
} else {
353+
cli_alert_info("Not making submission csv because we're in backtest mode or submission directory is cache")
352354
}
353355
}
354356
),
355357
tar_target(
356358
name = make_climate_submission_csv,
357359
command = {
358-
if (!backtest_mode) {
360+
if (!backtest_mode && submission_directory != "cache") {
359361
forecasts <- forecast_res
360362
forecasts %>%
361363
filter(forecaster %in% c("climate_base", "climate_geo_agged")) %>%
362364
group_by(geo_value, target_end_date, quantile) %>%
363-
summarize(forecast_date = first(forecast_date), value = mean(value, na.rm = TRUE), .groups = "drop") %>%
365+
summarize(forecast_date = as.Date(forecast_date_int), value = mean(value, na.rm = TRUE), .groups = "drop") %>%
364366
ungroup() %>%
365367
filter(!(geo_value %in% excluded_geos)) %>%
366368
format_flusight(disease = "flu") %>%
@@ -370,6 +372,8 @@ rlang::list2(
370372
submission_directory = file.path(submission_directory, "model-output/CMU-climate_baseline"),
371373
file_name = "CMU-climate_baseline"
372374
)
375+
} else {
376+
cli_alert_info("Not making climate submission csv because we're in backtest mode or submission directory is cache")
373377
}
374378
},
375379
priority = 0.99
@@ -468,10 +472,11 @@ rlang::list2(
468472
cue = tar_cue(mode = "always")
469473
)
470474
),
471-
tar_target(
472-
new_data_notebook,
473-
command = {
474-
rmarkdown::render("scripts/reports/new_data.Rmd", output_file = here::here("reports", "new_data.html"))
475-
}
476-
)
475+
# TODO
476+
# tar_target(
477+
# new_data_notebook,
478+
# command = {
479+
# rmarkdown::render("scripts/reports/new_data.Rmd", output_file = here::here("reports", "new_data.html"))
480+
# }
481+
# )
477482
)

0 commit comments

Comments
 (0)