Skip to content

Commit

Permalink
chore(pipeline): clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vmttn committed May 23, 2024
1 parent 947ba20 commit b00db91
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 159 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ final AS (
WHEN 'CCAS' THEN 'CCAS'
WHEN 'MAIRIE' THEN 'MUNI'
END AS "typologie",
CASE LENGTH(presentation_detail) <= 280
WHEN TRUE THEN presentation_detail
WHEN FALSE THEN LEFT(presentation_detail, 279) || ''
CASE
WHEN LENGTH(presentation_detail) <= 280 THEN presentation_detail
ELSE LEFT(presentation_detail, 279) || ''
END AS "presentation_resume",
CASE LENGTH(presentation_detail) <= 280
WHEN TRUE THEN NULL
WHEN FALSE THEN presentation_detail
CASE
WHEN LENGTH(presentation_detail) <= 280 THEN NULL
ELSE presentation_detail
END AS "presentation_detail"
FROM organisations
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ WITH creches AS (

final AS (
SELECT
id AS "id",
id AS "adresse_id",
NULL AS "siret",
NULL::BOOLEAN AS "antenne",
NULL AS "rna",
nom AS "nom",
telephone AS "telephone",
mail AS "courriel",
details__website AS "site_web",
_di_source_id AS "source",
'https://monenfant.fr/que-recherchez-vous/' || result_id AS "lien_source",
details__infos_pratiques__jour_horaire AS "horaires_ouverture",
NULL AS "accessibilite",
NULL::TEXT [] AS "labels_nationaux",
NULL::TEXT [] AS "labels_autres",
CASE WHEN avip THEN 'AVIP' END AS "typologie",
id AS "id",
id AS "adresse_id",
NULL AS "siret",
NULL::BOOLEAN AS "antenne",
NULL AS "rna",
nom AS "nom",
telephone AS "telephone",
mail AS "courriel",
details__website AS "site_web",
_di_source_id AS "source",
'https://monenfant.fr/que-recherchez-vous/' || result_id AS "lien_source",
details__infos_pratiques__jour_horaire AS "horaires_ouverture",
NULL AS "accessibilite",
NULL::TEXT [] AS "labels_nationaux",
NULL::TEXT [] AS "labels_autres",
CASE WHEN avip THEN 'AVIP' END AS "typologie",
{{ truncate_text("details__presentation__structure_projet") }} AS "presentation_resume",
details__presentation__structure_projet AS "presentation_detail",
derniere_modif_date AS "date_maj",
ARRAY['famille--garde-denfants'] AS "thematiques"
details__presentation__structure_projet AS "presentation_detail",
derniere_modif_date AS "date_maj",
ARRAY['famille--garde-denfants'] AS "thematiques"
FROM creches
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ final AS (
WHERE ressources_partenariales.type_res_part = di_thematique_by_odspep_type_res_part.type_res_part
)::TEXT [] AS "thematiques",
CONCAT(id_res, '_', zone_diffusion_unique_code) AS "id",
CASE LENGTH(service_description) <= 280
WHEN TRUE THEN service_description
WHEN FALSE THEN LEFT(service_description, 279) || ''
CASE
WHEN LENGTH(service_description) <= 280 THEN service_description
ELSE LEFT(service_description, 279) || ''
END AS "presentation_resume",
CASE LENGTH(service_description) <= 280
WHEN TRUE THEN NULL
WHEN FALSE THEN service_description
CASE
WHEN LENGTH(service_description) <= 280 THEN NULL
ELSE service_description
END AS "presentation_detail"
FROM ressources_partenariales
ORDER BY 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ di_thematique_by_soliguide_category_code AS (
('mobility', ARRAY['mobilite']),
('other_activities', ARRAY['remobilisation--decouvrir-son-potentiel-via-le-sport-et-la-culture']),
('overnight_stop', ARRAY['logement-hebergement--mal-loges-sans-logis']),
('parent_assistance', ARRAY['famille--information-et-accompagnement-des-parents','famille--soutien-a-la-parentalite', 'famille--soutien-aux-familles']),
('parent_assistance', ARRAY['famille--information-et-accompagnement-des-parents', 'famille--soutien-a-la-parentalite', 'famille--soutien-aux-familles']),
('provision_of_vehicles', ARRAY['mobilite--louer-un-vehicule']),
('psychological_support', ARRAY['sante--bien-etre-psychologique']),
('public_writer', ARRAY['acces-aux-droits-et-citoyennete--accompagnement-dans-les-demarches-administratives', 'numerique--realiser-des-demarches-administratives-avec-un-accompagnement']),
Expand Down Expand Up @@ -89,7 +89,7 @@ open_services AS (
CURRENT_DATE AT TIME ZONE 'Europe/Paris',
CURRENT_DATE AT TIME ZONE 'Europe/Paris'
)
OVERLAPS
OVERLAPS -- noqa: LT02
(
COALESCE(close__date_debut, CURRENT_DATE - INTERVAL '1 year'),
COALESCE(close__date_fin, CURRENT_DATE + INTERVAL '1 year')
Expand Down Expand Up @@ -132,13 +132,13 @@ final AS (
ARRAY['en-presentiel'] AS "modes_accueil",
categories.label || COALESCE(' : ' || open_services.name, '') AS "nom",
'https://soliguide.fr/fr/fiche/' || lieux.seo_url AS "lien_source",
CASE LENGTH(open_services.description) <= 280
WHEN TRUE THEN open_services.description
WHEN FALSE THEN LEFT(open_services.description, 279) || ''
CASE
WHEN LENGTH(open_services.description) <= 280 THEN open_services.description
ELSE LEFT(open_services.description, 279) || ''
END AS "presentation_resume",
CASE LENGTH(open_services.description) <= 280
WHEN TRUE THEN NULL
WHEN FALSE THEN open_services.description
CASE
WHEN LENGTH(open_services.description) <= 280 THEN NULL
ELSE open_services.description
END AS "presentation_detail",
CASE
WHEN open_services.different_hours
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ final AS (
NULL AS "telephone",
'https://soliguide.fr/fr/fiche/' || lieux.seo_url AS "lien_source",
UDF_SOLIGUIDE__NEW_HOURS_TO_OSM_OPENING_HOURS(lieux.newhours) AS "horaires_ouverture",
CASE LENGTH(lieux.description) <= 280
WHEN TRUE THEN lieux.description
WHEN FALSE THEN LEFT(lieux.description, 279) || ''
CASE
WHEN LENGTH(lieux.description) <= 280 THEN lieux.description
ELSE LEFT(lieux.description, 279) || ''
END AS "presentation_resume",
CASE LENGTH(lieux.description) <= 280
WHEN TRUE THEN NULL
WHEN FALSE THEN lieux.description
CASE
WHEN LENGTH(lieux.description) <= 280 THEN NULL
ELSE lieux.description
END AS "presentation_detail"
FROM lieux
ORDER BY 1
Expand Down
18 changes: 9 additions & 9 deletions pipeline/dbt/models/staging/brevo/stg_brevo__contacts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ WITH source AS (

final AS (
SELECT
(data ->> 'emailBlacklisted')::BOOLEAN AS "email_blacklisted",
(data ->> 'smsBlacklisted')::BOOLEAN AS "sms_blacklisted",
(data ->> 'createdAt')::TIMESTAMP WITH TIME ZONE AS "created_at",
(data ->> 'modifiedAt')::TIMESTAMP WITH TIME ZONE AS "modified_at",
ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS(data -> 'listIds'))::INT [] AS "list_ids",
data ->> 'id' AS "id",
TO_DATE(data -> 'attributes' ->> 'DATE_DI_RGPD_OPPOSITION', 'YYYY-MM-DD') AS "date_di_rgpd_opposition",
data -> 'attributes' ->> 'CONTACT_UIDS' AS "contact_uids",
NULLIF(TRIM(data ->> 'email'), '') AS "email"
CAST((data ->> 'emailBlacklisted') AS BOOLEAN) AS "email_blacklisted",
CAST((data ->> 'smsBlacklisted') AS BOOLEAN) AS "sms_blacklisted",
CAST((data ->> 'createdAt') AS TIMESTAMP WITH TIME ZONE) AS "created_at",
CAST((data ->> 'modifiedAt') AS TIMESTAMP WITH TIME ZONE) AS "modified_at",
CAST(ARRAY(SELECT * FROM JSONB_ARRAY_ELEMENTS(data -> 'listIds')) AS INT []) AS "list_ids",
data ->> 'id' AS "id",
TO_DATE(data -> 'attributes' ->> 'DATE_DI_RGPD_OPPOSITION', 'YYYY-MM-DD') AS "date_di_rgpd_opposition",
data -> 'attributes' ->> 'CONTACT_UIDS' AS "contact_uids",
NULLIF(TRIM(data ->> 'email'), '') AS "email"
FROM source
)

Expand Down
Loading

0 comments on commit b00db91

Please sign in to comment.