Skip to content
Snippets Groups Projects
Commit 3bd733e1 authored by Franck.Gaspard's avatar Franck.Gaspard
Browse files

remaniement des fonctions et nouveau calcul des data

0 errors :heavy_check_mark: | 0 warnings :heavy_check_mark: | 2 notes :heavy_multiplication_x:

── R CMD check results ──────────────────────────────────────── nitrates.pdl 0.0.0.9000 ────
Duration: 3m 3.4s

❯ checking installed package size ... NOTE
    installed size is 15.1Mb
    sub-directories of 1Mb or more:
      app       3.4Mb
      data     10.3Mb
      extdata   1.0Mb

❯ checking for future file timestamps ... NOTE
  unable to verify current time

0 errors :heavy_check_mark: | 0 warnings :heavy_check_mark: | 2 notes :heavy_multiplication_x:

R CMD check succeeded
parent 6cb0c598
Branches
No related tags found
2 merge requests!3fusion de dev_actualisation_2024 vers master,!2fusion de actualisation_table_unique_prelevement_analyse vers dev_actualisation_2024
Showing
with 65 additions and 52 deletions
......@@ -2,35 +2,18 @@
#'
#' percentiles 90 par station par annee.
#'
#' @format A data frame with 12848 rows and 29 variables:
#' @format A data frame with 12848 rows and 12 variables:
#' \describe{
#' \item{ code_station }{ factor }
#' \item{ code_bss }{ factor }
#' \item{ code_sise_eaux }{ factor }
#' \item{ code_naiades }{ factor }
#' \item{ libelle_station }{ factor }
#' \item{ code_nature_eau }{ factor }
#' \item{ date_creation }{ Date }
#' \item{ annee }{ numeric }
#' \item{ source_station }{ factor }
#' \item{ code_masse_eau }{ factor }
#' \item{ code_bassin_versant }{ factor }
#' \item{ code_commune }{ factor }
#' \item{ code_sage }{ factor }
#' \item{ captage_prioritaire }{ logical }
#' \item{ insee_dep }{ factor }
#' \item{ test }{ logical }
#' \item{ code_intervenant }{ factor }
#' \item{ code_reseau }{ factor }
#' \item{ code_support }{ numeric }
#' \item{ id_usage }{ factor }
#' \item{ id_prelevement_motif }{ factor }
#' \item{ P90 }{ numeric }
#' \item{ code_parametre }{ factor }
#' \item{ code_fraction_analysee }{ integer }
#' \item{ limite_detection }{ numeric }
#' \item{ limite_quantification }{ factor }
#' \item{ annee }{ numeric }
#' \item{ the_geom }{ sfc_POINT,sfc }
#' \item{ code_nature_eau }{ factor }
#' \item{ pos_a_garder }{ numeric }
#' \item{ classe }{ factor }
#' }
......
......@@ -4,7 +4,7 @@
#'
#' @format A data frame with 6231 rows and 5 variables:
#' \describe{
#' \item{ code_bassin_versant }{ factor }
#' \item{ code_bassin_versant }{ character }
#' \item{ annee }{ numeric }
#' \item{ code_nature_eau }{ factor }
#' \item{ maxP90 }{ numeric }
......
......@@ -4,7 +4,7 @@
#'
#' @format A data frame with 6231 rows and 5 variables:
#' \describe{
#' \item{ code_bassin_versant }{ factor }
#' \item{ code_bassin_versant }{ character }
#' \item{ annee }{ numeric }
#' \item{ code_nature_eau }{ factor }
#' \item{ moyP90 }{ numeric }
......
......@@ -2,7 +2,7 @@
#'
#' tendances des percentiles 90 par station par période de 10 ans.
#'
#' @format A data frame with 23450 rows and 5 variables:
#' @format A data frame with 10135 rows and 5 variables:
#' \describe{
#' \item{ code_station }{ factor }
#' \item{ libelle_station }{ factor }
......
......@@ -2,7 +2,7 @@
#'
#' données à télécharger des tendances des percentiles 90 par station par période de 10 ans.
#'
#' @format A data frame with 23450 rows and 12 variables:
#' @format A data frame with 10135 rows and 12 variables:
#' \describe{
#' \item{ periode }{ factor }
#' \item{ code_nature_eau }{ factor }
......
......@@ -164,7 +164,7 @@ prepa_NatureEau_fct <- function(station_pdl){
#' @importFrom dplyr group_by arrange mutate n filter rename select ungroup case_when mutate_if
prepa_nitrates_P90_fct <- function(nitrates){
nitrates_P90 <- nitrates %>%
dplyr::left_join(station_pdl) %>%
dplyr::left_join(station_pdl %>% sf::st_drop_geometry()) %>%
dplyr::group_by(code_station, annee) %>%
dplyr::arrange(code_station, annee, desc(resultat_analyse)) %>%
dplyr::mutate(
......@@ -189,8 +189,10 @@ prepa_nitrates_P90_fct <- function(nitrates){
)
) %>%
dplyr::select(
-c(code_prelevement_analyse, source_prelevement_analyse, date_prelevement, heure_prelevement, mois,
date_analyse, code_remarque)
# -c(code_prelevement_analyse, source_prelevement_analyse, date_prelevement, heure_prelevement, mois,
# date_analyse, code_remarque)
c(code_station, code_bss, code_sise_eaux, code_naiades, libelle_station,
annee, source_station, id_usage, P90, code_nature_eau, pos_a_garder, classe)
) %>%
dplyr::filter(!is.na(classe)) %>%
dplyr::mutate_if(is.character,as.factor)
......@@ -326,6 +328,12 @@ prepa_periode_nitrates_tendanceP90_fct <- function(annee){
prepa_nitrates_bassin_versant_fct <- function(nitrates_P90){
nitrates_bassin_versant <- nitrates_P90 %>%
dplyr::semi_join(station_pdl) %>%
dplyr::left_join(
station_pdl %>%
dplyr::select(c(code_station, libelle_station, code_bassin_versant)) %>%
sf::st_drop_geometry(),
by = c("code_station")
) %>%
dplyr::group_by(code_bassin_versant, annee, code_nature_eau) %>%
dplyr::summarise(
moyP90 = round(mean(P90), digits = 2),
......@@ -409,6 +417,11 @@ prepa_repartition_P90_fct <- function(
){
repartition_P90_region <- nitrates_P90 %>%
dplyr::semi_join(station_pdl) %>%
dplyr::left_join(
station_pdl %>%
dplyr::select(code_station, code_sage, code_bassin_versant, insee_dep) %>%
sf::st_drop_geometry()
) %>%
dplyr::group_by(code_nature_eau, annee, classe) %>%
dplyr::summarise(n = dplyr::n()) %>%
dplyr::mutate(
......@@ -420,6 +433,11 @@ prepa_repartition_P90_fct <- function(
repartition_P90_sage <- nitrates_P90 %>%
dplyr::semi_join(station_pdl) %>%
dplyr::left_join(
station_pdl %>%
dplyr::select(code_station, code_sage, code_bassin_versant, insee_dep) %>%
sf::st_drop_geometry()
) %>%
dplyr::group_by(code_nature_eau, code_sage, annee, classe) %>%
dplyr::summarise(n = dplyr::n()) %>%
dplyr::mutate(
......@@ -436,6 +454,11 @@ prepa_repartition_P90_fct <- function(
repartition_P90_bassin_versant <- nitrates_P90 %>%
dplyr::semi_join(station_pdl) %>%
dplyr::left_join(
station_pdl %>%
dplyr::select(code_station, code_sage, code_bassin_versant, insee_dep) %>%
sf::st_drop_geometry()
) %>%
dplyr::group_by(code_nature_eau, code_bassin_versant, annee, classe) %>%
dplyr::summarise(n = dplyr::n()) %>%
dplyr::mutate(
......@@ -501,7 +524,9 @@ prepa_repartition_tendanceP90_fct <- function(
repartition_tendanceP90_sage <- nitrates_tendanceP90 %>%
dplyr::semi_join(station_pdl) %>%
dplyr::left_join(
station_pdl %>% dplyr::select(code_station, code_sage, code_bassin_versant) %>% sf::st_drop_geometry()
station_pdl %>%
dplyr::select(code_station, code_sage, code_bassin_versant) %>%
sf::st_drop_geometry()
) %>%
dplyr::group_by(code_nature_eau, code_sage, periode,tendance) %>%
dplyr::summarise(n = dplyr::n()) %>%
......@@ -522,7 +547,9 @@ prepa_repartition_tendanceP90_fct <- function(
repartition_tendanceP90_bassin_versant <- nitrates_tendanceP90 %>%
dplyr::semi_join(station_pdl) %>%
dplyr::left_join(
station_pdl %>% dplyr::select(code_station, code_sage, code_bassin_versant) %>% sf::st_drop_geometry()
station_pdl %>%
dplyr::select(code_station, code_sage, code_bassin_versant) %>%
sf::st_drop_geometry()
) %>%
dplyr::group_by(code_nature_eau, code_bassin_versant, periode, tendance) %>%
dplyr::summarise(n = dplyr::n()) %>%
......@@ -640,11 +667,13 @@ prepa_nitrates_nature_eau_fct <- function(station_pdl, nature_eau){
#' @export
#' @importFrom dplyr group_by mutate n ungroup filter select left_join bind_rows mutate_if arrange
#' @importFrom sf st_drop_geometry
prepa_depassement_seuil_nature_eau_fct <- function(nitrates_nature_eau,
seuil,
station_pdl,
n_sage_r52,
masse_eau_bassin_versant_PDL){
prepa_depassement_seuil_nature_eau_fct <- function(
nitrates_nature_eau,
seuil,
station_pdl,
n_sage_r52,
masse_eau_bassin_versant_PDL
){
depassement_seuil_region <- nitrates_nature_eau %>%
dplyr::group_by(annee) %>%
unique() %>%
......@@ -751,7 +780,8 @@ prepa_nitrates_telecharger_fct <- function(
source_prelevement_analyse
) %>%
dplyr::left_join(
station_pdl %>% sf::st_drop_geometry() %>%
station_pdl %>%
sf::st_drop_geometry() %>%
dplyr::select(
code_station,
code_sage,
......@@ -803,7 +833,8 @@ prepa_nitrates_P90_telecharger_fct <- function(
classe
) %>%
dplyr::left_join(
station_pdl %>% sf::st_drop_geometry() %>%
station_pdl %>%
sf::st_drop_geometry() %>%
dplyr::select(
code_station,
code_sage,
......@@ -847,7 +878,8 @@ prepa_nitrates_tendanceP90_telecharger_fct <- function(
nitrates_tendanceP90_telecharger <- nitrates_tendanceP90 %>%
dplyr::semi_join(station_pdl, by = c("code_station")) %>%
dplyr::left_join(
station_pdl %>% sf::st_drop_geometry() %>%
station_pdl %>%
sf::st_drop_geometry() %>%
dplyr::select(
code_station,
code_sage,
......
......@@ -40,7 +40,8 @@ utils::globalVariables(
"bassin_versant_pa_telecharger", "departement_pa_telecharger",
"depassement", "nbre_depassement", "non_depassement",
"captage_prioritaire"
"captage_prioritaire",
"code_prelevement_analyse", "source_prelevement_analyse",
"code_bss", "code_naiades", "code_sise_eaux"
)
)
......@@ -266,6 +266,7 @@ usethis::use_data(
# # versement sur le sgbd/datamart/nitrates ------
datalibaba::poster_data(
data = nitrates_P90,
db = "datamart",
......@@ -277,10 +278,6 @@ datalibaba::poster_data(
droits_schema = TRUE,
user = "does"
)
# Erreur : COPY returned error : ERROR: invalid hexadecimal digit: "P"
# CONTEXT: COPY nitrates_p90_v0_21, line 1, column the_geom: "\xPOINT (399586 6830769)"
# lignes 267 et 268 de prepa_referentiel.R a priori
datalibaba::commenter_table(
comment = "calcul du P90 par station",
......@@ -301,10 +298,6 @@ datalibaba::poster_data(
droits_schema = TRUE,
user = "does"
)
# Erreur : Failed to fetch row : ERROR: could not create unique index "nitrates_tendancep90_v0_21_pkey"
# DETAIL: Key (code_station, libelle_station, periode)=(035000242, PONT JUHEL (L'AIRON), 2007 - 2016) is duplicated.
# idem
datalibaba::commenter_table(
comment = "calcul de la tendance P90 par station",
......@@ -344,6 +337,7 @@ datalibaba::poster_data(
droits_schema = TRUE,
user = "does"
)
datalibaba::commenter_table(
comment = "calcul du maximum P90 par bassin versant",
db = "datamart",
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -5,7 +5,7 @@
\alias{depassement_seuil_eso}
\title{depassement_seuil_eso}
\format{
A data frame with 867 rows and 5 variables:
A data frame with 921 rows and 5 variables:
\describe{
\item{ annee }{ factor }
\item{ depassement }{ numeric }
......
......@@ -5,7 +5,7 @@
\alias{depassement_seuil_esu}
\title{depassement_seuil_esu}
\format{
A data frame with 3444 rows and 5 variables:
A data frame with 3694 rows and 5 variables:
\describe{
\item{ annee }{ factor }
\item{ depassement }{ numeric }
......
......@@ -5,12 +5,15 @@
\alias{nitrates_P90}
\title{nitrates_P90}
\format{
A data frame with 11972 rows and 9 variables:
A data frame with 12848 rows and 12 variables:
\describe{
\item{ code_station }{ factor }
\item{ code_bss }{ factor }
\item{ code_sise_eaux }{ factor }
\item{ code_naiades }{ factor }
\item{ libelle_station }{ factor }
\item{ source_station }{ factor }
\item{ annee }{ numeric }
\item{ source_station }{ factor }
\item{ id_usage }{ factor }
\item{ P90 }{ numeric }
\item{ code_nature_eau }{ factor }
......
......@@ -5,7 +5,7 @@
\alias{nitrates_P90_telecharger}
\title{nitrates_P90_telecharger}
\format{
A data frame with 7781 rows and 13 variables:
A data frame with 12848 rows and 13 variables:
\describe{
\item{ annee }{ numeric }
\item{ code_nature_eau }{ factor }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment