@@ -172,18 +172,19 @@ data_substitutions <- function(dataset, disease, forecast_generation_date) {
172172}
173173
174174parse_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 )
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"
179180 )
180181 all_prod_weights <- readr :: read_csv(filename , comment = " #" , show_col_types = FALSE )
181182 # 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 )
183184 if (nrow(useful_prod_weights ) == 0 ) {
184185 useful_prod_weights <- all_prod_weights %> %
185186 filter(forecast_date == min(forecast_date )) %> %
186- mutate(forecast_date = gen_forecast_date )
187+ mutate(forecast_date = forecast_date )
187188 }
188189 useful_prod_weights %> %
189190 mutate(
@@ -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}
@@ -280,7 +281,8 @@ write_submission_file <- function(pred, forecast_reference_date, submission_dire
280281# ' Utility to get the reference date for a given date. This is the last day of
281282# ' the epiweek that the date falls in.
282283get_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
284286}
285287
286288update_site <- function () {
@@ -303,15 +305,31 @@ update_site <- function() {
303305 stop(" Template file does not exist." )
304306 }
305307 report_md_content <- readLines(template_path )
306-
307308 # 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+ )
309321
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 )
312330
313331 # Process each report file
314- for (report_file in report_files ) {
332+ for (report_file in used_reports $ filename ) {
315333 file_name <- path_file(report_file )
316334 file_parts <- str_split(fs :: path_ext_remove(file_name ), " _" , simplify = TRUE )
317335 date <- file_parts [1 ]
0 commit comments