@@ -125,7 +125,7 @@ rlang::list2(
125
125
}
126
126
),
127
127
tar_target(
128
- download_latest_nhsn ,
128
+ nhsn_latest_data ,
129
129
command = {
130
130
if (wday(Sys.Date()) < 6 & wday(Sys.Date()) > 3 ) {
131
131
# download from the preliminary data source from Wednesday to Friday
@@ -148,30 +148,11 @@ rlang::list2(
148
148
select(- version ) %> %
149
149
data_substitutions(disease = " flu" ) %> %
150
150
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
164
152
},
165
153
description = " Download the result, and update the file only if it's actually different" ,
166
154
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" )
175
156
),
176
157
tar_map(
177
158
# Because targets relies on R metaprogramming, it loses the Date class.
@@ -275,38 +256,47 @@ rlang::list2(
275
256
ensemble_linear_climate(aheads , other_weights = geo_forecasters_weights ) %> %
276
257
filter(geo_value %nin % geo_exclusions ) %> %
277
258
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" ))) %> %
280
268
group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
281
269
summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
282
270
sort_by_quantile()
283
271
}
284
272
),
285
273
tar_target(
286
- name = ens_climate_linear_window_season ,
274
+ name = ens_ar_only ,
287
275
command = {
288
276
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" )) %> %
295
278
group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
296
279
summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
297
280
sort_by_quantile()
298
281
}
299
282
),
300
283
tar_target(
301
- name = ens_climate_linear_window_season_ave_data ,
284
+ name = climate_linear_modified ,
302
285
command = {
303
286
forecast_res_modified %> %
304
287
# Apply the ahead-by-quantile weighting scheme
305
288
ensemble_linear_climate(aheads , other_weights = geo_forecasters_weights ) %> %
306
289
filter(geo_value %nin % geo_exclusions ) %> %
307
290
ungroup() %> %
291
+ sort_by_quantile()
292
+ }
293
+ ),
294
+ tar_target(
295
+ name = ens_climate_linear_window_season_modified ,
296
+ command = {
297
+ climate_linear_modified %> %
308
298
# 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 " ) )) %> %
310
300
group_by(geo_value , forecast_date , target_end_date , quantile ) %> %
311
301
summarize(value = mean(value , na.rm = TRUE ), .groups = " drop" ) %> %
312
302
sort_by_quantile()
@@ -316,7 +306,7 @@ rlang::list2(
316
306
name = combo_ens_climate_linear_window_season ,
317
307
command = {
318
308
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 ,
320
310
by = join_by(geo_value , forecast_date , target_end_date , quantile )
321
311
) %> %
322
312
rowwise() %> %
@@ -332,10 +322,10 @@ rlang::list2(
332
322
command = {
333
323
bind_rows(
334
324
forecast_res ,
335
- climate_linear %> % mutate(forecaster = " ensemble" ),
325
+ climate_linear %> % mutate(forecaster = " climate_linear" ),
326
+ ens_ar_only %> % mutate(forecaster = " ens_ar_only" ),
336
327
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" )
339
329
)
340
330
}
341
331
),
0 commit comments