Skip to content

Commit 3280c3c

Browse files
committed
actually functional download
1 parent 4ee4db0 commit 3280c3c

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dashboard:
8686
Rscript scripts/dashboard.R
8787

8888
update_site:
89-
Rscript -e "suppressPackageStartupMessages(source(here::here('R', 'load_all.R'))); update_site()"
89+
Rscript -e "suppressPackageStartupMessages(source(here::here('R', 'load_all.R'))); update_site()" > cache/update_site_log.txt
9090

9191
netlify:
9292
netlify deploy --dir=reports --prod

scripts/covid_hosp_prod.R

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,23 @@ rlang::list2(
8383
previous_result <- qs::qread(here::here(".nhsn_covid_cache.parquet"))
8484
} else
8585
# if something is different, update the file
86-
if (any(previous_result != most_recent_result)) {
86+
if (!isTRUE(all.equal(previous_result, most_recent_result))) {
8787
qs::qsave(most_recent_result, here::here(".nhsn_covid_cache.parquet"))
8888
} else {
8989
qs::qsave(most_recent_result, here::here(".nhsn_covid_cache.parquet"))
9090
}
9191
NULL
9292
},
9393
description = "Download the result, and update the file only if it's actually different",
94-
priority = 1
94+
priority = 1,
95+
cue = tar_cue(mode = "always")
9596
),
96-
tar_target(
97-
nhsn_latest_data,
97+
tar_change(
98+
name = nhsn_latest_data,
9899
command = {
99-
if (wday(Sys.Date()) < 6 & wday(Sys.Date()) > 3) {
100-
# download from the preliminary data source from Wednesday to Friday
101-
most_recent_result <- readr::read_csv("https://data.cdc.gov/resource/mpgq-jmmr.csv?$limit=20000&$select=weekendingdate,jurisdiction,totalconfc19newadm,totalconfflunewadm")
102-
} else {
103-
most_recent_result <- readr::read_csv("https://data.cdc.gov/resource/ua7e-t2fy.csv?$limit=20000&$select=weekendingdate,jurisdiction,totalconfc19newadm,totalconfflunewadm")
104-
}
105-
most_recent_result %>%
106-
process_nhsn_data() %>%
107-
filter(disease == "nhsn_covid") %>%
108-
select(-disease) %>%
109-
filter(geo_value %nin% insufficient_data_geos)
100+
qs::qread(here::here(".nhsn_flu_cache.parquet"))
110101
},
102+
change = tools::md5sum(here::here(".nhsn_flu_cache.parquet"))
111103
),
112104
tar_target(
113105
name = nhsn_archive_data,
@@ -342,6 +334,7 @@ rlang::list2(
342334
)
343335
)
344336
},
337+
cue = tar_cue(mode = "always")
345338
)
346339
),
347340
)

scripts/flu_hosp_prod.R

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ rlang::list2(
151151
if (file.exists(here::here(".nhsn_flu_cache.parquet"))) {
152152
previous_result <- qs::qread(here::here(".nhsn_flu_cache.parquet"))
153153
# if something is different, update the file
154-
if (isFALSE(all.equal(previous_result, most_recent_result))) {
154+
# !isTRUE(all.equal) is true iff there's at least one difference
155+
# can't use isFALSE(all.equal) because a bunch of strings are not, in fact, false
156+
if (!isTRUE(all.equal(previous_result, most_recent_result))) {
155157
qs::qsave(most_recent_result, here::here(".nhsn_flu_cache.parquet"))
156158
}
157159
} else {
@@ -161,18 +163,14 @@ rlang::list2(
161163
},
162164
description = "Download the result, and update the file only if it's actually different",
163165
priority = 1,
166+
cue = tar_cue(mode="always")
164167
),
165-
tar_target(
166-
nhsn_latest_data,
168+
tar_change(
169+
name = nhsn_latest_data,
167170
command = {
168171
qs::qread(here::here(".nhsn_flu_cache.parquet"))
169-
}
170-
),
171-
tar_target(
172-
name = nhsn_archive_data,
173-
command = {
174-
create_nhsn_data_archive(disease = "nhsn_flu")
175-
}
172+
},
173+
change = tools::md5sum(here::here(".nhsn_flu_cache.parquet"))
176174
),
177175
tar_map(
178176
# Because targets relies on R metaprogramming, it loses the Date class.
@@ -269,7 +267,7 @@ rlang::list2(
269267
cue = tar_cue(mode = "always")
270268
),
271269
tar_target(
272-
name = ensemble_res,
270+
name = climate_linear,
273271
command = {
274272
forecast_res %>%
275273
# Apply the ahead-by-quantile weighting scheme
@@ -284,7 +282,7 @@ rlang::list2(
284282
}
285283
),
286284
tar_target(
287-
name = ensemble_mixture_res,
285+
name = ens_climate_linear_window_season,
288286
command = {
289287
forecast_res %>%
290288
# Apply the ahead-by-quantile weighting scheme
@@ -299,7 +297,7 @@ rlang::list2(
299297
},
300298
),
301299
tar_target(
302-
name = ensemble_mixture_res_2,
300+
name = ens_climate_linear_window_season_ave_data,
303301
command = {
304302
forecast_res_modified %>%
305303
# Apply the ahead-by-quantile weighting scheme
@@ -314,10 +312,10 @@ rlang::list2(
314312
}
315313
),
316314
tar_target(
317-
name = combo_ensemble_mixture_res,
315+
name = combo_ens_climate_linear_window_season,
318316
command = {
319317
inner_join(
320-
ensemble_mixture_res, ensemble_mixture_res_2,
318+
ens_climate_linear_window_season, ens_climate_linear_window_season_ave_data,
321319
by = join_by(geo_value, forecast_date, target_end_date, quantile)
322320
) %>%
323321
rowwise() %>%
@@ -333,17 +331,17 @@ rlang::list2(
333331
command = {
334332
bind_rows(
335333
forecast_res,
336-
ensemble_res %>% mutate(forecaster = "ensemble"),
337-
ensemble_mixture_res %>% mutate(forecaster = "ensemble_mix"),
338-
ensemble_mixture_res_2 %>% mutate(forecaster = "ensemble_mix_2"),
339-
combo_ensemble_mixture_res %>% mutate(forecaster = "combo_ensemble_mix")
334+
climate_linear %>% mutate(forecaster = "ensemble"),
335+
ens_climate_linear_window_season %>% mutate(forecaster = "ensemble_linclim_windowed_seasonal"),
336+
ens_climate_linear_window_season_ave_data %>% mutate(forecaster = "ensemble_ave_data"),
337+
combo_ens_climate_linear_window_season %>% mutate(forecaster = "ensemble_overall")
340338
)
341339
}
342340
),
343341
tar_target(
344342
name = make_submission_csv,
345343
command = {
346-
ensemble_res %>%
344+
combo_ens_climate_linear_window_season %>%
347345
format_flusight(disease = "flu") %>%
348346
write_submission_file(
349347
get_forecast_reference_date(forecast_date_int),
@@ -463,6 +461,7 @@ rlang::list2(
463461
)
464462
)
465463
},
464+
cue = tar_cue(mode = "always")
466465
)
467466
),
468467
tar_target(

0 commit comments

Comments
 (0)