Skip to content

Commit

Permalink
Merge branch 'main' into disable-invalid-account
Browse files Browse the repository at this point in the history
  • Loading branch information
loicguillois authored Dec 26, 2024
2 parents c074416 + 8146f6b commit 2b88271
Show file tree
Hide file tree
Showing 109 changed files with 6,163 additions and 2,069 deletions.
20 changes: 0 additions & 20 deletions .eslintignore

This file was deleted.

56 changes: 0 additions & 56 deletions .eslintrc.json

This file was deleted.

37 changes: 7 additions & 30 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
# dependencies
/node_modules
/frontend/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
/frontend/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.env
/.idea/
/frontend/.env
/dist/

# specific files
/server/routers
build/
dist/
frontend/src/components/_dsfr/
frontend/jest.polyfills.js
node_modules/
public/
tools/
4 changes: 3 additions & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ fileignoreconfig:
checksum: 9893602dd7197e44a7c361e44c31b5fb86a025227af95c02998a6857bd1a694b
- filename: server/.env.example
checksum: 4955533b2ba29ebc4a052e65ce2aab5b911ebf8e4b4eeecff50b5e83d1857c35
- filename: server/src/controllers/campaignController.ts
checksum: 73a5c525402f4354bc0ad41cf33aa17dadade2ba05608bfe9894b659b2a51246
- filename: server/src/controllers/housingExportController.ts
checksum: cb506387b49506b7ba0ed426001c221b80aff9f953e544d52c1c6d287741cf64
- filename: server/src/infra/database/scripts/010-load-sder-sded.sql
Expand All @@ -31,5 +33,5 @@ allowed_patterns:
- keyof
- \[key\]
- key=
- "key:"
- 'key:'
version: "1.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{% macro get_last_establishment_event_status(user_source, event_name, all_users=false) %}
(
SELECT
u.establishment_id,
events.new_status AS status,
events.event_status_label AS status_label,
events.new_occupancy AS occupancy,
events.new_sub_status,
events.created_at,
ROW_NUMBER() OVER (PARTITION BY u.establishment_id ORDER BY events.created_at DESC) AS row_num
FROM {{ ref('int_production_events') }} AS events
LEFT JOIN {{ ref('int_production_users') }} AS u ON events.created_by = u.id
WHERE
1=1
{% if event_name == 'suivi' %}
AND events.status_changed = TRUE
{% elif event_name == 'occupation' %}
AND events.occupancy_changed = TRUE
{% else %}
{% endif %}
{% if not all_users %}
AND events.user_source = '{{ user_source }}'
{% endif %}
)
{% endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% macro select_last_establishment_event(establishment_table, event_table, column_suffix) %}
(
SELECT
e.id AS establishment_id,
evt.status AS last_event_status_{{ column_suffix }},
evt.status_label AS last_event_status_label_{{ column_suffix }},
evt.occupancy AS last_event_occupancy_{{ column_suffix }},
evt.new_sub_status AS last_event_sub_status_label_{{ column_suffix }},
evt.created_at AS last_event_date_{{ column_suffix }}
FROM {{ establishment_table }} AS e
LEFT JOIN {{ event_table }} AS evt
ON evt.establishment_id = e.id AND evt.row_num = 1
)
{% endmacro %}
20 changes: 20 additions & 0 deletions analytics/dbt/models/intermediate/ff/int_ff_history_housing.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
WITH ff_history as (
SELECT ff_idlocal, 'ff-' || ff_millesime as file_year,
FROM {{ ref('int_ff_ext_2023') }}
UNION ALL
SELECT ff_idlocal, 'ff-' || ff_millesime as file_year,
FROM {{ ref('int_ff_ext_2022') }}
UNION ALL
SELECT ff_idlocal, 'ff-' || ff_millesime as file_year,
FROM {{ ref('int_ff_ext_2021') }}
UNION ALL
SELECT ff_idlocal, 'ff-' || ff_millesime as file_year,
FROM {{ ref('int_ff_ext_2020') }}
UNION ALL
SELECT ff_idlocal, 'ff-' || ff_millesime as file_year,
FROM {{ ref('int_ff_ext_2019') }})
SELECT
ff_idlocal as local_id,
listagg(file_year, ',') as file_years,
FROM ff_history lh
GROUP BY local_id
4 changes: 4 additions & 0 deletions analytics/dbt/models/intermediate/ff/int_ff_owners_dedup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ SELECT ff_owner_idpersonne,
max(ff_owner_birth_date) as ff_owner_birth_date,
max(ff_owner_lastname) as ff_owner_lastname,
max(ff_owner_firstname) as ff_owner_firstname,
max(ff_owner_firstnames) as ff_owner_firstnames,
max(ff_owner_birth_lastname) as ff_owner_birth_lastname,
max(ff_owner_city) as ff_owner_city,
max(ff_owner_fullname) as ff_owner_fullname,
max(ff_locprop) as ff_locprop,
max(ff_locproptxt) as ff_locproptxt,
max(ff_owner_category) as ff_owner_category,
max(ff_owner_category_text) as ff_owner_category_text
FROM {{ ref('stg_ff_owners') }}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
WITH
establishment_status_user_followup AS {{ get_last_establishment_event_status('user', 'suivi') }},
establishment_status_user_occupancy AS {{ get_last_establishment_event_status('user', "occupation") }},
last_establishment_status_user_followup AS {{ select_last_establishment_event(ref('int_production_establishments'), 'establishment_status_user_followup', 'user_followup') }},
last_establishment_status_user_occupancy AS {{ select_last_establishment_event(ref('int_production_establishments'), 'establishment_status_user_occupancy', 'user_occupancy') }}

