Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch_relatorias() para câmara #110

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/colunas_constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,17 @@
)

# Relatorias
.COLNAMES_RELATORIAS <- c("codigo_tipo_relator"="character", "descricao_tipo_relator"="character", "data_designacao"="character",
.COLNAMES_RELATORIAS_SENADO <- c("codigo_tipo_relator"="character", "descricao_tipo_relator"="character", "data_designacao"="character",
"data_destituicao"="character", "descricao_motivo_destituicao"="character", "codigo_parlamentar"="character",
"nome_parlamentar"="character", "nome_completo_parlamentar"="character","sexo_parlamentar"="character",
"forma_tratamento"="character", "url_foto_parlamentar"="character", "url_pagina_parlamentar"="character",
"email_parlamentar"="character", "sigla_partido_parlamentar"="character", "uf_parlamentar"="character",
"codigo_comissao"="character", "sigla_comissao"="character", "nome_comissao"="character",
"sigla_casa_comissao"="character", "nome_casa_comissao"="character")

.COLNAMES_RELATORIAS_CAMARA <- c("data_hora"="character", "nome_parlamentar"="character", "partido"="character", "sigla_orgao"="character",
"uri_orgao"="character")

# Emendas
.COLNAMES_EMENDAS_SENADO <- c("codigo_emenda"="character", "numero"="integer", "data_apresentacao"="character", "local"="character",
"descricao_turno"="character", "descricao_tipo_emenda"="character", "autor"="character", "id_autor"="character",
Expand Down
6 changes: 3 additions & 3 deletions R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
.CAMARA_PROPOSICOES_PATH <- "/api/v2/proposicoes"
.VOTACOES_PATH <- "/api/v2/votacoes"
.DEPUTADOS_PATH <- "/api/v2/deputados"
.SENADO_PATH <- "/dadosabertos/materia"
.RELATORIA_SENADO_PATH <- "/relatorias/"
.EMENDAS_SENADO_PATH <- "/emendas/"
.PARTIDOS_PATH <- "/api/v2/partidos"
.CAMARA_SESSOES_PATH <- "/proposicoesWeb/sessoes_e_reunioes"
.TIPOS_PROPOSICOES_PATH <- "/api/v2/referencias/proposicoes/siglaTipo"
Expand All @@ -39,6 +36,9 @@
.AGENDA_SENADO_PATH <- "/dadosabertos/plenario/agenda/mes/"
.AGENDA_SENADO_COMISSOES <- "/dadosabertos/agenda/"
.SENADO_VOTACOES_PATH <- "/dadosabertos/materia/votacoes/"
.SENADO_PATH <- "/dadosabertos/materia"
.RELATORIA_SENADO_PATH <- "/relatorias/"
.EMENDAS_SENADO_PATH <- "/emendas/"

# Link do repositório do rcongresso
.RCONGRESSO_LINK <- "https://github.com/analytics-ufcg/rcongresso"
Expand Down
16 changes: 14 additions & 2 deletions R/relatorias.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
####### Relatorias ######
#' @title Fetches proposição's relatoria historic
#' @description Returns a dataframe containing the relatoria's historic, with date and relator's name.
#' @details Senado contains details about the end of each relatoria and camara contains initials of local
Expand All @@ -17,12 +16,16 @@ fetch_relatorias <- function(proposicao_id, casa, last_n=NULL) {
else if(tolower(casa) == 'camara') {
relatorias <- .fetch_relatorias_camara(proposicao_id)
}
else {
stop("Param 'casa' is invalid, must be 'senado' or 'camara'")
}

if(!is.null(last_n)){
relatorias <-
relatorias %>%
utils::head(last_n)
}

return(relatorias)
}

Expand Down Expand Up @@ -73,5 +76,14 @@ fetch_relatorias <- function(proposicao_id, casa, last_n=NULL) {
#' @return Dataframe containing detailed information about relatorias of a proposição from Camara
#' @export
.fetch_relatorias_camara <- function(proposicao_id) {
tibble::tibble()
fetch_tramitacao(proposicao_id, 'camara') %>%
dplyr::filter(descricao_tramitacao == "Designação de Relator") %>%
dplyr::transmute(
data_hora,
nome_parlamentar = stringr::str_extract(despacho, stringr::regex('Dep.?([^,(]*)', ignore_case=TRUE)),
partido = stringr::str_match(despacho,'[(](.*?)[)]')[,2],
sigla_orgao,
uri_orgao
) %>%
dplyr::arrange(desc(data_hora))
}
4 changes: 2 additions & 2 deletions R/tramitacoes.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#' @param casa Proposition's casa
#' @return Dataframe containing all the tramitation.
#' @examples
#' tramitacao_pec241 <- fetch_sessoes(2088351,'camara')
#' tramitacao_pls229 <- fetch_sessoes(91341,'senado')
#' tramitacao_pec241 <- fetch_tramitacao(2088351,'camara')
#' tramitacao_pls229 <- fetch_tramitacao(91341,'senado')
#' @rdname fetch_tramitacao
#' @export
fetch_tramitacao <- function(id_prop, casa) {
Expand Down
Binary file modified inst/extdata/test_cache.rds
Binary file not shown.
20 changes: 13 additions & 7 deletions tests/testthat/test_relatorias.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ context("Relatorias")

# Setup
ID_PROP_SENADO <<- 91341
ID_PROP_CAMARA <<- 2121442
QUANT_IDS <<- 2
relatorias_senado_df <<- fetch_relatorias(ID_PROP_SENADO, "senado", QUANT_IDS)
relatorias_camara_df <<- fetch_relatorias(ID_PROP_CAMARA, "camara", QUANT_IDS)
ID_PROP_CAMARA <<- 257161
QUANT_RELATORES <<- 2
relatorias_senado_df <<- fetch_relatorias(ID_PROP_SENADO, "senado", QUANT_RELATORES)
relatorias_camara_df <<- fetch_relatorias(ID_PROP_CAMARA, "camara", QUANT_RELATORES)

# Testa erros
test_that("GET proposição inexistente", {
Expand All @@ -20,9 +20,15 @@ test_that("Is dataframe", {
})

test_that("Quantidade de linhas retornadas - fetch_relatorias",{
expect_equal(nrow(relatorias_senado_df), QUANT_IDS)
expect_equal(nrow(relatorias_senado_df), QUANT_RELATORES)
expect_equal(nrow(relatorias_camara_df), QUANT_RELATORES)
})

test_that("fetch_relatorias()", {
expect_true(all(sapply(relatorias_senado_df, class) %in% .COLNAMES_RELATORIAS))
test_that("fetch_relatorias() column names", {
expect_true(all(sapply(relatorias_senado_df, class) %in% .COLNAMES_RELATORIAS_SENADO))
expect_true(all(sapply(relatorias_camara_df, class) %in% .COLNAMES_RELATORIAS_CAMARA))
})

test_that("fetch_relatorias() when the casa param is invalid", {
expect_error(fetch_relatorias(21312, "invalid"))
})