Skip to content

Commit

Permalink
(DE-685) dbt(snapshots): update model dependancies to snapshots offer…
Browse files Browse the repository at this point in the history
… and collective offer (#3745)

* update dependancies

* update

* update

* update dependancies

* update venue tables dependancies

* update snapshots dependancies to applicative tables

* fix

* fix

* fix

* fix

* update brevo retention pro

* test

* linter

* formatting

* formatting

* duplicate bookable_venue_history for double run

* last fix

* last fix

* change snapshot history folder

* renaming

* renaming
  • Loading branch information
Jules-Arbelot authored Feb 11, 2025
1 parent 6665219 commit dfc3146
Show file tree
Hide file tree
Showing 10 changed files with 341 additions and 287 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
)
}}


with
all_bookable_data as (
select
Expand Down Expand Up @@ -68,8 +69,8 @@ with
venue_id,
offerer_id,
partition_date,
individual as individual_bookable_offers,
collective as collective_bookable_offers
individual as total_individual_bookable_offers,
collective as total_collective_bookable_offers
from
all_bookable_data pivot (
sum(nb_bookable_offers) for offer_type in ('individual', 'collective')
Expand All @@ -80,8 +81,8 @@ select
venue_id,
offerer_id,
partition_date,
coalesce(individual_bookable_offers, 0) as individual_bookable_offers,
coalesce(collective_bookable_offers, 0) as collective_bookable_offers,
coalesce(individual_bookable_offers, 0)
+ coalesce(collective_bookable_offers, 0) as total_bookable_offers
coalesce(total_individual_bookable_offers, 0) as total_individual_bookable_offers,
coalesce(total_collective_bookable_offers, 0) as total_collective_bookable_offers,
coalesce(total_individual_bookable_offers, 0)
+ coalesce(total_collective_bookable_offers, 0) as total_bookable_offers
from pivoted_data
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,6 @@ with
sum(total_real_revenue) as total_real_revenue,
sum(total_created_offers) as total_created_offers,
sum(total_bookable_offers) as total_bookable_offers,
min(first_bookable_offer_date) as first_bookable_offer_date,
max(last_bookable_offer_date) as last_bookable_offer_date,
min(
first_individual_bookable_offer_date
) as first_individual_bookable_offer_date,
max(
last_individual_bookable_offer_date
) as last_individual_bookable_offer_date,
min(
first_collective_bookable_offer_date
) as first_collective_bookable_offer_date,
max(
last_collective_bookable_offer_date
) as last_collective_bookable_offer_date,
count(distinct venue_id) as total_managed_venues,
count(
distinct case when not venue_is_virtual then venue_id end
Expand All @@ -87,9 +73,7 @@ with
)
) as all_physical_venues_types,
count(
case
when venue_type_label = "Lieu administratif" then venue_id else null
end
case when venue_type_label = "Lieu administratif" then venue_id end
) as total_administrative_venues,
max(
case when offerer_real_revenue_rank = 1 then venue_type_label end
Expand Down Expand Up @@ -169,12 +153,6 @@ select
coalesce(vgo.total_real_revenue, 0) as total_real_revenue,
coalesce(vgo.total_created_offers, 0) as total_created_offers,
coalesce(vgo.total_bookable_offers, 0) as total_bookable_offers,
vgo.first_bookable_offer_date,
vgo.last_bookable_offer_date,
vgo.first_individual_bookable_offer_date,
vgo.last_individual_bookable_offer_date,
vgo.first_collective_bookable_offer_date,
vgo.last_collective_bookable_offer_date,
vgo.total_venues,
vgo.top_real_revenue_venue_type,
vgo.top_bookings_venue_type,
Expand Down Expand Up @@ -231,36 +209,6 @@ select
else
coalesce(vgo.last_individual_booking_date, vgo.last_collective_booking_date)
end as last_booking_date,
case
when date_diff(current_date, vgo.last_bookable_offer_date, day) <= 30
then true
else false
end as is_active_last_30days,
case
when date_diff(current_date, vgo.last_bookable_offer_date, year) = 0
then true
else false
end as is_active_current_year,
case
when date_diff(current_date, vgo.last_individual_bookable_offer_date, day) <= 30
then true
else false
end as is_individual_active_last_30days,
case
when date_diff(current_date, vgo.last_individual_bookable_offer_date, year) = 0
then true
else false
end as is_individual_active_current_year,
case
when date_diff(current_date, vgo.last_collective_bookable_offer_date, day) <= 30
then true
else false
end as is_collective_active_last_30days,
case
when date_diff(current_date, vgo.last_collective_bookable_offer_date, year) = 0
then true
else false
end as is_collective_active_current_year
from {{ ref("int_raw__offerer") }} as o
left join
venue_grouped_by_offerer as vgo on o.offerer_id = vgo.venue_managing_offerer_id
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,6 @@ with
) as total_bookable_collective_offers
from {{ ref("int_applicative__collective_offer") }}
group by venue_id
),

