Skip to content
Snippets Groups Projects
Commit a3d38671 authored by LE DURAND Matteo's avatar LE DURAND Matteo
Browse files

Merge branch '14-dataset-all-activity' into 'main'

Resolve "créer un dataset qui contient toutes les issues de tous les projets."

See merge request !3
parents 495e7ca4 b01344c6
No related branches found
No related tags found
1 merge request!3Resolve "créer un dataset qui contient toutes les issues de tous les projets."
Global.R 0 → 100644
# global -----
# 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")
library(shinygouv)
# install.packages("shinygouv")
library(rvest)
# install.packages("rvest")
library(gouvdown)
# install.packages("gouvdown")
library(purrr)
#install.packages("purrr")
library(httr)
#install.packages("httr")
library(jsonlite)
#install.package("jsonlite")
# inisialisation de connexion pour GitlabR
gitlabr::set_gitlab_connection(gitlab_url = "https://gitlab-forge.din.developpement-durable.gouv.fr", #adresse internet
private_token = Sys.getenv("GITLAB_COM_TOKEN")) # Token personelle pour connexion
## seconde connexion pour une fonction API
gitlab_url <- "https://gitlab-forge.din.developpement-durable.gouv.fr"
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
# premier filtre pour les groupes
groupf <- (group[as.numeric(group$open_issues_count) != 0, ])
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
})
#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_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)
# fonction API ----
# Fonction pour récupérer les événements GitLab pour un projet
get_gitlab_events <- function(project_id, event_type = NULL) {
url <- paste0(gitlab_url, "/api/v4/projects/", project_id, "/events")
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
if (!is.null(event_type)) {
params[["action"]] <- event_type
}
response <- GET(url, headers, query = params)
httr::stop_for_status(response)
if (status_code(response) != 200) {
stop("Échec de la récupération des données pour le projet ", project_id, " : ", content(response, "text"))
}
events <- fromJSON(content(response, "text"), flatten = TRUE)
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(
{
get_gitlab_events(project_id, event_type)
},
error = function(e) {
message("Erreur lors de la récupération des événements pour le projet ", project_id, " : ", e$message)
return(NULL) # Retourner NULL en cas d'erreur pour ce projet
}
)
if (!is.null(events)) {
all_events[[as.character(project_id)]] <- events
}
}
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
# 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 %>%
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")
#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"))
Server.R 0 → 100644
server <- function(input, output) {
output$tablef <-
DT::renderDT({ DT::datatable(groupf, class = "display",options = list(
pageLength = 6 ,
order = list(6 , "desc"),
scrollY = 300, scrollX = 400, scroller = TRUE
)
)
}
)
output$issue_graph <- plotly::renderPlotly({
p <- ggplot2::ggplot(groupf) +
ggplot2::aes(x = reorder(name,-open_issues_count), y = open_issues_count) +
ggplot2::geom_col(fill = "#000091") +
gouvdown::theme_gouv() +
ggplot2::theme(legend.position = "none",
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y = element_blank())
plotly::ggplotly(p)
})
# filtre les issues pour seulement garder ls variable interresante et celles encore ouverte pourl'exploration des données
groupid <- shiny::reactive({gitlabr::gl_list_issues(project = input$ID1) %>%
dplyr::select(iid ,
title,
description ,
state ,
created_at ,
updated_at ,
type,
labels,
user_notes_count) })
groupidf <- shiny::reactive({groupid() %>% dplyr::filter( state == "opened")})
nfermer <- shiny::reactive({nrow(groupid() %>% dplyr::filter( state == "closed"))})
output$issue_nbr <- shiny::renderText({paste(nfermer(),"issues ont été fermées sur le projet", input$ID1)})
output$issue <-
DT::renderDT({
DT::datatable(groupidf(),
class = "display",
options = list(pageLength = 6 ,
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$activity <-
DT::renderDT({
DT::datatable(
final_table,
class = "display",
options = list(
pageLength = 20 ,
order = list(7 , "desc"),
scrollY = 2500,
scrollX = 800,
scroller = TRUE,
autoWidth = TRUE
)
)
})
filteredData <- reactive({
shiny::req(input$daterange)
data %>%
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")
ggplotly(p, tooltip = "text")
})
}
Ui.R 0 → 100644
ui <- shinygouv::navbarPage_dsfr(
title = "Dataviz GitlabR",
id = "nav",
header = shinygouv::header_dsfr(
intitule = c("République", "Française"),
nom_site_service = "Tableau de bord GitLab-Forge",
baseline = "Les Projets du Centre de Service de la Donnée"
),
# 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é"),
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"))
),
# Second tab Issue
shinygouv::navbarPanel_dsfr(
title = "Les issues du projet sélectionné",
shinygouv::fluidRow_dsfr(
shinygouv::column_dsfr(9,
shiny::textOutput("issue_nbr"),
# Adding space to the column
# https://www.systeme-de-design.gouv.fr/elements-d-interface/fondamentaux-techniques/espacement
extra_class = "fr-my-6w"
),
shinygouv::column_dsfr(3, shinygouv::dateRangeInput_dsfr(inputId = "daterange1",
label = "Date range:",
start = "2016-01-01",
separator = "à"),
extra_class = "fr-my-6w"),
shinygouv::column_dsfr(12, DT::DTOutput(outputId = "issue")
)
)
),
# third tab activity
shinygouv::navbarPanel_dsfr(
title = "Activité des projets",
shinygouv::fluidRow_dsfr(
shinygouv::column_dsfr(12, DT::DTOutput(outputId = "activity")
,extra_class = "fr-my-6w")
)
),
#Fourth tab graph activity an time
shinygouv::navbarPanel_dsfr(
title = "Graphique des projets par durée",
shinygouv::fluidRow_dsfr(
shinygouv::column_dsfr(12,shinygouv::dateRangeInput_dsfr(inputId = "daterange",
label = "Sélectionnez une période :",
start = "2024-07-01",
separator = "à"),
extra_class = "fr-my-6w"),
shinygouv::column_dsfr(12,plotly::plotlyOutput("filteredPlot", height = "700px"),
extra_class = "fr-mt-1w")
)
)
)
# 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")
library(shinygouv)
# install.packages("shinygouv")
library(rvest)
# install.packages("rvest")
set_gitlab_connection(gitlab_url = "https://gitlab-forge.din.developpement-durable.gouv.fr", #adresse internet
private_token = Sys.getenv("GITLAB_COM_TOKEN")) # Token personelle pour connexion
# 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 <-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
# transformation de chr en date
group$last_activity_at <- date(group$last_activity_at)
group$updated_at <- date(group$updated_at)
# premier filtre pour les groupes
groupf <- (group[as.numeric(group$open_issues_count) != 0, ])
groupf$open_issues_count <- as.numeric(groupf$open_issues_count)
# choix par identifiant de projet
choice <- groupf[1]
server <- function(input, output) {
output$tablef <-
renderDataTable({ datatable(groupf, class = "display",options = list(
pageLength = 6 ,
order = list(6 , "desc")
)
)
}
)
# nombre de ligne dans le groupe filter
nprojet <- nrow(groupf)
# le diagramme
output$issue_graph <- renderPlotly({
p <- ggplot(groupf) +
aes(x = reorder(name,-open_issues_count), y = open_issues_count, colour = name) +
geom_col(fill = "#318ce7") +
scale_color_hue(direction = 1) +
theme_bw() +
theme(legend.position = "none",
axis.title.x = element_blank(),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.y = element_blank())
ggplotly(p)
})
# visualiser quelle identifiant de projet séléctionner
output$value <-
renderPrint({ input$ID1 })
# filtre les issues pour seulement garder ls variable interresante et celles encore ouverte
groupid <- reactive({gl_list_issues(project = input$ID1) %>%
dplyr::select(id ,
iid ,
title,
description ,
state ,
created_at ,
updated_at ,
user_notes_count) %>% mutate(
created_at = as.Date(created_at, format = "%Y-%m-%d"),
updated_at = as.Date(updated_at, format = "%Y-%m-%d"))})
groupidf <- reactive({groupid() %>% filter( state == "opened")})
nfermer <- reactive({nrow(groupid() %>% filter( state == "closed"))})
output$issue_nbr <- renderPrint({nfermer()})
output$issue <-
renderDataTable({
datatable(groupidf(),
class = "display",
options = list(pageLength = 6 ,
order = list(6 , "desc")))
})
#output$commentaire_env <- reactive(
#renderPrint(gl_create_issue(project = 51640054, title = input$commentaire)))
#new_iid <- reactive(
#gl_create_issue(project = 51640054, title = input$commentaire)$iid[1])
#output$description_env <- reactive(
# renderPrint(gl_edit_issue(project = 51640054, new_iid,description = input$description)))
}
dashboardPage(
skin = "green", # blue,black, purple, green, red, yellow
dashboardHeader(
title = "¤ Mon tableau de bord ¤",
titleWidth = 250 # à modifier quand le titre est long
),
dashboardSidebar(
width = 250, # pour fixer la largeur du panneau latéral
sidebarMenu(
# ------------
menuItem("Données", tabName = "tab_donnees", icon = icon("square-gitlab")),
selectInput("ID1",
label = h3("l'ID séléctionné"),
choices = choice # les identifiants séléctionnable du groupe
),
verbatimTextOutput("value"),
submitButton(text = "valider", icon = icon("play")),
menuItem("issues", tabName = "tab_issue", icon = icon("list-check"))
# menuItem("soumettre une issue", tabName = "tab_nouveau", icon = icon("table"))
)
),
dashboardBody(
#---------------
#---------------
tabItems(
# ----------------------------
tabItem(tabName = "tab_donnees",
h2("Tableau"),
box(plotlyOutput(outputId = "issue_graph"), width = 12,collapsible = TRUE, background = "black"),
box(dataTableOutput(outputId = "tablef"), width = 12, background = "olive")
),
# ----------------------------
tabItem(tabName = "tab_issue",
h2("les issues"),
infoBox(title = "nombre d'issue clos", value = NULL, icon = icon("lock"), color = "green", width = 4),
verbatimTextOutput("issue_nbr"),
box(dataTableOutput(outputId = "issue"), width = 12),
),
# ----------------------------
tabItem(
tabName = "tab_nouveau",
h2("nouvelle issue"),
box(
textInput(
inputId = "commentaire",
label = "issue a ajouter",
value = ""
),
actionButton("ajouter", "ajouter")
),
box(
textInput(
inputId = "description",
label = "Puis description a ajouter",
value = ""
),
actionButton("ajouter", "ajouter")
)
)
)# fin tabItem global
) # fin body
)# fin du dashboard
# deploiement vers le sserveur interne de dataviz
library(RCurl)
# creation de l'adresse de connexion FTP au serveur
con_ftp_svr_dataviz = paste0("ftp://", Sys.getenv("svr_dataviz_user_dtv"), ":", Sys.getenv("svr_dataviz_mdp_dtv"),
"@", Sys.getenv("svr_dataviz_ip"), "/gitlabr/")
# creation d'une fonction de transfert FTP vers le serveur à l'aide de ftpUpload de RCurl
## Les adresses des fichiers à transferer parte de la racine du projet RStudio
to_svr_dataviz_ftp <- function(fic = "app/shiny_siclop.RData") {
ftpUpload(what = fic, to = paste0(con_ftp_svr_dataviz, fic))
}
# fichiers à transférer
app_files <- c("global.R", list.files("R/", full.names = TRUE, recursive = TRUE),
"server.R", "ui.R", "dataviz_gitlabr.Rproj")
# Exécution des transferts
lapply(X = app_files, FUN = to_svr_dataviz_ftp)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment