@@ -172,18 +172,19 @@ data_substitutions <- function(dataset, disease, forecast_generation_date) {
172
172
}
173
173
174
174
parse_prod_weights <- function (filename = here :: here(" covid_geo_exclusions.csv" ),
175
- gen_forecast_date ) {
175
+ forecast_date_int , forecaster_fns ) {
176
+ forecast_date <- as.Date(forecast_date_int )
176
177
all_states <- c(
177
178
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 ),
178
179
" usa" , " us"
179
180
)
180
181
all_prod_weights <- readr :: read_csv(filename , comment = " #" , show_col_types = FALSE )
181
182
# if we haven't set specific weights, use the overall defaults
182
- useful_prod_weights <- filter(all_prod_weights , forecast_date == gen_forecast_date )
183
+ useful_prod_weights <- filter(all_prod_weights , forecast_date == forecast_date )
183
184
if (nrow(useful_prod_weights ) == 0 ) {
184
185
useful_prod_weights <- all_prod_weights %> %
185
186
filter(forecast_date == min(forecast_date )) %> %
186
- mutate(forecast_date = gen_forecast_date )
187
+ mutate(forecast_date = forecast_date )
187
188
}
188
189
useful_prod_weights %> %
189
190
mutate(
@@ -196,7 +197,7 @@ parse_prod_weights <- function(filename = here::here("covid_geo_exclusions.csv")
196
197
unnest_longer(forecaster ) %> %
197
198
group_by(forecast_date , forecaster , geo_value ) %> %
198
199
summarize(weight = min(weight ), .groups = " drop" ) %> %
199
- mutate(forecast_date = as.Date(forecast_date )) %> %
200
+ mutate(forecast_date = as.Date(forecast_date_int )) %> %
200
201
group_by(forecast_date , geo_value ) %> %
201
202
mutate(weight = ifelse(near(weight , 0 ), 0 , weight / sum(weight )))
202
203
}
@@ -280,7 +281,8 @@ write_submission_file <- function(pred, forecast_reference_date, submission_dire
280
281
# ' Utility to get the reference date for a given date. This is the last day of
281
282
# ' the epiweek that the date falls in.
282
283
get_forecast_reference_date <- function (date ) {
283
- MMWRweek :: MMWRweek2Date(epiyear(date ), epiweek(date )) + 6
284
+ date <- as.Date(date )
285
+ MMWRweek :: MMWRweek2Date(lubridate :: epiyear(date ), lubridate :: epiweek(date )) + 6
284
286
}
285
287
286
288
update_site <- function () {
@@ -303,15 +305,31 @@ update_site <- function() {
303
305
stop(" Template file does not exist." )
304
306
}
305
307
report_md_content <- readLines(template_path )
306
-
307
308
# Get the list of files in the reports directory
308
- report_files <- dir_ls(reports_dir , regexp = " .*_prod.html" )
309
+ report_files <- dir_ls(reports_dir , regexp = " .*_prod_on_.*.html" )
310
+ report_table <- tibble(
311
+ filename = report_files ,
312
+ dates = str_match_all(filename , " [0-9]{4}-..-.." )
313
+ ) %> %
314
+ unnest_wider(dates , names_sep = " _" ) %> %
315
+ rename(forecast_date = dates_1 , generation_date = dates_2 ) %> %
316
+ mutate(
317
+ forecast_date = ymd(forecast_date ),
318
+ generation_date = ymd(generation_date ),
319
+ disease = str_match(filename , " flu|covid" )
320
+ )
309
321
310
- # Extract dates and sort files by date in descending order
311
- report_files <- report_files [order(as.Date(str_extract(report_files , " \\ d{4}-\\ d{2}-\\ d{2}" )), decreasing = FALSE )]
322
+ # use the most recently generated forecast, and sort descending on the
323
+ # forecast date
324
+ used_reports <- report_table %> %
325
+ group_by(forecast_date , disease ) %> %
326
+ arrange(generation_date ) %> %
327
+ filter(generation_date == max(generation_date )) %> %
328
+ ungroup() %> %
329
+ arrange(forecast_date )
312
330
313
331
# Process each report file
314
- for (report_file in report_files ) {
332
+ for (report_file in used_reports $ filename ) {
315
333
file_name <- path_file(report_file )
316
334
file_parts <- str_split(fs :: path_ext_remove(file_name ), " _" , simplify = TRUE )
317
335
date <- file_parts [1 ]
0 commit comments