Skip to content

Commit

Permalink
solve histo of file active
Browse files Browse the repository at this point in the history
  • Loading branch information
laurinehu committed Dec 17, 2024
1 parent f776c4a commit 8833c1e
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 105 deletions.
101 changes: 0 additions & 101 deletions dbt/models/legacy/daily/candidats_sans_solution.sql

This file was deleted.

8 changes: 7 additions & 1 deletion dbt/models/marts/daily/candidats_recherche_active.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ select
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,
case
when 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
then true
else false
end 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
44 changes: 44 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,44 @@
{{
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 *
from candidats_recherche_active
where file_active_30_jours = true and date_derniere_candidature_acceptee is not null

0 comments on commit 8833c1e

Please sign in to comment.