ctsit / rcc.billing

Automated, data-driven service billing implemented on REDCap Custodian
https://ctsit.github.io/rcc.billing/
Apache License 2.0
0 stars 3 forks source link

Create service_request_time() #206

Closed pbchase closed 6 months ago

pbchase commented 7 months ago

Create this function

service_request_time <- function(time_minutes, time_hours) {
  result <- tibble(
    time_minutes = time_minutes,
    time_hours = time_hours
    ) |>
    mutate(time = case_when(
      time_minutes %in% c(15,30,45,60) ~ time_minutes/60,
      time_hours > 1 ~ time_hours,
      TRUE ~ NA_real_
    )) |>
    pull(time)

  return(result)
}

Add documentation. Include an example that looks kind of like the test code below. Make sure it passes the build check.

Make a test for it that looks kind of like this:

tribble(
  ~id, ~time2, ~time_more, ~expected_result
  1, 15, NA_real_, 0.25,
  2, 30, NA_real_, 0.5,
  3, 45, NA_real_, 0.75,
  4, 60, NA_real_, 1.0,
  5, 75, 1.25, 1.25,
  6, 75, 1.5, 1.5,
  7, 75, 1.75, 1.75
) |>
  mutate(time = service_request_time(time2, time_more))

Make sure that passes the build check.

ljwoodley commented 7 months ago
service_request_data |> 
  add_count(time2, time_more) |> 
  distinct(time2, time_more, n) |> 
  mutate(time = service_request_time(time2, time_more))

Check the time for rows 6 & 13. Should these outliers be considered in the function? It's only 3 rows of data so it wouldn't skew any aggregates atm but may become a problem later on if we get more weird data.

Screenshot 2024-04-07 at 9 51 13 AM

pbchase commented 6 months ago

Addressed by #213