Skip to content

Commit e7ebea5

Browse files
authored
Merge pull request #1154 from MTES-MCT/feat-count-by-statut
Compte les friches par statut
2 parents 92064df + 95935be commit e7ebea5

File tree

6 files changed

+27
-5
lines changed

6 files changed

+27
-5
lines changed

airflow/include/sql/sparte/macros/cartofriches/count_friche_by_value.sql

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ friche_data AS (
3535
SELECT
3636
site_id,
3737
{{ row_name }},
38-
surface
38+
surface,
39+
friche_statut as statut
3940
FROM {{ ref('friche') }}
4041
)
4142

@@ -45,7 +46,13 @@ SELECT
4546
l.land_name,
4647
v.{{ row_name }},
4748
COUNT(f.surface) AS friche_count,
48-
COALESCE(SUM(f.surface), 0) AS friche_surface
49+
COUNT(f.surface) filter (where f.statut = 'friche sans projet') AS friche_sans_projet_count,
50+
COUNT(f.surface) filter (where f.statut = 'friche avec projet') AS friche_avec_projet_count,
51+
COUNT(f.surface) filter (where f.statut = 'friche reconvertie') AS friche_reconvertie_count,
52+
COALESCE(SUM(f.surface), 0) AS friche_surface,
53+
COALESCE(SUM(f.surface) filter (where f.statut = 'friche sans projet'), 0) AS friche_sans_projet_surface,
54+
COALESCE(SUM(f.surface) filter (where f.statut = 'friche avec projet'), 0) AS friche_avec_projet_surface,
55+
COALESCE(SUM(f.surface) filter (where f.statut = 'friche reconvertie'), 0) AS friche_reconvertie_surface
4956
FROM
5057
land_base l
5158
CROSS JOIN
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{% macro standardize_friche_nature(friche_nature) %}
2+
CASE
3+
WHEN {{ friche_nature }} = 'MTE
4+
' THEN 'MTE'
5+
ELSE {{ friche_nature }}
6+
END
7+
{% endmacro %}

airflow/include/sql/sparte/models/cartofriches/friche.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ SELECT
6868
producteur_fk,
6969
source_nom,
7070
source_producteur,
71-
nature,
71+
{{ standardize_friche_nature('nature') }} as nature,
7272
source_contact,
7373
source_url,
7474
site_reconv_annee,

airflow/include/sql/sparte/models/cartofriches/friche_land.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ SELECT
2424
friche.friche_type_zone,
2525
friche.friche_type,
2626
friche.friche_surface_percentile_rank,
27-
friche.surface
27+
friche.surface,
28+
friche.source_producteur,
29+
friche.nature
2830
FROM
2931
{{ ref('friche') }}
3032
LEFT JOIN

airflow/include/sql/sparte/models/for_app/administration/for_app_land.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ SELECT
2020
land_ocsge_status.has_ocsge as has_ocsge,
2121
land_zonages.zonage_count > 0 as has_zonage,
2222
land_friche.friche_count > 0 as has_friche,
23+
land_friche.friche_source_producteurs as friche_source_producteurs,
24+
land_friche.friche_natures as friche_natures,
2325
land_millesimes.millesimes as millesimes,
2426
land_millesimes_by_index.millesimes_by_index as millesimes_by_index,
2527
land.child_land_types,
@@ -89,7 +91,9 @@ LEFT JOIN LATERAL (
8991
) land_ocsge_status ON true
9092
LEFT JOIN LATERAL (
9193
SELECT
92-
count(*) as friche_count
94+
count(*) as friche_count,
95+
array_agg(distinct source_producteur) as friche_source_producteurs,
96+
array_agg(distinct nature) as friche_natures
9397
FROM
9498
{{ ref('friche_land') }}
9599
WHERE

airflow/include/sql/sparte/models/for_app/friche/for_app_landfriche.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ SELECT
1919
friche.friche_type,
2020
friche.friche_surface_percentile_rank,
2121
friche.surface,
22+
friche.nature,
23+
friche.source_producteur,
2224
st_transform(st_pointonsurface(friche.geom), 4326) AS point_on_surface
2325

2426
FROM

0 commit comments

Comments
 (0)