SELECT
e.id AS establishment_id,
hsuf.last_event_status_user_followup,
hsuf.last_event_status_label_user_followup,
hsuf.last_event_date_user_followup,
hsuf.last_event_sub_status_label_user_followup,
hszo.last_event_occupancy_user_occupancy,
hszo.last_event_date_user_occupancy
FROM {{ ref('int_production_establishments') }} AS e
LEFT JOIN last_establishment_status_user_followup AS hsuf ON e.id = hsuf.establishment_id
LEFT JOIN last_establishment_status_user_occupancy AS hszo ON e.id = hszo.establishment_id
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ SELECT est.*,
WHEN est.kind IN ('SDED', 'SDER') THEN TRUE
ELSE FALSE
END AS covered_by_state_service
FROM {{ ref('stg_production_establishments') }} est

FROM {{ ref('stg_production_establishments') }} est
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

SELECT
ph.id as housing_id,
STRING_AGG(DISTINCT pel.establishment_id, ' | ') as establishment_ids,
ARRAY_AGG(DISTINCT pel.establishment_id) as establishment_ids_array,
CASE SUM(peu.user_number)
WHEN 0 THEN FALSE
ELSE TRUE
END as has_users
FROM {{ ref('int_production_housing') }} as ph
LEFT JOIN {{ ref('int_production_establishments_localities') }} as pel ON pel.geo_code = ph.geo_code
LEFT JOIN {{ ref('int_production_establishments_users') }} as peu ON peu.establishment_id = pel.establishment_id
GROUP BY housing_id
43 changes: 0 additions & 43 deletions analytics/dbt/models/marts/common/marts_common_cities.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,6 @@ SELECT
MIN(department_number) AS department_number,
MIN(region_name) AS region_name,
MIN(region_geojson_name) AS region_geojson_name,
SUM(vac_2024_moins_1an) AS total_vac_2024_moins_1an,
SUM(vac_2024_1an) AS total_vac_2024_1an,
SUM(vac_2024_2ans) AS total_vac_2024_2ans,
SUM(vac_2024_3ans) AS total_vac_2024_3ans,
SUM(vac_2024_4ans_plus) AS total_vac_2024_4ans_plus,
SUM(vac_2023_moins_1an) AS total_vac_2023_moins_1an,
SUM(vac_2023_1an) AS total_vac_2023_1an,
SUM(vac_2023_2ans) AS total_vac_2023_2ans,
SUM(vac_2023_3ans) AS total_vac_2023_3ans,
SUM(vac_2023_4ans_plus) AS total_vac_2023_4ans_plus,
SUM(vac_2023_total) AS total_vac_2023_total,
SUM(vac_2024_total) AS total_vac_2024_total,
SUM(vac_2024_plus_2ans) AS total_vac_2024_plus_2ans,
SUM(vac_2024_moins_2ans) AS total_vac_2024_moins_2ans,

