Skip to content

Commit

Permalink
Handle quarterly counts in the app
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmlft committed Nov 20, 2024
1 parent 3fc2228 commit 8ec2195
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
9 changes: 4 additions & 5 deletions app/R/fct_monthly_count_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ monthly_count_plot <- function(monthly_counts) {
stopifnot(is.data.frame(monthly_counts))
stopifnot(all(c("date_year", "date_month", "person_count") %in% colnames(monthly_counts)))

monthly_counts$date <- .convert_to_date(monthly_counts$date_year, monthly_counts$date_month)
monthly_counts$date <- lubridate::make_date(
year = monthly_counts$date_year,
month = monthly_counts$date_month
)

ggplot(monthly_counts, aes(x = .data$date, y = .data$record_count)) +
geom_bar(aes(fill = .data$concept_name), stat = "identity") +
Expand All @@ -26,7 +29,3 @@ monthly_count_plot <- function(monthly_counts) {
scale_x_date(date_labels = "%b %Y", date_breaks = "3 months") +
theme(legend.position = "none", axis.text.x = element_text(angle = 45, hjust = 1))
}

.convert_to_date <- function(date_year, date_month) {
as.Date(paste0(date_year, "-", date_month, "-01"))
}
10 changes: 10 additions & 0 deletions app/R/utils_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,19 @@ get_monthly_counts <- function() {
} else {
data <- .read_parquet_table("omopcat_monthly_counts")
}

if ("date_quarter" %in% colnames(data)) {
## Set `date_month` to the first month of the quarter
data$date_month <- .quarter_to_month(data$date_quarter)
}

return(data)
}

.quarter_to_month <- function(quarter) {
return((quarter - 1) * 3 + 1)
}

get_summary_stats <- function() {
if (should_use_dev_data()) {
out <- readr::read_csv(
Expand Down

0 comments on commit 8ec2195

Please sign in to comment.