Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Amélioration et historisation des candidats de la file active #382

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 0 additions & 101 deletions dbt/models/legacy/daily/candidats_sans_solution.sql

This file was deleted.

9 changes: 6 additions & 3 deletions dbt/models/marts/daily/candidats_recherche_active.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ select
max(cc.date_embauche) as date_derniere_embauche,
current_date - min(cc.date_premiere_candidature) as delai_premiere_candidature,
current_date - max(cc.date_candidature) as delai_derniere_candidature,
{{ interval_30_days('current_date - max(cc.date_candidature)', 0) }} as delai_derniere_candidature_interval,
cast({{ interval_30_days('current_date - max(cc.date_candidature)', 1) }} as integer) as delai_derniere_candidature_interval_order,
{{ interval_30_days('current_date - max(cc.date_candidature)', 0) }} as delai_derniere_candidature_interval,
{{ interval_30_days('current_date - max(cc.date_candidature)', 1) }} as delai_derniere_candidature_interval_order,
current_date - max(case when cc."état" = 'Candidature acceptée' then cc.date_candidature end) as delai_derniere_candidature_acceptee,
count(cc.id) as nb_candidatures,
sum(case when cc."état" = 'Candidature acceptée' then 1 else 0 end) as nb_candidatures_acceptees,
sum(case when cc."état" != 'Candidature acceptée' then 1 else 0 end) as nb_candidatures_sans_accept,
coalesce(sum(case when cc."état" = 'Candidature acceptée' then 1 else 0 end) > 0) as a_eu_acceptation,
coalesce(max(cc.date_embauche) >= current_date - interval '6 months', max(cc.date_embauche) is not null) as a_eu_embauche
coalesce(max(cc.date_embauche) >= current_date - interval '6 months', max(cc.date_embauche) is not null) as a_eu_embauche,
coalesce(
min(cc.date_premiere_candidature) <= current_date - interval '30 days' and coalesce(sum(case when cc."état" = 'Candidature acceptée' then 1 else 0 end), 0) = 0
) as file_active_30_jours
from {{ ref('stg_candidats_candidatures') }} as cc
where cc.date_candidature >= current_date - interval '6 months'
group by
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
select
{{ pilo_star(ref('stg_candidats_candidatures'), relation_alias="cdd") }},
cra.nb_candidatures_acceptees,
cra.delai_derniere_candidature
cdd.id as id_candidature,
cra.id as id_candidat
from {{ ref('stg_candidats_candidatures') }} as cdd
right join {{ ref('candidats_recherche_active') }} as cra
on cra.id = cdd.id
Expand Down
3 changes: 3 additions & 0 deletions dbt/models/marts/daily/properties.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ models:
description: >
Table contenant les candidats actifs les 6 derniers mois et permettant de savoir s'ils ont eu des candidatures acceptées ainsi que le délai depuis la dernière candidature émise.
Utile pour le calcul des candidats sans solution selon la définition simplifiée 'candidat actif les 6 derniers mois n'ayant eu aucune candidature acceptée'.
- name: candidatures_candidats_recherche_active
description: >
Contient les candidatures des 6 derniers mois pour les candidats en recherche active.
- name: visites_ft
description: >
Table permettant le suivi des visites et visiteurs uniques sur le TB 406 - Requetage FT.
Expand Down
42 changes: 42 additions & 0 deletions dbt/models/marts/weekly/candidats_recherche_active_histo.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{{
config(
materialized='incremental',
unique_key=['id', 'semaine_valide'],
post_hook="""
DELETE FROM {{ this }}
WHERE date_derniere_candidature_acceptee is not null and delai_premiere_candidature > 30
"""
)
}}

-- recover last known date in the table to increment for new period
with last_known_date as (
select max(date_trunc('week', dbt_valid_to)) as lkd
from {{ ref('candidats_recherche_active_snapshot') }}
)

select
{{ pilo_star(ref('candidats_recherche_active_snapshot'), except=["dbt_valid_from", "dbt_valid_to"]) }},
date_trunc('week', week_series) as semaine_valide
from
{{ ref('candidats_recherche_active_snapshot') }}
cross join
last_known_date
cross join
generate_series(
date_trunc('week', dbt_valid_from),
-- when dbt_valid_to is empty, state is still the same today
-- so we compute row for each week from valid_to to today
coalesce(date_trunc('week', dbt_valid_to), last_known_date.lkd),
interval '1 week'
) as week_series

{% if is_incremental() %}

-- we only update rows that have changed
-- the previous state is no longer current if :
-- 1: dbt_valid_from is bigger than last week date (this line is the new state) // dbt_valid_from is bigger than the last known date
-- 2: dbt_valid_to is bigger than last week date (this line is the last state that is now finished) // dbt_valid
where dbt_valid_from >= last_known_date.lkd or dbt_valid_to >= last_known_date.lkd

{% endif %}
4 changes: 4 additions & 0 deletions dbt/tests/test_candidats_file_active.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- if there is a date_derniere_candidature_acceptee, the candidate is not in the file active
select id
from candidats_recherche_active
where file_active_30_jours = true and date_derniere_candidature_acceptee is not null
Loading