diff --git a/DESCRIPTION b/DESCRIPTION index 8dfa7fcf96d8287797fbed8e14b2a9df7ff2a58c..b9367f50639f4ca265498abab827a52bea30d7a9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: floodam.data Title: An easy way to recover and prepare some useful data linked to CBA applied to flood -Version: 0.9.22.0 +Version: 0.9.23.0 Authors@R: c( person(given = "Frédéric", family = "Grelot", diff --git a/NAMESPACE b/NAMESPACE index da403bf11575b581c3382a8597954a44317ae70f..18c1366953e216bd7e4ce49be463fecebd882aac 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,8 @@ export(alert_gaspar) export(alert_mattermost) export(analyse_catnat) export(analyse_intersection) +export(analyse_ppr) +export(analyse_ppr_state) export(apply_scheme) export(complete.pattern) export(create.date) diff --git a/R/adapt_gaspar.R b/R/adapt_gaspar.R index 8f4ea118cdf66d436590cd2ab88de4815e4bc5be..b7780baac41fe3919e64e6ae7befcf6686acac83 100644 --- a/R/adapt_gaspar.R +++ b/R/adapt_gaspar.R @@ -108,6 +108,16 @@ adapt_gaspar = function( hazard = names(floodam.data::pprn_classification)[-(1:2)] result = merge(result, floodam.data::pprn_classification) result = result[apply(result[hazard], 1, any),] + + result["state"] = analyse_ppr_state( + result[c( + "date_prescription", + "date_deprescription", + "date_cancellation", + "date_repeal", + "date_approval" + )] + ) } # Saving diff --git a/R/analyse_gaspar.R b/R/analyse_gaspar.R index ea92b16079e5838a5d5be381c59fa7c4fb2db1d4..916e19343d043a66acec816c531b99f3f611cc6c 100644 --- a/R/analyse_gaspar.R +++ b/R/analyse_gaspar.R @@ -1,4 +1,4 @@ -#' @title Analyse gaspar to give some elementary results +#' @title Analyse catnat theme from gaspar to give some elementary results #' #' @details #' @@ -26,7 +26,7 @@ analyse_catnat = function(catnat) { year = table(factor(format(event[["date_start"]], "%Y"), levels = 1982:as.integer(format(Sys.Date(), "%Y")))) month = table(factor(format(event[["date_start"]], "%m"), levels = sprintf("%02d", 1:12))) - type = table(event$catnat) + type = table(event[["catnat"]]) return ( list( @@ -42,3 +42,94 @@ analyse_catnat = function(catnat) { # plot(month, lwd = 10, col = "grey50", lend = 1) ; grid() } +#' @title Analyse ppr theme from gaspar to give state of documents +#' +#' @details +#' +#' To be added. +#' +#' @param ppr data.frame, data to be analysed +#' +#' @return A factor of state. +#' +#' @export +#' +#' @encoding UTF-8 +#' @author Frédéric Grelot + +analyse_ppr_state = function(ppr) { + classification = data.frame( + in_use = + !is.na(ppr[["date_approval"]]) & + is.na(ppr[["date_deprescription"]]) & + is.na(ppr[["date_cancellation"]]) & + is.na(ppr[["date_repeal"]]), + in_progress = + !is.na(ppr[["date_prescription"]]) & + is.na(ppr[["date_deprescription"]]) & + is.na(ppr[["date_cancellation"]]) & + is.na(ppr[["date_repeal"]]) & + is.na(ppr[["date_approval"]]), + cancelled = + !is.na(ppr[["date_deprescription"]]) | + !is.na(ppr[["date_cancellation"]]) | + !is.na(ppr[["date_repeal"]]), + unknown = + is.na(ppr[["date_prescription"]]) & + is.na(ppr[["date_deprescription"]]) & + is.na(ppr[["date_cancellation"]]) & + is.na(ppr[["date_repeal"]]) & + is.na(ppr[["date_approval"]]) + ) + if (any(unique(apply(classification, 1, sum)) != 1)) { + warning("Classification of pprn has duplicated types.") + } + result = rep(NA_character_, nrow(classification)) + result[classification[["unknown"]]] = "unknown" + result[classification[["cancelled"]]] = "cancelled" + result[classification[["in_progress"]]] = "progress" + result[classification[["in_use"]]] = "use" + return(factor(result, levels = c("use", "progress", "cancelled", "unknown"))) +} + +#' @title Analyse ppr theme from gaspar to give some elementary results +#' +#' @details +#' +#' The following treatments are performed: +#' - In the element detail, a matrix gives for each commune (rows), the count +#' of all procedures depening on their state (columns). The column <NA> is +#' alwas given even if, normally, it should stay at 0 for each commune. +#' - In the element summary, from the information in element detail, a state at +#' the commune is given. It is performed this way: if one document is in state +#' "use", the commune is in state "use", otherwise if one document is in state +#' "progress", the commune is in state "progress", otherwise if one document +#' is in state "cancelled", the commune is in state "cancelled", otherwise if +#' one document is in state "unknown", the commune is in state "unknown", +#' otherwise the commune's state is NA. +#' +#' @param ppr data.frame, data to be analysed +#' +#' @return A list of analysis (detail, summary) +#' +#' @export +#' +#' @encoding UTF-8 +#' @author Frédéric Grelot + +analyse_ppr = function(ppr) { + result = stats::aggregate(ppr["state"], ppr["commune"], table, useNA = "always") + detail = result[["state"]] + rownames(detail) = as.character(result[["commune"]]) + + summary = structure(rep(NA_character_, nrow(detail)), names = rownames(detail)) + summary[detail[, "unknown"] > 0] = "unknown" + summary[detail[, "cancelled"] > 0] = "cancelled" + summary[detail[, "progress"] > 0] = "progress" + summary[detail[, "use"] > 0] = "use" + + list( + detail = detail, + summary = factor(summary, c("use", "progress", "cancelled", "unknown")) + ) +} \ No newline at end of file diff --git a/data/scheme_gaspar_pprn.rda b/data/scheme_gaspar_pprn.rda index 4e79dc4e3ef96899b0e344927ae80efbd33d4199..e64d45ed4114968a6364f4e4ad3d9bb23b71b88f 100644 Binary files a/data/scheme_gaspar_pprn.rda and b/data/scheme_gaspar_pprn.rda differ diff --git a/dev/tag-message b/dev/tag-message index d10d584d155cee829b335665320e1d9b0583e394..3a10cb4f4aa7e89f6c2d21a1a308487095f9e7cd 100644 --- a/dev/tag-message +++ b/dev/tag-message @@ -1,15 +1,16 @@ -floodam.data Version: 0.9.21.0 +floodam.data Version: 0.9.23.0 0 errors ✔ | 0 warnings ✔ | 0 notes ✔ **Note de version** - * ajout de analyse_intersection, analyse_eaip + * ajout du theme pprn dans adapt_gaspar + * ajout de analyse_ppr, analyse_ppr_state **Détails** - nouvelle fonction - - analyse_intersection (provides analysis from st_intersects and st_intersection) - - analyse_eaip (wrapper of analyse_intersection for eaip DB) + - analyse_ppr (gives an analysis of ppr at commune level) + - analyse_ppr_state (analyse some dates in ppr procedure to decide their state) -# git tag -a v0.9.21.0 -F dev/tag-message +# git tag -a v0.9.23.0 -F dev/tag-message # git push --tags diff --git a/inst/extdata/scheme_gaspar_pprn.csv b/inst/extdata/scheme_gaspar_pprn.csv index e8957084a930dcc05c9a3778dc819f1d68ac8df2..5649314a71f10b1ed0691cca7151d9b966e10269 100644 --- a/inst/extdata/scheme_gaspar_pprn.csv +++ b/inst/extdata/scheme_gaspar_pprn.csv @@ -1,7 +1,7 @@ name;name_origin;order;keep;type;label_fr;source;length_source;type_source;comment id;cod_nat_pprn;1;TRUE;character;ID du PPRN;georisques;;text; pprn_label_fr;lib_pprn;2;TRUE;factor;libellé du PPRN;georisques;;text; -catchment_label_fr;lib_bassin_risques;3;FALSE;factor;libellé du bassin de risque;georisques;;text; +catchment_label_fr;lib_bassin_risques;3;TRUE;factor;libellé du bassin de risque;georisques;;text; hazard;num_risque;4;TRUE;factor;code du risque;georisques;;integer; hazard_label_fr;lib_risque;5;TRUE;factor;libellé du risque;georisques;;text; pprn_revised;list_codenat_ppr_revise;6;TRUE;list;code du PPRN révisé;georisques;;text; @@ -14,8 +14,8 @@ type_label_fr;cod_ppr;10;TRUE;factor;code du PPRN;georisques;;text; ;dat_montage_deb;13;FALSE;date;date de début de réflexion de l'élaboration;georisques;;text; ;dat_montage_fin;14;FALSE;date;date de fin de réflexion de l'élaboration;georisques;;text; date_prescription;dat_prescription;15;TRUE;date;date de l'arrêté préfectoral portant prescription;georisques;;text; -;dat_appli_ant;16;FALSE;date;date de l'arrêté préfectoral portant application anticipée;georisques;;text; -;dat_deprescription;17;FALSE;date;date de l'arrêté préfectoral portant déprescription;georisques;;text; +date_anticipated;dat_appli_ant;16;TRUE;date;date de l'arrêté préfectoral portant application anticipée;georisques;;text; +date_deprescription;dat_deprescription;17;TRUE;date;date de l'arrêté préfectoral portant déprescription;georisques;;text; ;dat_etu_hydro_deb;18;FALSE;date;date de début de réalisation des études hydrologiques et hydrauliques;georisques;;text; ;dat_etu_hydro_fin;19;FALSE;date;date de fin de réalisation des études hydrologiques et hydrauliques;georisques;;text; ;dat_etu_alea_deb;20;FALSE;date;date de début de l'élaboration des cartes d’aléas;georisques;;text; @@ -36,9 +36,9 @@ date_mise_a_enquete_deb;dat_mise_a_enquete_deb;34;TRUE;date;date d’ouverture d date_mise_a_enquete_fin;dat_mise_a_enquete_fin;35;TRUE;date;date de fermeture de l’enquête publique;georisques;;text; date_approval;dat_approbation;36;TRUE;date;date de l'arrêté préfectoral portant approbation;georisques;;text; date_amendment;dat_modification;37;TRUE;date;date de l'arrêté préfectoral prescrivant une modification;georisques;;text; -date_cancellation;dat_annulation;38;FALSE;date;date de la décision d'annulation du Tribunal Administratif;georisques;;text; -date_plu;dat_annexion_plu;39;FALSE;date;date de l'arrêté municipal annexant le PPR au PLU;georisques;;text; -date_extension;dat_proroga;40;FALSE;date;date de l'arrêté préfectoral prorogeant de 18 mois la date de prescription;georisques;;text; -date_repeal;dat_abrog;41;FALSE;date;date de l'arrêté préfectoral portant abrogation;georisques;;text; +date_cancellation;dat_annulation;38;TRUE;date;date de la décision d'annulation du Tribunal Administratif;georisques;;text; +date_plu;dat_annexion_plu;39;TRUE;date;date de l'arrêté municipal annexant le PPR au PLU;georisques;;text; +date_extension;dat_proroga;40;TRUE;date;date de l'arrêté préfectoral prorogeant de 18 mois la date de prescription;georisques;;text; +date_repeal;dat_abrog;41;TRUE;date;date de l'arrêté préfectoral portant abrogation;georisques;;text; revision;etat_revision;42;TRUE;logical;Indique si le PPR a été révisé ou non;georisques;;text; date_update;dat_maj;43;TRUE;date;date de mise à jour de la fiche gaspar;georisques;;text; diff --git a/man/analyse_catnat.Rd b/man/analyse_catnat.Rd index 26ea665568cedbdc3663efc5cb441680aba86ebd..4e98036729dccd0b7929ce429b4fa1faedbafb86 100644 --- a/man/analyse_catnat.Rd +++ b/man/analyse_catnat.Rd @@ -3,7 +3,7 @@ \encoding{UTF-8} \name{analyse_catnat} \alias{analyse_catnat} -\title{Analyse gaspar to give some elementary results} +\title{Analyse catnat theme from gaspar to give some elementary results} \usage{ analyse_catnat(catnat) } @@ -14,7 +14,7 @@ analyse_catnat(catnat) A list of analysis (catnat, event, year, month, and type) } \description{ -Analyse gaspar to give some elementary results +Analyse catnat theme from gaspar to give some elementary results } \details{ The following treatments are performed: diff --git a/man/analyse_ppr.Rd b/man/analyse_ppr.Rd new file mode 100644 index 0000000000000000000000000000000000000000..b657dca9b19029278af6b00cbd276c8de453a7d2 --- /dev/null +++ b/man/analyse_ppr.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/analyse_gaspar.R +\encoding{UTF-8} +\name{analyse_ppr} +\alias{analyse_ppr} +\title{Analyse ppr theme from gaspar to give some elementary results} +\usage{ +analyse_ppr(ppr) +} +\arguments{ +\item{ppr}{data.frame, data to be analysed} +} +\value{ +A list of analysis (detail, summary) +} +\description{ +Analyse ppr theme from gaspar to give some elementary results +} +\details{ +The following treatments are performed: +- In the element detail, a matrix gives for each commune (rows), the count + of all procedures depening on their state (columns). The column <NA> is + alwas given even if, normally, it should stay at 0 for each commune. +- In the element summary, from the information in element detail, a state at + the commune is given. It is performed this way: if one document is in state + "use", the commune is in state "use", otherwise if one document is in state + "progress", the commune is in state "progress", otherwise if one document + is in state "cancelled", the commune is in state "cancelled", otherwise if + one document is in state "unknown", the commune is in state "unknown", + otherwise the commune's state is NA. +} +\author{ +Frédéric Grelot +} diff --git a/man/analyse_ppr_state.Rd b/man/analyse_ppr_state.Rd new file mode 100644 index 0000000000000000000000000000000000000000..c8f3b2e452c952b572a197c44e7785b28b5ac5de --- /dev/null +++ b/man/analyse_ppr_state.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/analyse_gaspar.R +\encoding{UTF-8} +\name{analyse_ppr_state} +\alias{analyse_ppr_state} +\title{Analyse ppr theme from gaspar to give state of documents} +\usage{ +analyse_ppr_state(ppr) +} +\arguments{ +\item{ppr}{data.frame, data to be analysed} +} +\value{ +A factor of state. +} +\description{ +Analyse ppr theme from gaspar to give state of documents +} +\details{ +To be added. +} +\author{ +Frédéric Grelot +} diff --git a/script/maintain_gaspar.R b/script/maintain_gaspar.R index e38ec2b541376e48280bec009dd8534bfe5b5bee..052953747857123d48d41bf70a121d554f4693fb 100644 --- a/script/maintain_gaspar.R +++ b/script/maintain_gaspar.R @@ -11,3 +11,10 @@ adapted = "data-local/floodam-data/adapted/gaspar" floodam.data::download_gaspar(original) floodam.data::adapt_gaspar(original, adapted, scope = list("so_ii" = so.ii::so_ii_scope)) floodam.data::alert_gaspar(adapted, scope = "so_ii") + +ppri = adapt_gaspar( + original, adapted, + theme = "pprn", + scope = list("so_ii" = so.ii::so_ii_scope), + retrieve = TRUE, keep = TRUE) +ppri_commune = analyse_ppr(ppri) \ No newline at end of file