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 Sep 18, 2024
1 parent 2352e34 commit 61806d9
Show file tree
Hide file tree
Showing 19 changed files with 745 additions and 143 deletions.
5 changes: 5 additions & 0 deletions pipeline/dags/dag_utils/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
"url": Variable.get("MES_AIDES_AIDES_URL", None),
"token": Variable.get("MES_AIDES_AIRTABLE_KEY", None),
},
"permis_velo": {
"filename": "aides.json",
"url": Variable.get("MES_AIDES_PERMIS_VELO_URL", None),
"token": Variable.get("MES_AIDES_AIRTABLE_KEY", None),
},
},
},
"siao": {
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 @@ -75,6 +75,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 @@ -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
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
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",
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
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,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
Loading

0 comments on commit 61806d9

Please sign in to comment.