R/medidor.R

#' Leitor medidor
#' 
#' @export
leitura_medidor <- function(arq = NULL) {
  if (is.null(arq)) {
    arq <- system.file('extdata/Medidor1.xlsx', package = 'medidor')
  }
  d <- readxl::read_excel(arq)
  d <- d[ , 1:6]
  names(d) <- c('tribunal', 'area', 'numero_controle', 
                'numero_cnj', 'caso', 'resumo')
  d <- dplyr::filter(d, !is.na(tribunal))
  d$numero_cnj <- gsub('[^0-9]', '', d$numero_cnj)
  d
}

#' @export
verifica_andamento <- function(d, row) {
  if (row > 1) {
    x <- d %>% dplyr::slice(c(row, row - 1))
    tempo <- as.numeric(diff(x$data))
  } else {
    x <- d %>% dplyr::slice(c(row))
    tempo <- as.numeric(diff(c(x$data, lubridate::today())))
  }
  if (tempo <= 7) {
    c(tempo, 'verde')
  } else if (tempo <= 30) {
    c(tempo, 'amarelo')
  } else {
    c(tempo, 'vermelho')
  }
  # padroes <- dplyr::data_frame(
  #   nome = c('Conclusos', 'Carga'),
  #   regex = c('concluso', 'carga')
  # )
  # anda <- x %>% 
  #   with(andamento) %>% 
  #   stringr::str_to_lower() %>% 
  #   stringr::str_trim() %>% 
  #   stj::desacentuar()
  # results <- sapply(padroes$regex, function(x) stringr::str_detect(anda, x))
  # results
}
jtrecenti/medidor documentation built on May 20, 2019, 3:17 a.m.