@@ -125,7 +125,7 @@ rlang::list2(
125125 }
126126 ),
127127 tar_target(
128- download_latest_nhsn ,
128+ nhsn_latest_data ,
129129 command = {
130130 if (wday(Sys.Date()) < 6 & wday(Sys.Date()) > 3 ) {
131131 # download from the preliminary data source from Wednesday to Friday
@@ -148,30 +148,11 @@ rlang::list2(
148148 select(- version ) %> %
149149 data_substitutions(disease = " flu" ) %> %
150150 as_epi_df(other_keys = " source" , as_of = Sys.Date())
151- # if there's not already a result we need to save it no matter what
152- if (file.exists(here :: here(" .nhsn_flu_cache.parquet" ))) {
153- previous_result <- qs :: qread(here :: here(" .nhsn_flu_cache.parquet" ))
154- # if something is different, update the file
155- # !isTRUE(all.equal) is true iff there's at least one difference
156- # can't use isFALSE(all.equal) because a bunch of strings are not, in fact, false
157- if (! isTRUE(all.equal(previous_result , most_recent_result ))) {
158- qs :: qsave(most_recent_result , here :: here(" .nhsn_flu_cache.parquet" ))
159- }
160- } else {
161- qs :: qsave(most_recent_result , here :: here(" .nhsn_flu_cache.parquet" ))
162- }
163- NULL
151+ most_recent_result
164152 },
165153 description = " Download the result, and update the file only if it's actually different" ,
166154 priority = 1 ,
167- cue = tar_cue(mode = " always" )
168- ),
169- tar_change(
170- name = nhsn_latest_data ,
171- command = {
172- qs :: qread(here :: here(" .nhsn_flu_cache.parquet" ))
173- },
174- change = tools :: md5sum(here :: here(" .nhsn_flu_cache.parquet" ))
155+ cue = tar_cue(mode = " always" )
175156 ),
176157 tar_map(
177158 # Because targets relies on R metaprogramming, it loses the Date class.
@@ -275,38 +256,47 @@ rlang::list2(
275256 ensemble_linear_climate(aheads , other_weights = geo_forecasters_weights ) %> %
276257 filter(geo_value %nin % geo_exclusions ) %> %
277258 ungroup() %> %
278- # Ensemble with windowed_seasonal
279- bind_rows(forecast_res %> % filter(forecaster == " windowed_seasonal" )) %> %
259+ sort_by_quantile()
260+ }
261+ ),
262+ tar_target(
263+ name = ens_climate_linear_window_season ,
264+ command = {
265+ climate_linear %> %
266+ # Ensemble with windowed_seasonal and windowed_seasonal_extra_sources
267+ bind_rows(forecast_res %> % filter(forecaster %in% c(" windowed_seasonal" , " windowed_seasonal_extra_sources" ))) %> %
280268 group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
281269 summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
282270 sort_by_quantile()
283271 }
284272 ),
285273 tar_target(
286- name = ens_climate_linear_window_season ,
274+ name = ens_ar_only ,
287275 command = {
288276 forecast_res %> %
289- # Apply the ahead-by-quantile weighting scheme
290- ensemble_linear_climate(aheads , other_weights = geo_forecasters_weights ) %> %
291- filter(geo_value %nin % geo_exclusions ) %> %
292- ungroup() %> %
293- # Ensemble with windowed_seasonal
294- bind_rows(forecast_res %> % filter(forecaster == " windowed_seasonal" , forecaster == " windowed_seasonal_extra_sources" )) %> %
277+ filter(forecaster %in% c(" windowed_seasonal" , " windowed_seasonal_extra_sources" )) %> %
295278 group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
296279 summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
297280 sort_by_quantile()
298281 }
299282 ),
300283 tar_target(
301- name = ens_climate_linear_window_season_ave_data ,
284+ name = climate_linear_modified ,
302285 command = {
303286 forecast_res_modified %> %
304287 # Apply the ahead-by-quantile weighting scheme
305288 ensemble_linear_climate(aheads , other_weights = geo_forecasters_weights ) %> %
306289 filter(geo_value %nin % geo_exclusions ) %> %
307290 ungroup() %> %
291+ sort_by_quantile()
292+ }
293+ ),
294+ tar_target(
295+ name = ens_climate_linear_window_season_modified ,
296+ command = {
297+ climate_linear_modified %> %
308298 # Ensemble with windowed_seasonal
309- bind_rows(forecast_res_modified %> % filter(forecaster == " windowed_seasonal" )) %> %
299+ bind_rows(forecast_res_modified %> % filter(forecaster %in% c( " windowed_seasonal" , " windowed_seasonal_extra_sources " ) )) %> %
310300 group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
311301 summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
312302 sort_by_quantile()
@@ -316,7 +306,7 @@ rlang::list2(
316306 name = combo_ens_climate_linear_window_season ,
317307 command = {
318308 inner_join(
319- ens_climate_linear_window_season , ens_climate_linear_window_season_ave_data ,
309+ ens_climate_linear_window_season , ens_climate_linear_window_season_modified ,
320310 by = join_by(geo_value , forecast_date , target_end_date , quantile )
321311 ) %> %
322312 rowwise() %> %
@@ -332,10 +322,10 @@ rlang::list2(
332322 command = {
333323 bind_rows(
334324 forecast_res ,
335- climate_linear %> % mutate(forecaster = " ensemble" ),
325+ climate_linear %> % mutate(forecaster = " climate_linear" ),
326+ ens_ar_only %> % mutate(forecaster = " ens_ar_only" ),
336327 ens_climate_linear_window_season %> % mutate(forecaster = " ensemble_linclim_windowed_seasonal" ),
337- ens_climate_linear_window_season_ave_data %> % mutate(forecaster = " ensemble_ave_data" ),
338- combo_ens_climate_linear_window_season %> % mutate(forecaster = " ensemble_overall" )
328+ combo_ens_climate_linear_window_season %> % mutate(forecaster = " ensemble_combo" )
339329 )
340330 }
341331 ),
0 commit comments