bookable_offer_history as (
select
venue_id,
min(partition_date) as first_bookable_offer_date,
max(partition_date) as last_bookable_offer_date,
min(
case when individual_bookable_offers > 0 then partition_date end
) as first_individual_bookable_offer_date,
max(
case when individual_bookable_offers > 0 then partition_date end
) as last_individual_bookable_offer_date,
min(
case when collective_bookable_offers > 0 then partition_date end
) as first_collective_bookable_offer_date,
max(
case when collective_bookable_offers > 0 then partition_date end
) as last_collective_bookable_offer_date
from {{ ref("bookable_venue_history") }}
group by venue_id
)

select
Expand Down Expand Up @@ -232,12 +211,6 @@ select
coalesce(co.total_created_collective_offers, 0) as total_created_collective_offers,
coalesce(o.total_created_individual_offers, 0)
+ coalesce(co.total_created_collective_offers, 0) as total_created_offers,
boh.first_bookable_offer_date,
boh.last_bookable_offer_date,
boh.first_individual_bookable_offer_date,
boh.last_individual_bookable_offer_date,
boh.first_collective_bookable_offer_date,
boh.last_collective_bookable_offer_date,
case
when
o.first_individual_booking_date is not null
Expand Down Expand Up @@ -293,36 +266,6 @@ select
coalesce(
co.total_current_year_non_cancelled_tickets, 0
) as total_current_year_non_cancelled_tickets,
case
when date_diff(current_date, boh.last_bookable_offer_date, day) <= 30
then true
else false
end as is_active_last_30days,
case
when date_diff(current_date, boh.last_bookable_offer_date, year) = 0
then true
else false
end as is_active_current_year,
case
when date_diff(current_date, boh.last_individual_bookable_offer_date, day) <= 30
then true
else false
end as is_individual_active_last_30days,
case
when date_diff(current_date, boh.last_individual_bookable_offer_date, year) = 0
then true
else false
end as is_individual_active_current_year,
case
when date_diff(current_date, boh.last_collective_bookable_offer_date, day) <= 30
then true
else false
end as is_collective_active_last_30days,
case
when date_diff(current_date, boh.last_collective_bookable_offer_date, year) = 0
then true
else false
end as is_collective_active_current_year,
row_number() over (
partition by venue_managing_offerer_id
order by
Expand All @@ -346,7 +289,6 @@ from {{ source("raw", "applicative_database_venue") }} as v
left join {{ ref("int_geo__venue_location") }} as v_loc on v_loc.venue_id = v.venue_id
left join offers_grouped_by_venue as o on o.venue_id = v.venue_id
left join collective_offers_grouped_by_venue as co on co.venue_id = v.venue_id
left join bookable_offer_history as boh on boh.venue_id = v.venue_id
left join
{{ source("raw", "applicative_database_venue_registration") }} as vr
on v.venue_id = vr.venue_id
Expand Down
Loading

0 comments on commit dfc3146

Please sign in to comment.