-
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.
feat(mes_aides): add permis velos from mes_aides source
- Loading branch information
Showing
19 changed files
with
745 additions
and
143 deletions.
There are no files selected for viewing
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
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
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
67 changes: 67 additions & 0 deletions
67
pipeline/dbt/models/intermediate/sources/mes_aides/garage/_mes_aides_garage__models.yml
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,67 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: int_mes_aides__adresses_garage | ||
data_tests: | ||
- check_adresse: | ||
config: | ||
severity: warn | ||
columns: | ||
- name: id | ||
data_tests: | ||
- unique | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: int_mes_aides__contacts | ||
columns: | ||
- name: contact_uid | ||
data_tests: | ||
- unique | ||
- not_null | ||
- name: courriel | ||
data_tests: | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
|
||
- name: int_mes_aides__structures_garages | ||
data_tests: | ||
- check_structure: | ||
config: | ||
severity: warn | ||
columns: | ||
- name: id | ||
data_tests: | ||
- unique | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
- name: adresse_id | ||
data_tests: | ||
- not_null | ||
- relationships: | ||
to: ref('int_mes_aides__adresses_garage') | ||
field: id | ||
|
||
- name: int_mes_aides__services_garage | ||
data_tests: | ||
- check_service: | ||
config: | ||
severity: warn | ||
columns: | ||
- name: id | ||
data_tests: | ||
- unique | ||
- not_null | ||
- dbt_utils.not_empty_string | ||
- name: structure_id | ||
data_tests: | ||
- not_null | ||
- relationships: | ||
to: ref('int_mes_aides__structures_garage') | ||
field: id | ||
- name: adresse_id | ||
data_tests: | ||
- not_null | ||
- relationships: | ||
to: ref('int_mes_aides__adresses_garage') | ||
field: id |
19 changes: 19 additions & 0 deletions
19
pipeline/dbt/models/intermediate/sources/mes_aides/garage/int_mes_aides__adresses_garage.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,19 @@ | ||
WITH garages AS ( | ||
SELECT * FROM {{ ref('stg_mes_aides__garages') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
id AS "id", | ||
ville_nom AS "commune", | ||
code_postal AS "code_postal", | ||
code_insee AS "code_insee", | ||
adresse AS "adresse", | ||
NULL AS "complement_adresse", | ||
longitude AS "longitude", | ||
latitude AS "latitude", | ||
_di_source_id AS "source" | ||
FROM garages | ||
) | ||
|
||
SELECT * FROM final |
File renamed without changes.
103 changes: 103 additions & 0 deletions
103
pipeline/dbt/models/intermediate/sources/mes_aides/garage/int_mes_aides__services_garage.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,103 @@ | ||
{% set check_structure_str = "Veuillez vérifier sur le site internet de la structure" %} | ||
|
||
WITH garages AS ( | ||
SELECT * FROM {{ ref('stg_mes_aides__garages') }} | ||
), | ||
|
||
service_types_by_garage AS ( | ||
SELECT | ||
garages.id, | ||
service_type | ||
FROM garages, | ||
UNNEST(garages.services) AS service_type | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
garages.id AS "adresse_id", | ||
TRUE AS "contact_public", | ||
TRUE AS "cumulable", | ||
garages.cree_le AS "date_creation", | ||
garages.modifie_le AS "date_maj", | ||
CAST(NULL AS DATE) AS "date_suspension", | ||
NULL AS "formulaire_en_ligne", | ||
'{{ check_structure_str }}' AS "frais_autres", | ||
CAST(UUID(MD5(garages.id || COALESCE(service_types_by_garage.service_type, ''))) AS TEXT) AS "id", | ||
CAST(NULL AS TEXT []) AS "justificatifs", | ||
'https://mes-aides.francetravail.fr/transport-et-mobilite/garages-solidaires' AS "lien_source", | ||
ARRAY['en-presentiel'] AS "modes_accueil", | ||
ARRAY_REMOVE( | ||
ARRAY[ | ||
CASE WHEN garages.telephone IS NOT NULL THEN 'telephoner' END, | ||
CASE WHEN garages.email IS NOT NULL THEN 'envoyer-un-mail' END | ||
], | ||
NULL | ||
) AS "modes_orientation_accompagnateur", | ||
CASE | ||
WHEN | ||
garages.telephone IS NULL | ||
AND garages.email IS NULL | ||
THEN '{{ check_structure_str }}' | ||
END AS "modes_orientation_accompagnateur_autres", | ||
ARRAY_REMOVE( | ||
ARRAY[ | ||
'se-presenter', | ||
CASE WHEN garages.telephone IS NOT NULL THEN 'telephoner' END, | ||
CASE WHEN garages.email IS NOT NULL THEN 'envoyer-un-mail' END | ||
], | ||
NULL | ||
) AS "modes_orientation_beneficiaire", | ||
NULL AS "modes_orientation_beneficiaire_autres", | ||
FORMAT( | ||
'%s de %s', | ||
COALESCE(service_types_by_garage.service_type, 'Réparation, vente et location'), | ||
LOWER(COALESCE(NULLIF(ARRAY_TO_STRING(garages.types_de_vehicule, ', '), ''), 'véhicule')) | ||
) AS "nom", | ||
FORMAT( | ||
'%s de %s à tarif solidaire pour les personnes en difficulté, et selon leur situation', | ||
COALESCE(service_types_by_garage.service_type, 'Réparation, vente et location'), | ||
LOWER(COALESCE(NULLIF(ARRAY_TO_STRING(garages.types_de_vehicule, ', '), ''), 'véhicule')) | ||
) AS "presentation_resume", | ||
NULL AS "presentation_detail", | ||
NULL AS "prise_rdv", | ||
CAST(NULL AS TEXT []) AS "profils", | ||
NULL AS "recurrence", | ||
garages._di_source_id AS "source", | ||
garages.id AS "structure_id", | ||
ARRAY_REMOVE( | ||
ARRAY[ | ||
CASE service_types_by_garage.service_type | ||
WHEN 'Achat' THEN 'mobilite--acheter-un-vehicule-motorise' | ||
WHEN 'Location' THEN 'mobilite--louer-un-vehicule' | ||
WHEN 'Réparation' THEN 'mobilite--entretenir-reparer-son-vehicule' | ||
ELSE 'mobilite' | ||
END, | ||
CASE | ||
WHEN | ||
service_types_by_garage.service_type = 'Achat' | ||
AND 'Vélo' = ANY(garages.types_de_vehicule) | ||
THEN 'mobilite--acheter-un-velo' | ||
END | ||
], | ||
NULL | ||
) AS "thematiques", | ||
ARRAY['aide-materielle', 'aide-financiere'] AS "types", | ||
CASE LEFT(garages.code_insee, 2) | ||
WHEN '97' THEN LEFT(garages.code_insee, 3) | ||
ELSE LEFT(garages.code_insee, 2) | ||
END AS "zone_diffusion_code", | ||
NULL AS "zone_diffusion_nom", | ||
'departement' AS "zone_diffusion_type", | ||
garages.criteres_eligibilite AS "pre_requis", | ||
NULL AS "contact_nom_prenom", | ||
garages.email AS "courriel", | ||
garages.telephone AS "telephone", | ||
CAST(NULL AS TEXT []) AS "frais", | ||
NULL AS "page_web" | ||
FROM garages | ||
LEFT JOIN service_types_by_garage ON garages.id = service_types_by_garage.id | ||
WHERE | ||
garages.en_ligne | ||
) | ||
|
||
SELECT * FROM final |
32 changes: 32 additions & 0 deletions
32
...ine/dbt/models/intermediate/sources/mes_aides/garage/int_mes_aides__structures_garage.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,32 @@ | ||
WITH garages AS ( | ||
SELECT * FROM {{ ref('stg_mes_aides__garages') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
id AS "id", | ||
id AS "adresse_id", | ||
siret AS "siret", | ||
NULL::BOOLEAN AS "antenne", | ||
NULL AS "rna", | ||
nom AS "nom", | ||
telephone AS "telephone", | ||
email AS "courriel", | ||
url AS "site_web", | ||
_di_source_id AS "source", | ||
NULL AS "lien_source", | ||
NULL AS "horaires_ouverture", | ||
NULL AS "accessibilite", | ||
NULL::TEXT [] AS "labels_nationaux", | ||
NULL::TEXT [] AS "labels_autres", | ||
NULL AS "typologie", | ||
NULL AS "presentation_resume", | ||
NULL AS "presentation_detail", | ||
modifie_le::DATE AS "date_maj", | ||
ARRAY['mobilite'] AS "thematiques" | ||
FROM garages | ||
WHERE | ||
en_ligne | ||
) | ||
|
||
SELECT * FROM final |
40 changes: 28 additions & 12 deletions
40
pipeline/dbt/models/intermediate/sources/mes_aides/int_mes_aides__adresses.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 |
---|---|---|
@@ -1,19 +1,35 @@ | ||
WITH garages AS ( | ||
SELECT * FROM {{ ref('stg_mes_aides__garages') }} | ||
WITH adresses_garage AS ( | ||
SELECT * FROM {{ ref('int_mes_aides__adresses_garage') }} | ||
), | ||
|
||
adresses_permis_velo AS ( | ||
SELECT * FROM {{ ref('int_mes_aides__adresses_permis_velo') }} | ||
), | ||
|
||
final AS ( | ||
SELECT | ||
id AS "id", | ||
ville_nom AS "commune", | ||
code_postal AS "code_postal", | ||
code_insee AS "code_insee", | ||
adresse AS "adresse", | ||
NULL AS "complement_adresse", | ||
longitude AS "longitude", | ||
latitude AS "latitude", | ||
_di_source_id AS "source" | ||
FROM garages | ||
adresses_garage.id, | ||
adresses_garage.commune, | ||
adresses_garage.code_insee, | ||
adresses_garage.longitude, | ||
adresses_garage.latitude, | ||
adresses_garage.source, | ||
adresses_garage.code_postal, | ||
adresses_garage.adresse, | ||
adresses_garage.complement_adresse | ||
FROM adresses_garage | ||
UNION ALL | ||
SELECT | ||
adresses_permis_velo.id, | ||
adresses_permis_velo.commune, | ||
adresses_permis_velo.code_insee, | ||
adresses_permis_velo.longitude, | ||
adresses_permis_velo.latitude, | ||
adresses_permis_velo.source, | ||
adresses_permis_velo.code_postal, | ||
adresses_permis_velo.adresse, | ||
adresses_permis_velo.complement_adresse | ||
FROM adresses_permis_velo | ||
) | ||
|
||
SELECT * FROM final |
Oops, something went wrong.