generated from dataforgoodfr/d4g-project-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Feat/165 population densite #199
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
4 commits
Select commit
Hold shift + click to select a range
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
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
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
21 changes: 21 additions & 0 deletions
21
dbt_odis/models/bronze/population_population_superficie.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,21 @@ | ||
| {{ config( | ||
| tags = ['bronze', 'population'], | ||
| alias = 'vw_population_population_superficie' | ||
| ) }} | ||
|
|
||
| with population_superficie as | ||
| ( | ||
| select | ||
| id, | ||
| (data::jsonb)->'dimensions'->>'GEO'::text as geo, | ||
| (data::jsonb)->'dimensions'->>'OCS'::text as ocs, | ||
| (data::jsonb)->'dimensions'->>'FREQ'::text as freq, | ||
| (data::jsonb)->'dimensions'->>'RP_MEASURE'::text as rp_measure, | ||
| (data::jsonb)->'dimensions'->>'TIME_PERIOD'::text as time_period, | ||
| (data::jsonb)->'measures'->'OBS_VALUE_NIVEAU'->>'value'::text as measure_value | ||
|
|
||
| from {{ source('bronze', 'population_population_superficie') }} | ||
|
|
||
| ) | ||
|
|
||
| select * from population_superficie |
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
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,19 @@ | ||
| {{ config( | ||
| tags=['gold', 'population'], | ||
| alias='vw_population_densite' | ||
| ) }} | ||
|
|
||
| with densite as ( | ||
| select | ||
| -- ajout du prefix 'reg' pour les régions, pour les differencier des DEP | ||
| case | ||
| when codegeo_type = 'REG' then concat('reg', codegeo) else codegeo end | ||
| as codegeo, | ||
| "year", | ||
| -- densite au km2, mais superficie exprimee en hectares | ||
| cast(round(population / nullif(superficie * 1e-2, 0), 0) as int) as densite | ||
| from {{ ref('stg_population_population_superficie') }} | ||
| where "year" = '2022' | ||
| ) | ||
|
|
||
| select * from densite |
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
28 changes: 28 additions & 0 deletions
28
dbt_odis/models/silver/stg_population_population_superficie.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,28 @@ | ||
| {{ config( | ||
| tags=['silver', 'population'], | ||
| alias='vw_population_population_superficie_stg', | ||
| materialized='view' | ||
| ) }} | ||
|
|
||
| with pivot_pop_sup as | ||
| ( | ||
| select | ||
| split_part("geo", '-', 1) as codegeo_year, | ||
| split_part("geo", '-', 2) as codegeo_type, -- REG, COM, DEP, etc. | ||
| split_part("geo", '-', 3) as codegeo, | ||
| time_period as "year", | ||
| -- pivot population et superficie | ||
| cast(max(case when rp_measure = 'POP' then split_part(measure_value, '.', 1) end) as int) as population, | ||
| cast(max(case when rp_measure = 'SUP' then split_part(measure_value, '.', 1) end) as int) as superficie | ||
| from {{ ref('population_population_superficie') }} | ||
| -- filtres presents dans datasource.yml, mais explicites ici pour clarte | ||
| where split_part("geo", '-', 2) in ('COM', 'REG', 'DEP') | ||
| and ocs = '_T' | ||
| group by | ||
| split_part(geo, '-', 1), | ||
| split_part(geo, '-', 2), | ||
| split_part(geo, '-', 3), | ||
| time_period | ||
| ) | ||
|
|
||
| select * from pivot_pop_sup |
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.