generated from dataforgoodfr/d4g-project-template
-
Notifications
You must be signed in to change notification settings - Fork 51
Ajour des résultats des metaux lourds #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
7bbc835
init
simondac c115571
init
simondac 1b4ea89
delete
simondac ad7843d
livraison métaux lourds - plomb pour 1ère PR
simondac 3b827e1
suppression ";" qui pose problème
simondac 02814fc
correction resultats_udi_pb_dernier_prel.datetimeprel
simondac 8959dc4
bug accepted_values corrigé
simondac 59f4692
modif marginales
simondac a93e28a
mise à niveau suite chgt venv
simondac b06b8a4
correction
simondac 2e60b61
Merge remote-tracking branch 'origin/main' into analyst/simon_met_lou…
simondac 7b6ed93
ajout description et type
simondac c19ea13
vérif nom categorie suite à merge main dans branche
simondac 07434f6
ajout "ref" dans .SQL
simondac b05a156
fix ref
simondac 3e6058c
correction >=10 au lieu de >10
simondac 6b9b694
fichier renommé
simondac 5bb0d0b
ajout arsenic dernier prel
simondac d73f1e6
notebook complété suite à ajout Arsenic et simplification requête der…
simondac e0909bc
ajout arsenic
simondac 66b043b
correction longueur lignes
simondac f70d90e
fix reference
simondac 14609c0
fix ref ?
simondac bdfedaa
suppr unicité cdreseau
simondac 646c366
modif suite review Vinca
simondac 9fdb360
modif model
simondac ceb3626
modif indentation
simondac 7c0ee63
modif indentation
simondac 6eec0da
ajout commune dernier prel
simondac 20772de
sup_limite_qualite renommé sup_limite_sanitaire
simondac 08d13b2
fix sup_limite_sanitaire
simondac e24d493
Ajout requêtes prélèvements annuels UDI et Commune
simondac 8d234f4
fix ligne vierge fin script
simondac 1102c4c
ajout annuel dans model yaml
simondac 380f2e3
suppr venv
simondac 1fcd803
venv non indexés
simondac c26a6a6
venv non indexé
simondac 483c484
modif test unicité
simondac 65a83f1
Merge branch 'main' into analyst/simon_met_lourds_arsenic_pb
simondac b0e2a90
ajout categorie au test d'unicité sub_indus annuel
simondac 900a936
ajout description et type manquatns
simondac eeba613
récupération des valeurs des champs limite_qualite et valeur_sanitair…
simondac 68b3a61
Merge branch 'main' into analyst/simon_met_lourds_arsenic_pb
jereze 6ca59e0
update int__resultats_metaux_lourds_*_dernier models
jereze 56c137e
update int__resultats_metaux_lourds_*_annuel models
jereze b55806b
add metaux_lourds to results
jereze bd69c85
config website
jereze File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4,190 changes: 4,190 additions & 0 deletions
4,190
analytics/notebooks/resultats_metaux_lourds.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
dbt_/models/intermediate/metaux_lourds/_int__metaux_lourds_models.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
models: | ||
- name: int__resultats_metaux_lourds_udi_dernier | ||
description: Résultats des métaux lourds (Plomb et Arsenic) par UDI pour la temporalité 'dernier prélèvement' | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- cdreseau | ||
- categorie | ||
columns: | ||
- name: cdreseau | ||
description: "Code de l'installation (unité de distribution)" | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- name: date_dernier_prel | ||
description: "Date et heure du dernier prélèvement pris en compte dans l'analyse." | ||
type: TIMESTAMP | ||
tests: | ||
- not_null | ||
- dbt_utils.expression_is_true: | ||
expression: ">= CURRENT_DATE - INTERVAL 1 YEAR" | ||
- name: periode | ||
description: "Période de résultat" | ||
type: VARCHAR | ||
tests: | ||
- accepted_values: | ||
values: ["dernier_prel"] | ||
- name: nb_parametres | ||
type: INTEGER | ||
- name: categorie | ||
type: VARCHAR | ||
tests: | ||
- accepted_values: | ||
values: | ||
- metaux_lourds_pb | ||
- metaux_lourds_as | ||
- name: resultat | ||
description: "Interprétation du résultat en fonction des seuils sanitaires et des valeurs mesurées." | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- accepted_values: | ||
values: | ||
- non_quantifie | ||
- sup_limite_qualite | ||
- sup_limite_qualite_2036 | ||
- sup_valeur_sanitaire | ||
- inf_limite_qualite | ||
- name: parametres_detectes | ||
description: "JSON contenant les paramètres détectés (valtraduite > 0) avec leurs valeurs correspondantes." | ||
type: JSON | ||
|
||
- name: int__resultats_metaux_lourds_commune_dernier | ||
description: Résultats des métaux lourds (Plomb et Arsenic) par commube pour la temporalité 'dernier prélèvement' | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- inseecommune | ||
- categorie | ||
columns: | ||
- name: inseecommune | ||
description: "Code INSEE de la commune" | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- name: date_dernier_prel | ||
description: "Date et heure du dernier prélèvement pris en compte dans l'analyse." | ||
type: TIMESTAMP | ||
tests: | ||
- not_null | ||
- dbt_utils.expression_is_true: | ||
expression: ">= CURRENT_DATE - INTERVAL 1 YEAR" | ||
- name: periode | ||
description: "Période de résultat" | ||
type: VARCHAR | ||
tests: | ||
- accepted_values: | ||
values: ["dernier_prel"] | ||
- name: nb_parametres | ||
type: INTEGER | ||
- name: categorie | ||
type: VARCHAR | ||
tests: | ||
- accepted_values: | ||
values: | ||
- metaux_lourds_pb | ||
- metaux_lourds_as | ||
- name: resultat | ||
description: "Interprétation du résultat en fonction des seuils sanitaires et des valeurs mesurées." | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- accepted_values: | ||
20k-P marked this conversation as resolved.
Show resolved
Hide resolved
|
||
values: | ||
- non_quantifie | ||
- sup_limite_qualite | ||
- sup_limite_qualite_2036 | ||
- sup_valeur_sanitaire | ||
- inf_limite_qualite | ||
- name: parametres_detectes | ||
description: "JSON contenant les paramètres détectés (valtraduite > 0) avec leurs valeurs correspondantes." | ||
type: JSON | ||
|
||
- name: int__resultats_metaux_lourds_commune_annuel | ||
description: Résultats des métaux lourds (Plomb et Arsenic) par commune pour la temporalité 'bilan_annuel' | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- inseecommune | ||
- annee | ||
- categorie | ||
columns: | ||
- name: inseecommune | ||
description: "Code INSEE de la commune" | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- name: annee | ||
description: "Année de prélèvement" | ||
type: smallint | ||
tests: | ||
- not_null | ||
- name: categorie | ||
description: "Catégorie du paramètre (pesticides, pfas, vcm, nitrates, etc.) selon la classification établie." | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- accepted_values: | ||
values: | ||
- metaux_lourds_pb | ||
- metaux_lourds_as | ||
- name: periode | ||
description: "Période du résultat" | ||
type: VARCHAR | ||
tests: | ||
- dbt_utils.expression_is_true: | ||
expression: "LIKE 'bilan_annuel%'" | ||
- name: nb_depassements | ||
type: INTEGER | ||
- name: nb_prelevements | ||
type: INTEGER | ||
- name: ratio | ||
description: Pourcentage de prélèvements qui dépassent la valeur sanitaire ou la limite de qualité | ||
type: FLOAT | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_values_to_be_between: | ||
min_value: 0 | ||
max_value: 1 | ||
|
||
- name: int__resultats_metaux_lourds_udi_annuel | ||
description: Résultats des métaux lourds (Plomb et Arsenic) par UDI pour la temporalité 'bilan_annuel' | ||
tests: | ||
- dbt_utils.unique_combination_of_columns: | ||
combination_of_columns: | ||
- cdreseau | ||
- annee | ||
- categorie | ||
columns: | ||
- name: cdreseau | ||
description: Code de l'installation (unité de distribution) | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- name: annee | ||
description: "Année de prélèvement" | ||
type: smallint | ||
tests: | ||
- not_null | ||
- name: categorie | ||
description: "Catégorie du paramètre (pesticides, pfas, vcm, nitrates, etc.) selon la classification établie." | ||
type: VARCHAR | ||
tests: | ||
- not_null | ||
- accepted_values: | ||
values: | ||
- metaux_lourds_pb | ||
- metaux_lourds_as | ||
- name: periode | ||
description: "Période du résultat" | ||
type: VARCHAR | ||
tests: | ||
- dbt_utils.expression_is_true: | ||
expression: "LIKE 'bilan_annuel%'" | ||
- name: nb_depassements | ||
type: INTEGER | ||
- name: nb_prelevements | ||
type: INTEGER | ||
- name: ratio | ||
description: Pourcentage de prélèvements qui dépassent la valeur sanitaire ou la limite de qualité | ||
type: FLOAT | ||
tests: | ||
- not_null | ||
- dbt_expectations.expect_column_values_to_be_between: | ||
min_value: 0 | ||
max_value: 1 |
66 changes: 66 additions & 0 deletions
66
dbt_/models/intermediate/metaux_lourds/int__resultats_metaux_lourds_commune_annuel.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
WITH | ||
metaux_lourds_prels AS ( | ||
-- Certains prélèvements ont plusieurs analyses pour la même substance | ||
-- Le SELECT DISTINCT ne dédoublonne pas ces cas là | ||
-- Donc il n'y a pas d'unicité sur referenceprel dans cetre requête | ||
SELECT DISTINCT | ||
de_partition AS annee, | ||
inseecommune, | ||
cdparametresiseeaux, | ||
valeur_sanitaire_1, | ||
limite_qualite, | ||
referenceprel, | ||
datetimeprel, | ||
valtraduite | ||
FROM | ||
{{ ref('int__resultats_udi_communes') }} | ||
WHERE | ||
cdparametresiseeaux IN ('PB', 'AS') | ||
) | ||
|
||
SELECT | ||
inseecommune, | ||
annee, | ||
CASE | ||
WHEN cdparametresiseeaux = 'PB' THEN 'metaux_lourds_pb' | ||
WHEN cdparametresiseeaux = 'AS' THEN 'metaux_lourds_as' | ||
END AS categorie, | ||
'bilan_annuel_' || annee AS periode, | ||
count( | ||
DISTINCT | ||
CASE | ||
WHEN | ||
cdparametresiseeaux = 'PB' | ||
AND valtraduite IS NOT NULL AND valtraduite >= limite_qualite | ||
THEN referenceprel | ||
WHEN | ||
cdparametresiseeaux = 'AS' | ||
AND valtraduite IS NOT NULL | ||
AND valtraduite >= valeur_sanitaire_1 | ||
THEN referenceprel | ||
END | ||
) AS nb_depassements, | ||
count(DISTINCT referenceprel) AS nb_prelevements, | ||
( | ||
count( | ||
DISTINCT | ||
CASE | ||
WHEN | ||
cdparametresiseeaux = 'PB' | ||
AND valtraduite IS NOT NULL | ||
AND valtraduite >= limite_qualite | ||
THEN referenceprel | ||
WHEN | ||
cdparametresiseeaux = 'AS' | ||
AND valtraduite IS NOT NULL | ||
AND valtraduite >= valeur_sanitaire_1 | ||
THEN referenceprel | ||
END | ||
)::float | ||
/ | ||
count(DISTINCT referenceprel)::float | ||
) AS ratio | ||
|
||
FROM metaux_lourds_prels | ||
|
||
GROUP BY inseecommune, annee, categorie |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.