-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
118 additions
and
36 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
airflow/include/sql/sparte/macros/insee/merge_flux_population_by_admin_level.sql
This file contains 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,37 @@ | ||
{% macro merge_flux_population_by_admin_level( | ||
group_by_column, | ||
code_name | ||
) %} | ||
SELECT | ||
{{ group_by_column }} as {{ code_name }}, | ||
{% set last_available_year = 2020 %} | ||
{% set first_available_year = 2009 %} | ||
{% set ns = namespace(continued=false) %} | ||
{% for start_year in range(2009, last_available_year + 1) %} | ||
{% for end_year in range(2009, last_available_year + 1) -%} | ||
{% if start_year > end_year -%} | ||
{% set ns.continued = true %} | ||
{% continue %} | ||
{% else %} | ||
{% set ns.continued = false %} | ||
{% endif %} | ||
sum(population_{{ start_year }}_{{ end_year + 1 }}) | ||
as population_{{ start_year }}_{{ end_year + 1 }} | ||
{% if not loop.last and not ns.continued -%}, {% endif %} | ||
{% endfor %} {% if not loop.last and not ns.continued -%}, {% endif %} | ||
{% endfor %} | ||
FROM | ||
{{ ref('flux_population') }} as flux_population | ||
LEFT JOIN | ||
{{ ref('commune') }} | ||
ON commune.code = flux_population.code_commune | ||
LEFT JOIN | ||
{{ ref('scot_communes') }} as scot_communes | ||
ON commune.code = scot_communes.commune_code | ||
-- la condition suivante est nécessaire car un grand nombre de communes ne fait pas partie d'un SCOT, | ||
-- et plus rarement certaines communes ne font pas partie d'un EPCI | ||
WHERE | ||
{{ group_by_column }} IS NOT NULL | ||
GROUP BY | ||
{{ group_by_column }} | ||
{% endmacro %} |
8 changes: 8 additions & 0 deletions
8
airflow/include/sql/sparte/models/insee/aggregated/flux_population_departements.sql
This file contains 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,8 @@ | ||
{{ config(materialized='table') }} | ||
|
||
{{ | ||
merge_flux_population_by_admin_level( | ||
'departement', | ||
'code_departement' | ||
) | ||
}} |
8 changes: 8 additions & 0 deletions
8
airflow/include/sql/sparte/models/insee/aggregated/flux_population_epcis.sql
This file contains 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,8 @@ | ||
{{ config(materialized='table') }} | ||
|
||
{{ | ||
merge_flux_population_by_admin_level( | ||
'epci', | ||
'code_epci' | ||
) | ||
}} |
8 changes: 8 additions & 0 deletions
8
airflow/include/sql/sparte/models/insee/aggregated/flux_population_regions.sql
This file contains 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,8 @@ | ||
{{ config(materialized='table') }} | ||
|
||
{{ | ||
merge_flux_population_by_admin_level( | ||
'region', | ||
'code_region' | ||
) | ||
}} |
8 changes: 8 additions & 0 deletions
8
airflow/include/sql/sparte/models/insee/aggregated/flux_population_scots.sql
This file contains 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,8 @@ | ||
{{ config(materialized='table') }} | ||
|
||
{{ | ||
merge_flux_population_by_admin_level( | ||
'id_scot', | ||
'code_scot' | ||
) | ||
}} |
49 changes: 49 additions & 0 deletions
49
airflow/include/sql/sparte/models/insee/flux_population.sql
This file contains 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,49 @@ | ||
{{ | ||
config( | ||
materialized='table', | ||
indexes=[{'columns': ['code_commune'], 'type': 'btree'}] | ||
) | ||
}} | ||
with flux as ( | ||
SELECT | ||
code_commune, | ||
(population_2010 - population_2009) as population_2009_2010, | ||
(population_2011 - population_2010) as population_2010_2011, | ||
(population_2012 - population_2011) as population_2011_2012, | ||
(population_2013 - population_2012) as population_2012_2013, | ||
(population_2014 - population_2013) as population_2013_2014, | ||
(population_2015 - population_2014) as population_2014_2015, | ||
(population_2016 - population_2015) as population_2015_2016, | ||
(population_2017 - population_2016) as population_2016_2017, | ||
(population_2018 - population_2017) as population_2017_2018, | ||
(population_2019 - population_2018) as population_2018_2019, | ||
(population_2020 - population_2019) as population_2019_2020, | ||
(population_2021 - population_2020) as population_2020_2021 | ||
FROM | ||
{{ ref('population_cog_2024') }} | ||
) | ||
SELECT | ||
code_commune, | ||
{% set last_available_year = 2020 %} | ||
{% set first_available_year = 2009 %} | ||
{% set ns = namespace(continued=false) %} | ||
{% for start_year in range(2009, last_available_year + 1) %} | ||
{% for end_year in range(2009, last_available_year + 1) -%} | ||
{% if start_year > end_year -%} | ||
{% set ns.continued = true %} | ||
{% continue %} | ||
{% else %} | ||
{% set ns.continued = false %} | ||
{% endif %} | ||
( | ||
{% for first_year in range(start_year, end_year + 1) -%} | ||
{% set next_year = first_year + 1 -%} | ||
population_{{ first_year }}_{{ next_year }} | ||
{% if not loop.last -%} + {% endif %} | ||
{% endfor %} | ||
) as population_{{ start_year }}_{{ end_year + 1 }} | ||
{% if not loop.last and not ns.continued -%}, {% endif %} | ||
{% endfor %} {% if not loop.last and not ns.continued -%}, {% endif %} | ||
{% endfor %} | ||
FROM | ||
flux |
36 changes: 0 additions & 36 deletions
36
airflow/include/sql/sparte/models/insee/intersected/conso_pop_communes_of_epci.sql
This file was deleted.
Oops, something went wrong.