SUM(vac_2020_moins_1an) AS total_vac_2020_moins_1an,
SUM(vac_2020_1an) AS total_vac_2020_1an,
SUM(vac_2020_2ans) AS total_vac_2020_2ans,
SUM(vac_2020_3ans) AS total_vac_2020_3ans,
SUM(vac_2020_4ans_plus) AS total_vac_2020_4ans_plus,
SUM(vac_2020_total) AS total_vac_2020_total,
SUM(ext_2023_gc.nombre_logements) AS nombre_logements_prives_2023,
SUM(ext_2020_gc.nombre_logements) AS nombre_logements_prives_2020,

100 * (SUM(vac_2024_plus_2ans) / SUM(ext_2023_gc.nombre_logements)) AS part_logement_vacants_plus_2ans_2024_parc_prive_2023, --Part des logements vacants >2 ans en 2024
100 * (SUM(vac_2024_moins_2ans) / SUM(ext_2023_gc.nombre_logements)) AS part_logement_vacants_moins_2ans_2024_parc_prive_2023, -- Part des logements ≤ 2 ans en 2023
100 * (SUM(vac_2023_total) / SUM(ext_2023_gc.nombre_logements)) AS part_logement_vacants_2023_parc_prive_2023,-- Part des logements vacants en 2024
100 * (SUM(vac_2024_total) / SUM(ext_2023_gc.nombre_logements)) AS part_logement_vacants_2024_parc_prive_2023,-- Part des logements vacants en 2023
MAX(ca1.is_in) AS tlv1, -- Prend 1 s'il y a au moins un arrondissement où la valeur est 1
MAX(ca2.is_in) AS tlv2, -- Idem
MAX(action_coeur_de_ville) AS action_coeur_de_ville,
Expand All @@ -47,16 +19,6 @@ SELECT
MAX(pig) AS pig,
MAX(cort.signed) as ort_signed,
MAX(cort.signed_at) as ort_signed_at,
MAX(cf.has_fusion) AS has_fusion,
MAX(cf.libelle_source) AS fusion_libelle_source,
MAX(cf.libelle_destination) AS fusion_libelle_destination,
MAX(cf.geo_code_source) AS fusion_geo_code_source,
MAX(cf.year) as fusion_date,
MAX(cs.has_scission) AS has_scission,
MAX(cs.libelle_source) AS scission_libelle_source,
MAX(cs.libelle_destination) AS scission_libelle_destination,
MAX(cs.geo_code_source) AS scission_geo_code_source,
MAX(cs.year) as scission_date,
MAX(UU_name) as uu_name,
MAX(UU_code) as uu_code,
MAX(EPCI_code) as epci_code,
Expand All @@ -75,12 +37,7 @@ LEFT JOIN {{ ref('int_common_article_232_1') }} ca1 ON ca1.geo_code = ccm.city_c
LEFT JOIN {{ ref('int_common_article_232_2') }} ca2 ON ca2.geo_code = ccm.city_code -- les données des articles 1 et 2 sont basé sur les codes insee des villes et non des arrondissements
LEFT JOIN {{ ref('int_common_ngeo_anct_cog_2023') }} ncac ON ncac.geo_code = cc.geo_code
LEFT JOIN {{ ref('int_common_table_appartenance') }} cta ON cta.geo_code = cc.geo_code
LEFT JOIN {{ ref('int_common_fusions') }} cf ON cf.geo_code_destination = cc.geo_code
LEFT JOIN {{ ref('int_common_scissions') }} cs ON cs.geo_code_destination = cc.geo_code
LEFT JOIN {{ ref('int_common_opah') }} co ON co.geo_code = cc.geo_code
LEFT JOIN {{ ref('int_lovac_geo_code') }} lgc ON lgc.geo_code = cc.geo_code
LEFT JOIN {{ ref('int_ff_ext_2023_geo_code') }} ext_2023_gc ON ext_2023_gc.geo_code = cc.geo_code
LEFT JOIN {{ ref('int_ff_ext_2020_geo_code') }} ext_2020_gc ON ext_2020_gc.geo_code = cc.geo_code
LEFT JOIN {{ ref('int_common_ort') }} cort ON ccm.city_code = cort.geo_code
LEFT JOIN {{ ref('int_production_geo_code_establishments') }} gce ON gce.geo_code = cc.geo_code
GROUP BY
Expand Down
54 changes: 54 additions & 0 deletions analytics/dbt/models/marts/import/import_gold_housing.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
WITH ff_data AS (
SELECT
ff_idlocal,
ff_jdatat AS last_mutation_date,
ff_dcapec2 AS cadastral_classification,
ff_dcntpa AS plot_area,
ff_geomloc AS geometry,
ff_ccthp AS occupancy,
ST_X(ST_Transform(ST_GeomFromWKB(FROM_HEX(ff_geomloc)), 'EPSG:2154', 'EPSG:4326')) AS latitude,
ST_Y(ST_Transform(ST_GeomFromWKB(FROM_HEX(ff_geomloc)), 'EPSG:2154', 'EPSG:4326')) AS longitude
FROM {{ ref('int_ff_ext_2023') }}
),
lovac_2024 AS (
SELECT
ff_idlocal,
ff_dcntpa AS plot_area,
ff_jdatat AS last_mutation_date,
dvf_datemut AS last_transaction_date,
dvf_valeurfonc AS last_transaction_value,
ffh_ccthp AS occupancy_history,
ban_latitude AS latitude,
ban_longitude AS longitude,
'lovac-2024' AS data_file_years
FROM {{ ref('int_lovac_fil_2024') }}
),
lovac_2023 AS (
SELECT
ff_idlocal,
ff_dcntpa AS plot_area,
ff_jdatat AS last_mutation_date,
dvf_datemut AS last_transaction_date,
dvf_valeurfonc AS last_transaction_value,
ffh_ccthp AS occupancy_history,
ban_latitude AS latitude,
ban_longitude AS longitude,
'lovac-2023' AS data_file_years
FROM {{ ref('int_lovac_fil_2023') }}
),
lovac_history AS (
SELECT * FROM {{ ref('int_lovac_history_housing') }}
)
SELECT
COALESCE(l24.ff_idlocal, l23.ff_idlocal, fd.ff_idlocal) AS local_id,
COALESCE(l24.plot_area, l23.plot_area, fd.plot_area) AS plot_area,
fd.cadastral_classification AS cadastral_classification,
COALESCE(l24.latitude, l23.latitude, fd.latitude) AS latitude,
COALESCE(l24.longitude, l23.longitude, fd.longitude) AS longitude,
COALESCE(l24.last_mutation_date, l23.last_mutation_date, fd.last_mutation_date) AS last_mutation_date,
COALESCE(l24.last_transaction_date, l23.last_transaction_date) AS last_transaction_date,
COALESCE(l24.last_transaction_value, l23.last_transaction_value) AS last_transaction_value,
COALESCE(l24.occupancy_history, l23.occupancy_history) AS occupancy_history
FROM ff_data fd
FULL OUTER JOIN lovac_2024 l24 ON fd.ff_idlocal = l24.ff_idlocal
FULL OUTER JOIN lovac_2023 l23 ON COALESCE(fd.ff_idlocal, l24.ff_idlocal) = l23.ff_idlocal
Loading

0 comments on commit 2b88271

Please sign in to comment.