Mise en place API

This commit is contained in:
2026-06-11 10:23:33 +02:00
parent da46965f95
commit 699d976c80
5 changed files with 95 additions and 108 deletions
-32
View File
@@ -4,44 +4,12 @@ suppressPackageStartupMessages({
library(tidyr)
})
#' #' Nettoie une liste d'animaux hbcanim -------------------------------ANCIENNE VERSION
#' #' @param tab_anims dataframe. Liste d'animaux brute
#' #' @return Liste d'animaux nettoyée
#' clean_data_anims<- function(tab_anims, num_cheptel){
#' result_data <- tab_anims %>%
#' select(numero, chantiersPointage) %>%
#' unnest(chantiersPointage, names_sep = "_", keep_empty = TRUE) %>%
#'
#' # garder le dernier chantier adulte avant d'unnest les codes
#' filter(chantiersPointage_typePointage == "Adulte") %>%
#' group_by(numero) %>%
#' arrange(desc(chantiersPointage_datePointage)) %>%
#' slice(1) %>%
#' ungroup() %>%
#'
#' # maintenant seulement on unnest les codes du chantier sélectionné
#' unnest(chantiersPointage_pointages, names_sep = "_", keep_empty = TRUE) %>%
#'
#' pivot_wider(
#' names_from = chantiersPointage_pointages_codePointage,
#' values_from = chantiersPointage_pointages_notePointage,
#' names_glue = "{.name}_adulte"
#' ) %>%
#' mutate(across(any_of(c("DM_adulte", "DS_adulte", "AF_adulte")), as.numeric))
#'
#' result <- tab_anims %>%
#' left_join(result_data, by = "numero")
#' }
#' Nettoie une liste d'animaux hbcanim
#' @param tab_anims dataframe. Liste d'animaux brute
#' @return Liste d'animaux nettoyée
clean_data_anims<- function(tab_anims){
result_data <- tab_anims %>%
mutate(
# across(c("dmAdulte", "dsAdulte", "afAdulte", "pat12M", "pat18M", "pat24M", "rangVelageMipg", "fiabIiv1", "fiabIvv2Corr", "agevel1", "pat120", "pat210",
# "pat120Corrige", "pat210Corrige", "dmSevrage", "dsSevrage", "afSevrage", "nbVelageVeauxDeclares", "nbFinGestation"), as.numeric),
dateNaiss = as.Date(as.POSIXct(dateNaiss / 1000, origin = "1970-01-01", tz = "UTC")),
dateSortDetenteur = as.Date(as.POSIXct(dateSortDetenteur / 1000, origin = "1970-01-01", tz = "UTC"))
)
+2 -2
View File
@@ -215,10 +215,10 @@ fake <- function(){
get_parents_ipg <- function(){
rep_imp <- "/home/lea/Documents/ecow/"
meresIPG <- read_csv(paste(rep_imp, "nb_prod_IPG_byMERE_20260106.csv", sep='')) # ok 20230327
meresIPG <- read_csv(paste(rep_imp, "nb_prod_IPG_byMERE_20260106.csv", sep=''), show_col_types = FALSE)
colnames(meresIPG) <- c('ANIM','NBPRODIPG')
peresIPG <- read_csv(paste(rep_imp, "nb_prod_IPG_byPERE_20260106.csv", sep='')) # ok 20230327
peresIPG <- read_csv(paste(rep_imp, "nb_prod_IPG_byPERE_20260106.csv", sep=''), show_col_types = FALSE)
colnames(peresIPG) <- c('ANIM','NBPRODIPG')
parentsIPG <- rbind(meresIPG, peresIPG)