Skip to content

Commit

Permalink
Update BC hosp/ICU data
Browse files Browse the repository at this point in the history
- ccodwg/CovidTimelineCanada#82
- Update `agg2pt` function to work with raw data
  • Loading branch information
jeanpaulrsoucy committed Oct 6, 2023
1 parent ee4ec0a commit 334ebda
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
14 changes: 12 additions & 2 deletions R/assemble_final_datasets.R
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,12 @@ assemble_final_datasets <- function() {
)

## bc
hospitalizations_bc <- get_covid19tracker_d("hospitalizations", "BC")
hospitalizations_bc <- dplyr::bind_rows(
get_covid19tracker_d("hospitalizations", "BC") |>
dplyr::filter(.data$date <= as.Date("2021-03-12")),
read_d("raw_data/static/bc/bc_hospitalizations_hr_ts.csv") |>
agg2pt(raw = TRUE)
)

## mb
hospitalizations_mb <- dplyr::bind_rows(
Expand Down Expand Up @@ -513,7 +518,12 @@ assemble_final_datasets <- function() {
)

## bc
icu_bc <- get_covid19tracker_d("icu", "BC")
icu_bc <- dplyr::bind_rows(
get_covid19tracker_d("icu", "BC") |>
dplyr::filter(.data$date <= as.Date("2021-03-12")),
read_d("raw_data/static/bc/bc_icu_hr_ts.csv") |>
agg2pt(raw = TRUE)
)

## mb
icu_mb <- dplyr::bind_rows(
Expand Down
30 changes: 25 additions & 5 deletions R/process_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#' @param val The value to select.
#' @param out_col The name of the value column in the output dataset.
#' @param sr A vector of sub-regions to drop.
#' @param raw Is this function operating on raw data with only one of "value" or
#' "value_daily" columns?
#' @param as_of_date The date to add as the "as-of date".
#' @param geo The geographic level of the data. One of "pt", "hr", "sub-hr".
#' @param d1 Dataset to append to. A cumulative value dataset.
Expand Down Expand Up @@ -318,13 +320,31 @@ add_hr_col <- function(d, name) {
#' @rdname process_funs
#'
#' @export
agg2pt <- function(d) {
agg2pt <- function(d, raw = FALSE) {
tryCatch(
{
d %>%
dplyr::select(-.data$sub_region_1) %>%
dplyr::group_by(.data$name, .data$region, .data$date) %>%
dplyr::summarise(value = sum(.data$value), value_daily = sum(.data$value_daily), .groups = "drop")
if (!raw) {
d %>%
dplyr::select(-.data$sub_region_1) %>%
dplyr::group_by(.data$name, .data$region, .data$date) %>%
dplyr::summarise(value = sum(.data$value), value_daily = sum(.data$value_daily), .groups = "drop")
} else {
if ("value" %in% names(d) & "value_daily" %in% names(d)) {
stop("Argument 'raw' can only be used on raw data with one of 'value' or 'value_daily'.")
} else {
if ("value" %in% names(d)) {
d %>%
dplyr::select(-.data$sub_region_1) %>%
dplyr::group_by(.data$name, .data$region, .data$date) %>%
dplyr::summarise(value = sum(.data$value), .groups = "drop")
} else {
d %>%
dplyr::select(-.data$sub_region_1) %>%
dplyr::group_by(.data$name, .data$region, .data$date) %>%
dplyr::summarise(value_daily = sum(.data$value_daily), .groups = "drop")
}
}
}
},
error = function(e) {
print(e)
Expand Down
5 changes: 4 additions & 1 deletion man/process_funs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 334ebda

Please sign in to comment.