@@ -85,20 +85,30 @@ get_target_response <- function(signals,
8585 " forecast dates: " ,
8686 paste(forecast_dates [problem_dates ], collapse = " , " ),
8787 " ." ))
88- if (sum (problem_dates ) == length(forecast_dates )) return (empty_actual())
88+ if (length (problem_dates ) == length(forecast_dates )) return (empty_actual())
8989 out <- out [! problem_dates ]
9090 forecast_dates <- forecast_dates [! problem_dates ]
9191 target_periods <- target_periods [! problem_dates , ]
9292 }
9393 names(out ) <- forecast_dates
9494 target_periods $ forecast_date = lubridate :: ymd(forecast_dates )
95+
96+ if (grepl(" cumulative" , response $ signal , fixed = TRUE )) {
97+ agg_fn <- function (df ) {
98+ slice(df , which.max(time_value )) %> % select(geo_value , forecast_date , actual = value )
99+ }
100+ } else {
101+ agg_fn <- function (df ) {
102+ summarize(df , actual = sum(.data $ value ))
103+ }
104+ }
95105 out <- out %> %
96106 bind_rows(.id = " forecast_date" ) %> %
97107 mutate(forecast_date = lubridate :: ymd(.data $ forecast_date )) %> %
98108 group_by(.data $ geo_value , .data $ forecast_date ) %> %
99- summarize(actual = sum(.data $ value )) %> %
100- # mutate(forecast_date = forecast_dates[as.numeric(.data$forecast_date)]) %>%
109+ agg_fn() %> %
101110 left_join(target_periods , by = " forecast_date" )
111+
102112 # record date that this function was run for reproducibility
103113 attr(out , " as_of" ) <- Sys.Date()
104114 out
0 commit comments