Skip to content

Commit

Permalink
Merge pull request #739 from MTES-MCT/feat-conso-aggregation
Browse files Browse the repository at this point in the history
Fix des tests dbt de conso / pop
  • Loading branch information
alexisig authored Nov 18, 2024
2 parents a7378bd + 9623407 commit 5bcab87
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ SELECT
FROM
{{ ref('conso_epci_stats_commune') }} as epci_stats_commune
UNION
SELECT
'{{ var('COMMUNE') }}' as relevance_level,
'{{ var('NATION') }}' as land_type,
'{{ var('NATION') }}' as land_id,
{{ fields_to_query }}
FROM
{{ ref('conso_national_stats_commune') }} as epci_stats_commune
UNION
SELECT
'{{ var('DEPARTEMENT') }}' as relevance_level,
'{{ var('REGION') }}' as land_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ SELECT
FROM
{{ ref('pop_epci_stats_commune') }} as epci_stats_commune
UNION
SELECT
'{{ var('COMMUNE') }}' as relevance_level,
'{{ var('NATION') }}' as land_type,
'{{ var('NATION') }}' as land_id,
{{ fields_to_query }}
FROM
{{ ref('pop_national_stats_commune') }} as national_stats_commune
UNION
SELECT
'{{ var('DEPARTEMENT') }}' as relevance_level,
'{{ var('REGION') }}' as land_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ models:
- name: evolution_percent
data_tests:
- not_null
- name: evolution_median
data_tests:
- not_null
- name: evolution_avg
data_tests:
- not_null
- name: start_population
data_tests:
- not_null
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ FROM
LEFT JOIN
{{ ref('commune') }} as commune
ON commune.code = pop.code_commune
WHERE
commune.epci IS NOT NULL
GROUP BY
commune.epci,
from_year,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ models:
- name: epci
data_tests:
- not_null
- unique
- has_all_epcis
- relationships:
to: ref('epci')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{{ config(materialized='table') }}

SELECT
from_year,
to_year,
{{ sum_percent_median_avg('evolution', 'start_population') }}
FROM
{{ ref('period_flux_population_commune') }} as pop
LEFT JOIN
{{ ref('commune') }} as commune
ON commune.code = pop.code_commune
GROUP BY
from_year,
to_year
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{ config(materialized='table') }}

SELECT
from_year,
to_year,
{{ sum_percent_median_avg('total', 'commune.surface') }},
{{ sum_percent_median_avg('activite', 'commune.surface') }},
{{ sum_percent_median_avg('habitat', 'commune.surface') }},
{{ sum_percent_median_avg('mixte', 'commune.surface') }},
{{ sum_percent_median_avg('route', 'commune.surface') }},
{{ sum_percent_median_avg('ferroviaire', 'commune.surface') }},
{{ sum_percent_median_avg('inconnu', 'commune.surface') }}
FROM
{{ ref('period_consommation_commune') }} as conso
LEFT JOIN
{{ ref('commune') }} as commune
ON commune.code = conso.commune_code
GROUP BY
from_year,
to_year
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{{ config(materialized='table') }}

SELECT

from_year,
to_year,
{{ sum_percent_median_avg('total', 'epci.surface') }},
Expand Down

0 comments on commit 5bcab87

Please sign in to comment.