-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/nb_menages #197
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
base: main
Are you sure you want to change the base?
Feat/nb_menages #197
Changes from all commits
53b3b6a
945112a
a97df83
774c2e8
f5e8fa5
10c8286
4f58c42
97eefba
6ac5e95
b5ff88b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,16 @@ | ||
| {{ config( | ||
| tags = ['bronze', 'population'], | ||
| alias='vw_population_menages_2021' | ||
| alias='vw_population_nb_menages' | ||
| ) | ||
| }} | ||
|
|
||
| select | ||
| {{ dbt_utils.star(from=source('bronze', 'population_menages_td_men1_2021')) }} | ||
| from {{ source('bronze', 'population_menages_td_men1_2021') }} | ||
| {% set local_year = '2021' %} | ||
|
|
||
| with population_nb_menages as | ||
| ( | ||
| select {{ dbt_utils.star(from=source('bronze', 'population_menages_td_men1_2021')) }}, | ||
| '{{ local_year }}' as "year" | ||
| from {{ source('bronze', 'population_menages_td_men1_2021') }} | ||
| ) | ||
|
|
||
| select * from population_nb_menages | ||
ThomGram marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -570,3 +570,23 @@ models: | |
| - name: densite | ||
| description: densité de population, nombre d'habitants au kilomètre carré. | ||
| data_type: numeric | ||
|
|
||
|
|
||
| - name: gold_population_nb_menages | ||
| description: Table contenant le nombre de ménages et le nombre moyen d'occupants par ménage à tous les niveaux géographiques (commune, département, région). Union des tables silver_population_menages, silver_population_menages_departement et silver_population_menages_region. | ||
| columns: | ||
| - name: codgeo | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ajouter l'année du codegeo si suggestion acceptée |
||
| description: Code géographique selon le niveau (Code INSEE commune, Code département, ou 'reg' + Code région) | ||
| data_type: text | ||
| - name: year | ||
| description: Année de référence des données du recensement | ||
| data_type: numeric | ||
| - name: nb_menages | ||
| description: Nombre total de ménages dans la zone géographique | ||
| data_type: numeric | ||
| - name: nb_occ_moyen | ||
| description: Nombre moyen d'occupants par ménage dans la zone géographique | ||
| data_type: numeric | ||
| - name: niveau_geo | ||
| description: Niveau géographique (COM pour commune, DEP pour département, REG pour région) | ||
| data_type: text | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| {{ config( | ||
| tags = ['gold', 'population', 'nb_menages'], | ||
| ) | ||
| }} | ||
|
|
||
| select * from {{ref('silver_population_menages')}} | ||
| union all | ||
| select * from {{ref('silver_population_menages_departement')}} | ||
| union all | ||
| select * from {{ref('silver_population_menages_region')}} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| {{ config( | ||
| tags = ['silver', 'population'], | ||
| alias='silver_population_menages' | ||
| ) | ||
| }} | ||
|
|
||
| with population_nb_menages as ( | ||
| select | ||
| coalesce(passage."Code Courant Officiel", pop."CODGEO") as codgeo, | ||
| pop.year, | ||
| SUM(pop."NB") as nb_menages, | ||
| SUM(pop."NPERC" * pop."NB") / nullif(SUM(pop."NB"),0) as nb_occ_Moyen, | ||
| 'COM' as niveau_geo | ||
| from {{ ref('population_menages_2021') }} pop | ||
| left join {{ ref('geocodes_passage_annuel') }} passage | ||
| on pop."CODGEO" = passage."Ancien Code Officiel" | ||
| and passage."Niveau" = 'COM' | ||
| where pop."NIVGEO" = 'COM' | ||
| group by coalesce(passage."Code Courant Officiel", pop."CODGEO"), pop.year | ||
| ) | ||
|
|
||
| select * from population_nb_menages |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| {{ config( | ||
| tags = ['silver', 'population'], | ||
| alias='silver_population_menages_departement' | ||
| ) | ||
| }} | ||
|
|
||
| with population_nb_menages_dept as ( | ||
| select | ||
| geo."CODDEP" as codgeo, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je rajouterais l'année du code geo ici par sécurité, vu qu'ils changent annuellement - en plus du code et du type.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bonne idée, mais je ne trouve pas l'info de l'année du codgeo... je creuse |
||
| year, | ||
| SUM(pop."NB") as nb_menages, | ||
| SUM(pop."NPERC" * pop."NB") / nullif(SUM(pop."NB"),0) as nb_occ_Moyen, | ||
| 'DEP' as niveau_geo | ||
| from {{ ref('population_menages_2021') }} pop | ||
| inner join {{ ref('com_dep_reg') }} geo on pop."CODGEO" = geo."CODGEO" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pour pousser le raisonnement il faudrait aussi faire la jointure sur l'année du codegeo - en l'ajoutant aussi dans
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Les codgeo de com_dep_reg sont mis à jour depuis l'api Melodi, je crois que l'api ne renvoit pas de champs concernant l'année malheureusement.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On peut ajouter un test pour s'assurer que toutes les communes ont bien un codgeo dans com_dep_reg |
||
| where pop."NIVGEO" = 'COM' | ||
| group by geo."CODDEP", year | ||
| ) | ||
|
|
||
| select * from population_nb_menages_dept | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| {{ config( | ||
| tags = ['silver', 'population'], | ||
| alias='silver_population_menages_region' | ||
| ) | ||
| }} | ||
|
|
||
| with population_nb_menages_reg as ( | ||
| select | ||
| 'reg' || geo."CODREG" as codgeo, | ||
| year, | ||
| SUM(pop."NB") as nb_menages, | ||
| SUM(pop."NPERC" * pop."NB") / nullif(SUM(pop."NB"),0) as nb_occ_Moyen, | ||
| 'REG' as niveau_geo | ||
| from {{ ref('population_menages_2021') }} pop | ||
| inner join {{ ref('com_dep_reg') }} geo on pop."CODGEO" = geo."CODGEO" | ||
| where pop."NIVGEO" = 'COM' | ||
| group by geo."CODREG", year | ||
| ) | ||
|
|
||
| select * from population_nb_menages_reg |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.