Skip to content

Commit

Permalink
feat(mes_aides): add permis velos from mes_aides source
Browse files Browse the repository at this point in the history
  • Loading branch information
hlecuyer committed Oct 24, 2024
1 parent 9e98106 commit b6787ec
Show file tree
Hide file tree
Showing 26 changed files with 965 additions and 229 deletions.
6 changes: 3 additions & 3 deletions pipeline/dags/dag_utils/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
"url": Variable.get("MES_AIDES_GARAGES_URL", None),
"token": Variable.get("MES_AIDES_AIRTABLE_KEY", None),
},
"aides": {
"filename": "aides.json",
"url": Variable.get("MES_AIDES_AIDES_URL", None),
"permis_velo": {
"filename": "permis_velo.json",
"url": Variable.get("MES_AIDES_PERMIS_VELO_URL", None),
"token": Variable.get("MES_AIDES_AIRTABLE_KEY", None),
},
},
Expand Down
3 changes: 3 additions & 0 deletions pipeline/dbt/models/_sources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ sources:
- name: garages
meta:
kind: structure
- name: permis_velo
meta:
kind: structure
- name: aides
meta:
kind: service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
-- depends_on: {{ ref('stg_mediation_numerique__structures') }}
-- depends_on: {{ ref('int_mediation_numerique__services') }}
-- depends_on: {{ ref('int_mediation_numerique__structures') }}
-- depends_on: {{ ref('stg_mes_aides__aides') }}
-- depends_on: {{ ref('stg_mes_aides__permis_velo') }}
-- depends_on: {{ ref('stg_mes_aides__garages') }}
-- depends_on: {{ ref('int_mes_aides__services') }}
-- depends_on: {{ ref('int_mes_aides__structures') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@ models:
- 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
data_tests:
- check_structure:
Expand Down Expand Up @@ -65,3 +54,13 @@ models:
- relationships:
to: ref('int_mes_aides__adresses')
field: id
- 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: 2

models:
- name: int_mes_aides__garages__adresses
data_tests:
- check_adresse:
config:
severity: warn
columns:
- name: id
data_tests:
- unique
- not_null
- dbt_utils.not_empty_string

- name: int_mes_aides__garages__structures
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__garages__adresses')
field: id

- name: int_mes_aides__garages__services
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__garages__structures')
field: id
- name: adresse_id
data_tests:
- not_null
- relationships:
to: ref('int_mes_aides__garages__adresses')
field: id
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
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",
NULL::DATE AS "date_suspension",
NULL AS "formulaire_en_ligne",
'{{ check_structure_str }}' AS "frais_autres",
(UUID(MD5(garages.id || COALESCE(service_types_by_garage.service_type, ''))))::TEXT AS "id",
NULL::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",
NULL::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",
NULL::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
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
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
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
{{ dbt_utils.union_relations(
relations=[ref('int_mes_aides__garages__adresses'), ref('int_mes_aides__permis_velo__adresses')]
) }}
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
WITH structure_contacts AS (
SELECT
id AS "id",
_di_source_id AS "source",
email AS "courriel",
telephone AS "telephone",
NULL AS "contact_nom_prenom",
'mes-aides:garages:' || id AS "contact_uid"
'mes-aides:garages:' || id AS contact_uid
FROM {{ ref('stg_mes_aides__garages') }}
WHERE email IS NOT NULL
),

service_contacts AS (
SELECT
id AS "id",
_di_source_id AS "source",
email AS "courriel",
telephone AS "telephone",
NULL AS "contact_nom_prenom",
'mes-aides:aides:' || id AS "contact_uid"
FROM {{ ref('stg_mes_aides__aides') }}
WHERE email IS NOT NULL
contact_email AS "courriel",
'mes-aides:aides:' || id AS contact_uid
FROM {{ ref('stg_mes_aides__permis_velo') }}
WHERE contact_email IS NOT NULL
),

final AS (
Expand Down
Loading

0 comments on commit b6787ec

Please sign in to comment.