From 779371595298e80a5a160c9b7984039dee5fa4ea Mon Sep 17 00:00:00 2001 From: GeraldineGomez Date: Thu, 25 Apr 2024 07:24:55 -0500 Subject: [PATCH 1/2] fix(calcular_incidencia): added validation of coeficiente and default value Ref: #108 --- R/checking_data.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/checking_data.R b/R/checking_data.R index d0b6ef38..bdfa2efa 100644 --- a/R/checking_data.R +++ b/R/checking_data.R @@ -934,7 +934,7 @@ calcular_incidencia <- function(data_incidencia, data_agrupada, year, poblacion <- NULL total_casos <- NULL total_poblacion <- NULL - incidencia <- 0 + incidencia <- 0.00 nomb_cols <- obtener_tip_ocurren_geo(data_agrupada$nombre_evento[1]) unidades_geo <- obtener_dpto_mpio(data_agrupada = data_agrupada, nomb_cols = nomb_cols, @@ -983,9 +983,15 @@ calcular_incidencia <- function(data_incidencia, data_agrupada, year, vals_event <- obtener_cond_inciden_event(cod_eve = data_agrupada$cod_eve[1]) vals_event$coeficiente <- as.integer(vals_event$coeficiente) if (total_poblacion > 0) { + if (length(vals_event$coeficiente) == 0) { + vals_event$coeficiente <- 100000 + } incidencia <- round((total_casos / total_poblacion) * vals_event$coeficiente, 2) + if (length(incidencia) == 0) { + incidencia <- 0.00 + } } return(incidencia) } From 9da2179808e0c01598ebc0e564a0be6bcb977863 Mon Sep 17 00:00:00 2001 From: GeraldineGomez Date: Thu, 25 Apr 2024 07:25:57 -0500 Subject: [PATCH 2/2] fix(calcular_incidencia_sex): group data by event and calculation Ref: #108 --- R/checking_data.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/checking_data.R b/R/checking_data.R index bdfa2efa..3bdb98f5 100644 --- a/R/checking_data.R +++ b/R/checking_data.R @@ -1138,6 +1138,16 @@ calcular_incidencia_sex <- function(data_incidencia, mpio <- dept_data$codigo_municipio } } + cod_eve <- data_agrupada$cod_eve[1] + nombre_evento <- data_agrupada$nombre_evento[1] + data_agrupada <- data_agrupada %>% + group_by_at("sexo") %>% + dplyr::summarise(casos = sum(.data[["casos"]]), .groups = "drop") + cols_eve <- data.frame(cod_eve = rep(cod_eve, + nrow(data_agrupada)), + nombre_evento = rep(nombre_evento, + nrow(data_agrupada))) + data_agrupada <- cbind(data_agrupada, cols_eve) for (fila in seq_len(nrow(data_agrupada))) { sex_fila <- data_agrupada[fila, ] incidencia_sex <- calcular_incidencia(data_incidencia = data_incidencia,