openjusticeok / ojodb

OJO's R package for opening the black box of our justice system
https://openjusticeok.github.io/ojodb/
GNU General Public License v3.0
8 stars 3 forks source link

Unexpected behavior when collecting #149

Closed brancengregory closed 1 year ago

brancengregory commented 1 year ago

Just ran this script:

library(ojoverse)
library(lubridate)

march_entries <- ojo_tbl("process_log", schema = "eviction_addresses") |>
  filter(
    updated_at >= "2023-03-01",
    updated_at < "2023-04-01"
  ) |>
  mutate(
    date_entered = floor_date(created_at, "day") |>
      as_date(),
  ) |>
  select(
    case,
    date_entered
  )

march_entries |>
  left_join(
    ojo_tbl("case"),
    by = c("case" = "id")
  ) |>
  left_join(
    ojo_tbl("issue"),
    by = c("case" = "case_id")
  ) |>
  select(
    case,
    date_filed,
    date_entered,
    disposition_date,
    disposition
  ) |>
  mutate(
    clean_disposition = case_when(
      str_detect(disposition,  "DISMISS") ~ "DISMISSED",
      str_detect(disposition,  "JUDGMENT|JUDGEMENT") ~
        case_when(
          str_detect(disposition,  "DEFAULT") ~ "DEFAULT JUDGMENT",
          str_detect(disposition,  "PLAINTIFF") ~ "JUDGMENT FOR PLAINTIFF",
          str_detect(disposition,  "DEFENDANT") ~ "JUDGMENT FOR DEFENDANT",
          TRUE ~ "JUDGMENT ENTERED"
        ),
      str_detect(disposition,  "ADVISEMENT") ~ "UNDER ADVISEMENT",
      TRUE ~ NA_character_
    )
  ) |>
  mutate(
    judgment = case_when(
      clean_disposition %in% c("DEFAULT JUDGMENT", "JUDGMENT FOR PLAINTIFF") ~ "Landlord",
      clean_disposition == "JUDGMENT FOR DEFENDANT" ~ "Tenant",
      clean_disposition == "JUDGMENT ENTERED" ~ "Decided, Outcome Unknown",
      clean_disposition == "DISMISSED" ~ "Dismissed (Settled Outside Court)",
      !is.na(clean_disposition) ~ "Other",
      TRUE ~ NA_character_
    )
  ) |>
  count(disposition, clean_disposition, judgment)

Recieved this output:

── Connection: [bgregory@34.122.10.67:5432/ojodb] ─────────────────────────────────────────────── ojodb 2.5.0 ──
Error in `rlang::warn()`:for matching results...
! `.frequency_id` must be supplied with `.frequency`.
Run `rlang::last_error()` to see where the error occurred.
✖ Something went wrong sending your query to the database! Please check your connection. [35ms]
andrewjbe commented 1 year ago

I believe this was resolved by #152 -- the example code runs successfully now.