Skip to content

Commit ad1c99b

Browse files
committed
covid comparison, include national data
1 parent 0c59000 commit ad1c99b

File tree

5 files changed

+966
-6
lines changed

5 files changed

+966
-6
lines changed

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ prod-covid-log:
1717
prod-covid:
1818
export TAR_RUN_PROJECT=covid_hosp_prod; Rscript scripts/run.R
1919

20+
prod-covid-2:
21+
export TAR_RUN_PROJECT=covid_hosp_prod_2; Rscript scripts/run.R
22+
2023
prod-flu-log:
2124
export TAR_RUN_PROJECT=flu_hosp_prod; Rscript scripts/run.R >> cache/logs/prod_flu 2>&1
2225

2326
prod-flu:
2427
export TAR_RUN_PROJECT=flu_hosp_prod; Rscript scripts/run.R
2528

29+
prod-flu-2:
30+
export TAR_RUN_PROJECT=flu_hosp_prod2; Rscript scripts/run.R
31+
2632
prod: prod-covid prod-flu update-site netlify
2733

2834
prod-log: prod-covid-log prod-flu-log update-site-log netlify-log

R/aux_data_utils.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,46 @@ get_nhsn_data_archive <- function(disease_name) {
682682
}
683683

684684
up_to_date_nssp_state_archive <- function(disease = c("covid", "influenza")) {
685+
disease <- arg_match(disease)
686+
nssp_national <- get_cast_api_data(
687+
source = "nssp",
688+
signal = glue::glue("pct_ed_visits_{disease}"),
689+
geo_type = "nation",
690+
columns = c("geo_value", "time_value", "value", "report_ts_nominal_start", "report_ts_nominal_end"),
691+
limit = -1
692+
)
693+
nssp_state <- get_cast_api_data(
694+
source = "nssp",
695+
signal = glue::glue("pct_ed_visits_{disease}"),
696+
geo_type = "state",
697+
columns = c("geo_value", "time_value", "value", "report_ts_nominal_start", "report_ts_nominal_end"),
698+
limit = -1
699+
)
700+
nssp_data <- nssp_state %>%
701+
rbind(nssp_national) %>%
702+
select(geo_value, time_value, nssp = value, version = report_ts_nominal_start) %>%
703+
mutate(
704+
geo_value = tolower(geo_value),
705+
# Need to center the time_value on Wednesday of the week (rather than Saturday).
706+
time_value = time_value - 3,
707+
version = as.Date(version)
708+
) %>%
709+
# Ensure uniqueness and convert to epi_archive
710+
arrange(geo_value, time_value, version) %>%
711+
distinct(geo_value, time_value, version, .keep_all = TRUE)
712+
713+
# covid wyoming is missing nssp data
714+
if (disease == "covid") {
715+
nssp_data <- nssp_data %>% filter(geo_value != "wy")
716+
}
717+
# Complete the rest of the conversion.
718+
nssp_data %>%
719+
# End of week to midweek correction.
720+
mutate(time_value = floor_date(time_value, "week", week_start = 7) + 3) %>%
721+
as_epi_archive(compactify = TRUE)
722+
}
723+
724+
old_up_to_date_nssp_state_archive <- function(disease = c("covid", "influenza")) {
685725
disease <- arg_match(disease)
686726
nssp_from_legacy_api <- bind_rows(
687727
retry_fn(

_targets.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ covid_hosp_prod:
1818
store: covid_hosp_prod
1919
use_crew: yes
2020
reporter_make: timestamp
21+
covid_hosp_prod_2:
22+
script: scripts/covid_hosp_prod_2.R
23+
store: covid_hosp_prod_2
24+
use_crew: yes
25+
reporter_make: timestamp
2126
flu_hosp_prod2:
2227
script: scripts/flu_hosp_prod2.R
2328
store: flu_hosp_prod2
2429
use_crew: yes
2530
reporter_make: timestamp
26-

0 commit comments

Comments
 (0)