From c750511b8525dddec4407bd16a82e7e11dbb7aac Mon Sep 17 00:00:00 2001 From: Guirec Andre <guirec.andre@ofb.gouv.fr> Date: Mon, 24 Feb 2025 16:49:04 +0100 Subject: [PATCH 1/2] plot.type heure ajoute dans report_mig_mult --- R/report_mig_mult.R | 64 +++++++++++++++++++++++- tests/testthat/test-01-report_mig_mult.R | 1 + 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/R/report_mig_mult.R b/R/report_mig_mult.R index 671a02e..62e098c 100644 --- a/R/report_mig_mult.R +++ b/R/report_mig_mult.R @@ -566,7 +566,69 @@ setMethod("plot", signature(x = "report_mig_mult", y = "missing"), definition = funout(gettext("The data for the plot have been assigned to envir_stacomi,write grdata<-get('grdata',envir_stacomi) to retrieve the object")) } - # ==========================end / type=3============================= + # ==========================type=4============================= + if (plot.type == "heure") { + grdata <- fun_date_extraction(data=report_mig_mult@data, # tableau de donnees e importer + nom_coldt = "ope_date_debut", # nom de la colonne + annee=TRUE, + mois=TRUE, + quinzaine=FALSE, + semaine=TRUE, + semaine_std=FALSE, + jour_an=FALSE, + jour_mois=TRUE, + heure=TRUE + ) + hhh <- grdata %>% group_by(heure, lot_tax_code, lot_std_code, ope_dic_identifiant) %>% summarize(N=sum(value)) + + if (length(unique(grdata$lot_tax_code)) == 1 & length(unique(grdata$lot_std_code)) == 1) { + p <- ggplot(hhh, aes(x = heure)) + + geom_histogram(aes(y=N), width = 0.6, colour = NA,stat="identity") + + coord_polar(start=3*pi/4) + + theme_minimal() + + ylab("Nombre")+ + facet_grid(ope_dic_identifiant ~ + ., scales = "free_y") + + } else if (length(unique(grdata$lot_tax_code)) == 1) { + p <- ggplot(hhh, aes(x = heure, fill=lot_std_code)) + + geom_histogram(aes(y=N), width = 0.6, colour = NA,stat="identity") + + coord_polar(start=3*pi/4) + + theme_minimal() + + ylab("Nombre")+ + facet_grid(ope_dic_identifiant ~ + ., scales = "free_y") + scale_fill_brewer(palette = "Set2") + + } else if (length(unique(grdata$lot_std_code)) == 1) { + p <- ggplot(hhh, aes(x = heure, fill=lot_tax_code)) + + geom_histogram(aes(y=N), width = 0.6, colour = NA,stat="identity") + + coord_polar(start=3*pi/4) + + theme_minimal() + + ylab("Nombre")+ + facet_grid(ope_dic_identifiant ~ + ., scales = "free_y") + scale_fill_brewer(palette = "Set2") + + } else { + p <- ggplot(hhh, aes(x = heure, fill=lot_std_code)) + + geom_histogram(aes(y=N), width = 0.6, colour = NA,stat="identity") + + coord_polar(start=3*pi/4) + + theme_minimal() + + ylab("Nombre")+ + facet_grid(cols=vars(hhh$ope_dic_identifiant) , rows=vars(hhh$lot_tax_code), scales = "free_y") + scale_fill_brewer(palette = "Set2") + # facet_grid(ope_dic_identifiant + lot_tax_code ~ + # ., scales = "free_y") + scale_fill_brewer(palette = "Set2") + } + + print(p) + assign("p_heure", p, envir = envir_stacomi) + if (!silent) + funout(gettext("The plot has been assigned to p_multiple in envir_stacomi,write p<-get('pmultiple',envir_stacomi) to retrieve the object")) + assign("grdata", grdata, envir_stacomi) + if (!silent) + funout(gettext("The data for the plot have been assigned to envir_stacomi,write grdata<-get('grdata',envir_stacomi) to retrieve the object")) + + } + # ==========================end / type=4============================= return(invisible(NULL)) }) diff --git a/tests/testthat/test-01-report_mig_mult.R b/tests/testthat/test-01-report_mig_mult.R index e9706fe..cecbb5c 100644 --- a/tests/testthat/test-01-report_mig_mult.R +++ b/tests/testthat/test-01-report_mig_mult.R @@ -269,6 +269,7 @@ test_that("Test plot", expect_error(plot(report_mig_mult,plot.type="standard",silent=TRUE), NA) expect_error(plot(report_mig_mult,plot.type="step",silent=TRUE), NA) expect_error(plot(report_mig_mult,plot.type="multiple",silent=TRUE), NA) + expect_error(plot(report_mig_mult,plot.type="heure",silent=TRUE), NA) rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) }) -- GitLab From f1ed066970e85d2df153f57473ec8fbf476585bb Mon Sep 17 00:00:00 2001 From: Guirec Andre <guirec.andre@ofb.gouv.fr> Date: Tue, 25 Feb 2025 09:35:15 +0100 Subject: [PATCH 2/2] changer heure en time --- R/report_mig_mult.R | 4 ++-- tests/testthat/test-01-report_mig_mult.R | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/report_mig_mult.R b/R/report_mig_mult.R index 62e098c..23a731a 100644 --- a/R/report_mig_mult.R +++ b/R/report_mig_mult.R @@ -567,7 +567,7 @@ setMethod("plot", signature(x = "report_mig_mult", y = "missing"), definition = } # ==========================type=4============================= - if (plot.type == "heure") { + if (plot.type == "time") { grdata <- fun_date_extraction(data=report_mig_mult@data, # tableau de donnees e importer nom_coldt = "ope_date_debut", # nom de la colonne annee=TRUE, @@ -620,7 +620,7 @@ setMethod("plot", signature(x = "report_mig_mult", y = "missing"), definition = } print(p) - assign("p_heure", p, envir = envir_stacomi) + assign("p_time", p, envir = envir_stacomi) if (!silent) funout(gettext("The plot has been assigned to p_multiple in envir_stacomi,write p<-get('pmultiple',envir_stacomi) to retrieve the object")) assign("grdata", grdata, envir_stacomi) diff --git a/tests/testthat/test-01-report_mig_mult.R b/tests/testthat/test-01-report_mig_mult.R index cecbb5c..a977d67 100644 --- a/tests/testthat/test-01-report_mig_mult.R +++ b/tests/testthat/test-01-report_mig_mult.R @@ -269,7 +269,7 @@ test_that("Test plot", expect_error(plot(report_mig_mult,plot.type="standard",silent=TRUE), NA) expect_error(plot(report_mig_mult,plot.type="step",silent=TRUE), NA) expect_error(plot(report_mig_mult,plot.type="multiple",silent=TRUE), NA) - expect_error(plot(report_mig_mult,plot.type="heure",silent=TRUE), NA) + expect_error(plot(report_mig_mult,plot.type="time",silent=TRUE), NA) rm(list = ls(envir = envir_stacomi), envir = envir_stacomi) }) -- GitLab