diff --git a/R/assemble_final_datasets.R b/R/assemble_final_datasets.R index fecfa9d..a69d43c 100644 --- a/R/assemble_final_datasets.R +++ b/R/assemble_final_datasets.R @@ -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( @@ -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( diff --git a/R/process_funs.R b/R/process_funs.R index 14d3012..b5819f6 100644 --- a/R/process_funs.R +++ b/R/process_funs.R @@ -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. @@ -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) diff --git a/man/process_funs.Rd b/man/process_funs.Rd index 522d61a..2a39f5c 100644 --- a/man/process_funs.Rd +++ b/man/process_funs.Rd @@ -38,7 +38,7 @@ collate_datasets(val) add_hr_col(d, name) -agg2pt(d) +agg2pt(d, raw = FALSE) agg2can(d) @@ -67,6 +67,9 @@ dataset_format(d, geo = c("pt", "hr", "sub-hr"), digits) \item{d2}{Dataset being appended. A daily value dataset.} +\item{raw}{Is this function operating on raw data with only one of "value" or +"value_daily" columns?} + \item{digits}{The number of digits to round to for numeric values. If not provided, no rounding will be done for numeric values.} }