Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
brancengregory committed Jul 1, 2024
1 parent a129676 commit 214510b
Show file tree
Hide file tree
Showing 5 changed files with 1,107 additions and 1,459 deletions.
27 changes: 16 additions & 11 deletions R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,22 @@ plot_cases <- function(db, ..., .silent = FALSE) {
#' plot_logins(db, c("test", "test2"), lubridate::ymd("2022-12-12"), lubridate::today())
#' }
#'
plot_logins <- function(db, users, start = lubridate::ymd("2022-12-12"), end = lubridate::today(), .silent = FALSE) {
plot_logins <- function(db, users = "all", start = lubridate::ymd("2022-12-12"), end = lubridate::today(), .silent = FALSE) {
# Query the sessions table by users and date
query <- glue::glue_sql(
'SELECT "user", DATE("login_time") AS "date", COUNT(*) AS "count"',
'FROM "eviction_addresses"."session"',
'WHERE "user" IN ({users*})',
'AND "login_time" BETWEEN {start} AND {end}',
'GROUP BY "user", DATE("login_time")',
.sep = " ",
.con = db
)
user_filter <- if (users == "all") {
""
} else {
glue::glue_sql("WHERE \"user\" IN ({users*}) AND \"login_time\" BETWEEN {start} AND {end}", users = users, start = start, end = end, .con = db)
}

query <- glue::glue_sql(
'SELECT "user", DATE("login_time") AS "date", COUNT(*) AS "count"',
'FROM "eviction_addresses"."session"',
user_filter,
'GROUP BY "user", DATE("login_time")',
.sep = " ",
.con = db
)

# Store the result in a tibble
# Convert the count column to numeric from integer64
Expand Down Expand Up @@ -340,6 +345,7 @@ calculate_pay <- function(
priority_rate = 0.35,
backlog_rate = 0.25
) {

# Query process table for number of addresses entered per person and entry type
query <- glue::glue_sql(
'SELECT "user", DATE(pl.created_at) as created_at, c.date_filed ',
Expand Down Expand Up @@ -382,7 +388,6 @@ calculate_pay <- function(
dplyr::count() |>
dplyr::ungroup() |>
dplyr::left_join(rates, by = "type") |>
dplyr::select(-.data$user) |>
dplyr::mutate(
pay = .data$n * .data$rate,
type = stringr::str_to_title(.data$type),
Expand Down
Binary file modified avg_days_to_ready.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 19 additions & 4 deletions inst/scripts/reporting.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ plot_avg_days_to_ready <- function(data, result) {

# Main script

start_date <- as_date("2023-01-01")
end_date <- rollback(as_date("2023-12-01"))
start_date <- as_date("2022-10-01")
end_date <- rollback(as_date("2024-01-01"))

data <- load_preprocess_data(
start_date = start_date,
Expand All @@ -194,7 +194,7 @@ plot1 <- plot_letters_each_day(result)
plot2 <- plot_avg_days_to_ready(data, result)

plot1
plot2 + expand_limits(y = 0)
plot2

plot2 |>
ggsave(
Expand Down Expand Up @@ -264,5 +264,20 @@ data_to_plot |>
days_to_ready = as.numeric(days_to_ready)
) |>
pull(days_to_ready) |>
skimr::skim()
skimr::skim() |>
select(
starts_with("numeric.p")
) |>
gt::gt() |>
gt::cols_label(
numeric.p0 = "Min",
numeric.p25 = "25%",
numeric.p50 = "Median",
numeric.p75 = "75%",
numeric.p100 = "Max"
) |>
gt::tab_header(
title = "Summary Statistics for Days to Ready",
subtitle = "The percentage of cases that are ready within a certain number of days after being filed, e.g. 75% of cases are ready within 8 days."
)

Loading

0 comments on commit 214510b

Please sign in to comment.