diff --git a/Global.R b/Global.R index 1c98db10728a076ff6d3444e9d7931fac2c56d54..ff1e3649f0cb9286e3240c5d983ce2f8cce7889b 100644 --- a/Global.R +++ b/Global.R @@ -2,37 +2,19 @@ # les packages nécessaire library(gitlabr) -# install.packages("gitlabr") library(DT) -# install.packages("DT") library(shiny) -# install.packages("shiny") -library(shinydashboard) -# install.packages("shinydashboard") -library(shinythemes) -# install.packages("shinythemes") library(dplyr) -# install.packages("dplyr") -library(tidyverse) -# install.packages("tidyverse") -library(randomcoloR) -# install.packages("randomcoloR") library(ggplot2) -# install.packages("ggplot2") library(plotly) -# install.packages("plotly") +# remotes::install_github("spyrales/shinygouv") library(shinygouv) -# install.packages("shinygouv") -library(rvest) -# install.packages("rvest") +# remotes::install_github("spyrales/gouvdown") library(gouvdown) -# install.packages("gouvdown") library(purrr) -#install.packages("purrr") library(httr) -#install.packages("httr") library(jsonlite) -#install.package("jsonlite") +library(utils) # inisialisation de connexion pour GitlabR gitlabr::set_gitlab_connection(gitlab_url = "https://gitlab-forge.din.developpement-durable.gouv.fr", #adresse internet @@ -44,35 +26,31 @@ token <- Sys.getenv("GITLAB_COM_TOKEN") # attention j'ai du modifier le filtre puisque les variable ne correspondait plus a ce de la veille on va peut etre partire sur le select() group <- gitlabr::gl_list_group_projects(group_id = 1013, max_page = 10) -group <- group %>% dplyr::select(id,name,created_at,star_count,last_activity_at,open_issues_count,updated_at,description,contains("members")) # _links.members - +group <- group %>% dplyr::select(id,name,created_at,star_count,last_activity_at,open_issues_count,updated_at,description,contains("members"),path) # _links.members # premier filtre pour les groupes groupf <- (group[as.numeric(group$open_issues_count) != 0, ]) +groupf <- groupf %>% + mutate( + name_encoded = utils::URLencode(name), # Encode les espaces et autres caractères spéciaux + analyse = paste0( + "<a href='https://gitlab-forge.din.developpement-durable.gouv.fr/dreal-pdl/csd/", + name_encoded, + "/-/value_stream_analytics' target='_blank'>GitLab_analytics</a>" + ) + ) %>% dplyr::select(id,name,created_at,star_count,last_activity_at,open_issues_count,updated_at,description,analyse,contains("members")) groupf$open_issues_count <- as.numeric(groupf$open_issues_count) # choix par identifiant de projet -choice <- groupf$id %>% setNames(groupf$name) - - -#identifier les variables disponible -var_group <- names(gl_list_group_projects(group_id = 1013, max_page = 10)) -var_issue <- names(gl_list_issues(project = 23034)) - -# parcourir la liste des identifiants ---- -résultats <- base::lapply(groupf$id, function(x) { - base::return(x) # La fonction doit retourner une valeur pour fonctionner -}) +choice <- groupf$id %>% stats::setNames(groupf$name) #creation du df pour le journal d'activité ---- -final_table <- résultats %>% - purrr::map_dfr(gl_list_issues) - -final_table <- final_table %>%dplyr::mutate(id = project_id) %>% - dplyr::select(id,project_id,title,description,state,created_at,updated_at,labels,labels1,labels2,labels3,assignees.username,assignees.state,author.username,type,confidential,references.short,closed_at,closed_by.username) +final_table0 <- purrr::map_dfr(groupf$id, gitlabr::gl_list_issues) -final_table <- final_table %>% - left_join(select(groupf,id,name),by = "id") %>% dplyr::select(name,project_id,title,description,state,created_at,updated_at,labels,labels1,labels2,labels3,assignees.username,assignees.state,author.username,type,confidential,references.short,closed_at,closed_by.username) +final_table <- final_table0 %>%dplyr::mutate(id = project_id) %>% + dplyr::select(id,project_id,title,description,state,created_at,updated_at,labels,labels1,labels2,labels3,assignees.username,assignees.state,author.username,type,confidential,references.short,closed_at,closed_by.username) %>% + dplyr::left_join(dplyr::select(groupf,id,name),by = "id") %>% + dplyr::select(name,project_id,title,description,state,created_at,updated_at,labels,labels1,labels2,labels3,assignees.username,assignees.state,author.username,type,confidential,references.short,closed_at,closed_by.username) # fonction API ---- # Fonction pour récupérer les événements GitLab pour un projet @@ -81,7 +59,7 @@ get_gitlab_events <- function(project_id, event_type = NULL) { headers <- add_headers(`PRIVATE-TOKEN` = token) # Construire la requête en fonction du type d'événement souhaité - params <- list(per_page = 100) # Limite à 100 événements par requête + params <- list(per_page = 1500) # Limite à 1500 événements par requête if (!is.null(event_type)) { params[["action"]] <- event_type } @@ -97,49 +75,63 @@ get_gitlab_events <- function(project_id, event_type = NULL) { events$project_id <- project_id # Ajouter l'identifiant du projet pour le suivi return(events) } -# Fonction pour récupérer les événements pour plusieurs projets---- -get_events_for_projects <- function(project_ids, event_type = NULL) { - all_events <- list() - for (project_id in project_ids) { - cat("Récupération des événements pour le projet : ", project_id, "\n") - events <- tryCatch( +# Fonction pour récupérer les événements pour plusieurs projets +get_events_for_projects <- function(project_ids, event_type = NULL) { + all_events <- map(project_ids, ~{ + cat("Récupération des événements pour le projet : ", .x, "\n") + tryCatch( { - get_gitlab_events(project_id, event_type) + get_gitlab_events(.x, event_type) }, error = function(e) { - message("Erreur lors de la récupération des événements pour le projet ", project_id, " : ", e$message) + message("Erreur lors de la récupération des événements pour le projet ", .x, " : ", e$message) return(NULL) # Retourner NULL en cas d'erreur pour ce projet } ) - if (!is.null(events)) { - all_events[[as.character(project_id)]] <- events - } - } + }) %>% + set_names(project_ids) %>% + discard(is.null) all_events_df <- bind_rows(all_events, .id = "project_id") return(all_events_df) } + # Liste des identifiants de projets -project_ids <- résultats # Remplacez par vos identifiants de projets +project_ids <- as.list(groupf$id) # Remplacez par vos identifiants de projets # Récupérer tous les événements pour tous les projets all_events <- get_events_for_projects(project_ids) # Convertir les données en un DataFrame all_events_df <- as_tibble(all_events) -# pour le graphique temps/projet -data <- all_events_df %>% +## pour le graphique temps/projet +# traduction des type +traduction <- c( + "created" = "Création", + "DiffNote"= "Note d'information", + "DiscussionNote" = "Note de discussion" , + "Issue" = "Ticket" , + "joined" = "Rejoint" , + "MergeRequest" = "Demande de fusion", + "pushed to" = "poussé vers", + "WikiPage::Meta" = "Page Wiki" +) + +data_chronol <- all_events_df %>% dplyr::mutate( id = project_id, - type = ifelse(is.na(target_type), action_name, target_type), - temps = created_at, - info = ifelse(is.na(push_data.commit_title),target_title,push_data.commit_title)) %>% - dplyr::select(id, type, temps, info) -data$temps <- as.Date(data$temps) -data <- data %>% - dplyr::left_join(select(groupf,id,name),by = "id") + type = dplyr::coalesce(target_type,action_name), + type = as.factor(type), + temps = lubridate::as_datetime( created_at), + info = dplyr::coalesce(push_data.commit_title,target_title)) %>% + dplyr::select(id, type, temps, info) %>% + dplyr::left_join(dplyr::select(groupf,id,name),by = "id") #au cas ou il reste des valeur manquante -data$info[is.na(data$info)] <- "" -data <- dplyr::distinct(data) -data <- data %>% dplyr::filter(!type %in% c("deleted", "pushed")) +data_chronol$info[is.na(data_chronol$info)] <- "" +data_chronol <- dplyr::distinct(data_chronol) +data_chronol <- data_chronol %>% dplyr::filter(!type %in% c("deleted", "pushed new")) + +# Traduire les niveaux de facteur +data_chronol <- data_chronol %>% + dplyr::mutate(type = dplyr::recode(type, !!!traduction)) diff --git a/Server.R b/Server.R index 9b5109698e28686213231f31f2d0d4700196ba4f..c332b0ba21828eb90694c76f2bf5dc7ac0afef74 100644 --- a/Server.R +++ b/Server.R @@ -4,7 +4,7 @@ server <- function(input, output) { pageLength = 6 , order = list(6 , "desc"), scrollY = 300, scrollX = 400, scroller = TRUE - ) + ), escape = FALSE ) } ) @@ -46,13 +46,7 @@ server <- function(input, output) { order = list(6 , "desc"), scrollY = 600, scrollX = 400, scroller = TRUE)) }) - dateinf <- shiny::reactive({ - tail(groupid()$created_at, 1) - }) - observeEvent(input$daterange1, { - print(dateinf()) - }) - output$dateinferieur <- renderText({dateinf()}) + output$dateinferieur <- shiny::renderText({dateinf()}) output$activity <- @@ -71,23 +65,27 @@ server <- function(input, output) { ) }) +# utilisation du jeu de donnée data_chronol qui se trouve dans le global filteredData <- reactive({ shiny::req(input$daterange) - data %>% + data_chronol %>% dplyr::filter(temps >= as.Date(input$daterange[[1]]) & temps <= as.Date(input$daterange[[2]])) }) output$filteredPlot <- plotly::renderPlotly({ - p <- ggplot(filteredData(), aes(x = temps, y = as.factor(name))) + - geom_jitter(aes(shape = type, color = type, text = paste("",info)), size = 3, width = 0.1,height = 0.5) + - labs(x = "Temps", shape = "Type", color = "Type") + - theme_gouv() + - theme(axis.text.x = element_text(angle = 0, hjust = 1), - axis.title.y = element_blank())+ - scale_color_gouv_discrete(palette = "pal_gouv_qual1") + p <- ggplot2::ggplot(filteredData(), ggplot2::aes(x = temps, y = as.factor(name))) + + ggplot2::geom_jitter(ggplot2::aes(shape = type,color = name,text = paste(temps, info, sep = "\n")), + size = 3,width = 0.75,height = 0,alpha = 0.5 + ) + + ggplot2::labs(x = "Temps") + + gouvdown::theme_gouv() + + ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 0, hjust = 1), axis.title.y = ggplot2::element_blank())+ + gouvdown::scale_color_gouv_discrete(palette = "pal_gouv_qual1")+ + scale_shape_manual(values = 1 : 10)+ + ggplot2::scale_x_datetime(date_labels = "%d %b", timezone = "Europe/Paris") - ggplotly(p, tooltip = "text") + plotly::ggplotly(p, tooltip = "text") }) } diff --git a/Ui.R b/Ui.R index 4fdecfc7eaf0fa7d2594b8a6c5462ac6687b489f..eb3ecf7e744ebd1b068c936a8a1f08b3f9e90dac 100644 --- a/Ui.R +++ b/Ui.R @@ -2,23 +2,48 @@ ui <- shinygouv::navbarPage_dsfr( title = "Dataviz GitlabR", id = "nav", header = shinygouv::header_dsfr( - intitule = c("République", "Française"), + intitule = c("DREAL", "Pays de la Loire"), nom_site_service = "Tableau de bord GitLab-Forge", - baseline = "Les Projets du Centre de Service de la Donnée" + baseline = "Les Projets du Centre de Services de la Donnée" + ), + footer = footer_dsfr( + intitule = c("Territoire", "Service"), + description = "une description", + accessibilite = "non", + add_extra_url_body = footer_extra_url_body_dsfr( + footer_li_dsfr( + href = "https://siteinternet.fr", + titre = "siteinternet.fr.fr - nouvelle fenêtre", + texte = "siteinternet.fr.fr", type = "body" + ), + footer_li_dsfr( + href = "https://siteinternet.fr", + titre = "siteinternet.fr.fr - nouvelle fenêtre", + texte = "siteinternet.fr.fr", type = "body" + ) + ), + add_extra_url_bottom = footer_extra_url_bottom_dsfr( + + footer_li_dsfr( + href = "https://siteinternet.fr", + titre = "siteinternet.fr.fr - nouvelle fenêtre", + texte = "siteinternet.fr.fr", type = "bottom" + ) + ) ), # First tab Projet shinygouv::navbarPanel_dsfr( title = "Choix du projet à sélectionné", shinygouv::fluidRow_dsfr( shinygouv::column_dsfr(12, selectInput("ID1", - label = h3("Nom du projet séléctionné"), + label = h3("Nom du projet séléctionner"), choices = choice ), extra_class = "fr-my-6w") ), shinygouv::fluidRow_dsfr(plotlyOutput(outputId = "issue_graph")), shinygouv::fluidRow_dsfr( shinygouv::column_dsfr(12, - DT::DTOutput(outputId = "tablef"),extra_class = "fr-mt-2w")) + DT::DTOutput(outputId = "tablef"),extra_class = "fr-my-1w")) ), @@ -38,13 +63,14 @@ ui <- shinygouv::navbarPage_dsfr( start = "2016-01-01", separator = "à"), extra_class = "fr-my-6w"), - shinygouv::column_dsfr(12, DT::DTOutput(outputId = "issue") + shinygouv::column_dsfr(12, DT::DTOutput(outputId = "issue"), + extra_class = "fr-my-1w" ) ) ), # third tab activity shinygouv::navbarPanel_dsfr( - title = "Activité des projets", + title = "Activité des issues", shinygouv::fluidRow_dsfr( shinygouv::column_dsfr(12, DT::DTOutput(outputId = "activity") ,extra_class = "fr-my-6w") @@ -56,11 +82,11 @@ ui <- shinygouv::navbarPage_dsfr( shinygouv::fluidRow_dsfr( shinygouv::column_dsfr(12,shinygouv::dateRangeInput_dsfr(inputId = "daterange", label = "Sélectionnez une période :", - start = "2024-07-01", + start = format(Sys.Date() - 7, format="%Y-%m-%d"), separator = "à"), extra_class = "fr-my-6w"), shinygouv::column_dsfr(12,plotly::plotlyOutput("filteredPlot", height = "700px"), - extra_class = "fr-mt-1w") + extra_class = "fr-my-1w") ) ) )