Merged PR 3469: Switches Listing and Deal metrics

# Description

Switches Listings and Deal metrics to production.
I also modified the dependencies on the old lifecycles to read from the news, so we can remove these in a following PR.

I'm considering re-computing also the dimension - specific models to operate within KPIs folder, but will do this later on in a dedicated PR.

# Checklist

- [X] The edited models and dependants run properly with production data.
- [X] The edited models are sufficiently documented.
- [X] The edited models contain PK tests, and I've ran and passed them.
- [ ] I have checked for DRY opportunities with other models and docs.
- [ ] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #23761
This commit is contained in:
Oriol Roqué Paniagua 2024-11-08 11:11:04 +00:00
parent 335ba9a29b
commit 5e1b418570
4 changed files with 63 additions and 49 deletions

View file

@ -3,8 +3,8 @@
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }} {{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
with with
int_core__mtd_accommodation_segmentation as ( int_kpis__dimension_daily_accommodation as (
select * from {{ ref("int_core__mtd_accommodation_segmentation") }} select * from {{ ref("int_kpis__dimension_daily_accommodation") }}
), ),
int_core__user_host as (select * from {{ ref("int_core__user_host") }}), int_core__user_host as (select * from {{ ref("int_core__user_host") }}),
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}) int_dates_mtd as (select * from {{ ref("int_dates_mtd") }})
@ -23,7 +23,7 @@ with
d.is_current_month d.is_current_month
from int_dates_mtd d from int_dates_mtd d
{% if dimension.dimension == "'by_number_of_listings'" %} {% if dimension.dimension == "'by_number_of_listings'" %}
inner join int_core__mtd_accommodation_segmentation a on d.date = a.date inner join int_kpis__dimension_daily_accommodation a on d.date = a.date
{% elif dimension.dimension == "'by_billing_country'" %} {% elif dimension.dimension == "'by_billing_country'" %}
inner join inner join
int_core__user_host h int_core__user_host h

View file

@ -4,9 +4,14 @@ This model aggregates the different metrics by deal for those hosts that have it
*/ */
with with
int_dates_by_deal as (select * from {{ ref("int_dates_by_deal") }}), int_dates_by_deal as (select * from {{ ref("int_dates_by_deal") }}),
int_mtd_deal_lifecycle as (select * from {{ ref("int_mtd_deal_lifecycle") }}), daily_deal_lifecycle as (select * from {{ ref("int_kpis__lifecycle_daily_deal") }}),
int_core__monthly_accommodation_history_by_deal as ( listings as (
select * from {{ ref("int_core__monthly_accommodation_history_by_deal") }} select *
from {{ ref("int_kpis__agg_daily_listings") }}
where
dimension in ('by_deal')
and dimension_value <> 'UNSET'
and is_end_of_month = true
), ),
created_bookings as ( created_bookings as (
select * select *
@ -74,7 +79,7 @@ select
d.main_billing_country_iso_3_per_deal, d.main_billing_country_iso_3_per_deal,
-- DEAL LIFECYCLE -- -- DEAL LIFECYCLE --
deal_lifecycle.deal_lifecycle_state, daily_deal_lifecycle.deal_lifecycle_state,
-- BOOKINGS -- -- BOOKINGS --
created_bookings.created_bookings, created_bookings.created_bookings,
@ -98,16 +103,16 @@ select
/ completed_guest_journeys.completed_guest_journeys as payment_rate_guest_journey, / completed_guest_journeys.completed_guest_journeys as payment_rate_guest_journey,
-- LISTINGS -- -- LISTINGS --
accommodations.new_listings, listings.new_listings,
accommodations.never_booked_listings, listings.never_booked_listings,
accommodations.first_time_booked_listings, listings.first_time_booked_listings,
accommodations.active_listings, listings.active_listings,
accommodations.churning_listings, listings.churning_listings,
accommodations.inactive_listings, listings.inactive_listings,
accommodations.reactivated_listings, listings.reactivated_listings,
accommodations.listings_booked_in_month, listings.listings_booked_in_month,
accommodations.listings_booked_in_6_months, listings.listings_booked_in_6_months,
accommodations.listings_booked_in_12_months, listings.listings_booked_in_12_months,
-- HOST (OPERATOR) REVENUE -- -- HOST (OPERATOR) REVENUE --
invoiced_revenue.xero_booking_net_fees_in_gbp, invoiced_revenue.xero_booking_net_fees_in_gbp,
@ -171,14 +176,14 @@ select
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif( ) / nullif(
accommodations.listings_booked_in_month, 0 listings.listings_booked_in_month, 0
) as total_revenue_per_listings_booked_in_month ) as total_revenue_per_listings_booked_in_month
from int_dates_by_deal d from int_dates_by_deal d
left join left join
int_mtd_deal_lifecycle deal_lifecycle daily_deal_lifecycle
on d.date = deal_lifecycle.date on d.date = daily_deal_lifecycle.date
and d.id_deal = deal_lifecycle.id_deal and d.id_deal = daily_deal_lifecycle.id_deal
left join left join
created_bookings created_bookings
on d.date = created_bookings.end_date on d.date = created_bookings.end_date
@ -215,10 +220,7 @@ left join
guest_payments guest_payments
on d.date = guest_payments.end_date on d.date = guest_payments.end_date
and d.id_deal = guest_payments.dimension_value and d.id_deal = guest_payments.dimension_value
left join left join listings on d.date = listings.date and d.id_deal = listings.dimension_value
int_core__monthly_accommodation_history_by_deal accommodations
on d.date = accommodations.date
and d.id_deal = accommodations.id_deal
left join left join
invoiced_revenue invoiced_revenue
on d.date = invoiced_revenue.end_date on d.date = invoiced_revenue.end_date

View file

@ -9,8 +9,8 @@ with
int_dates_mtd_by_dimension as ( int_dates_mtd_by_dimension as (
select * from {{ ref("int_dates_mtd_by_dimension") }} select * from {{ ref("int_dates_mtd_by_dimension") }}
), ),
int_core__mtd_accommodation_segmentation as ( int_kpis__dimension_daily_accommodation as (
select * from {{ ref("int_core__mtd_accommodation_segmentation") }} select * from {{ ref("int_kpis__dimension_daily_accommodation") }}
), ),
int_core__deal as (select * from {{ ref("int_core__deal") }}), int_core__deal as (select * from {{ ref("int_core__deal") }}),
churn_metrics_per_date as ( churn_metrics_per_date as (
@ -43,9 +43,9 @@ with
from int_monthly_12m_window_contribution_by_deal m12wc from int_monthly_12m_window_contribution_by_deal m12wc
{% if dimension.dimension == "'by_number_of_listings'" %} {% if dimension.dimension == "'by_number_of_listings'" %}
inner join inner join
int_core__mtd_accommodation_segmentation mas int_kpis__dimension_daily_accommodation dda
on m12wc.id_deal = mas.id_deal on m12wc.id_deal = dda.id_deal
and m12wc.date = mas.date and m12wc.date = dda.date
{% elif dimension.dimension == "'by_billing_country'" %} {% elif dimension.dimension == "'by_billing_country'" %}
inner join inner join
int_core__deal ud int_core__deal ud

View file

@ -108,10 +108,22 @@ with
dimension in ('global', 'by_number_of_listings', 'by_billing_country') dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET' and dimension_value <> 'UNSET'
), ),
int_core__mtd_accommodation_metrics as ( listings as (
select * from {{ ref("int_core__mtd_accommodation_metrics") }} select *
from {{ ref("int_kpis__agg_daily_listings") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
and (is_month_to_date = true or is_end_of_month = true)
),
deals as (
select *
from {{ ref("int_kpis__agg_daily_deals") }}
where
dimension in ('global', 'by_number_of_listings', 'by_billing_country')
and dimension_value <> 'UNSET'
and (is_month_to_date = true or is_end_of_month = true)
), ),
int_mtd_deal_metrics as (select * from {{ ref("int_mtd_deal_metrics") }}),
guest_payments as ( guest_payments as (
select * select *
from {{ ref("int_kpis__agg_mtd_guest_payments") }} from {{ ref("int_kpis__agg_mtd_guest_payments") }}
@ -207,16 +219,16 @@ with
deals.deals_booked_in_12_months, deals.deals_booked_in_12_months,
-- LISTINGS (ACCOMMODATIONS) -- -- LISTINGS (ACCOMMODATIONS) --
accommodations.new_listings, listings.new_listings,
accommodations.never_booked_listings, listings.never_booked_listings,
accommodations.first_time_booked_listings, listings.first_time_booked_listings,
accommodations.active_listings, listings.active_listings,
accommodations.churning_listings, listings.churning_listings,
accommodations.inactive_listings, listings.inactive_listings,
accommodations.reactivated_listings, listings.reactivated_listings,
accommodations.listings_booked_in_month, listings.listings_booked_in_month,
accommodations.listings_booked_in_6_months, listings.listings_booked_in_6_months,
accommodations.listings_booked_in_12_months, listings.listings_booked_in_12_months,
-- HOST (OPERATOR) REVENUE -- -- HOST (OPERATOR) REVENUE --
invoiced_revenue.xero_booking_net_fees_in_gbp, invoiced_revenue.xero_booking_net_fees_in_gbp,
@ -288,7 +300,7 @@ with
+ coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_operator_net_fees_in_gbp, 0)
+ coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0) + coalesce(invoiced_revenue.xero_apis_net_fees_in_gbp, 0)
) / nullif( ) / nullif(
accommodations.listings_booked_in_month, 0 listings.listings_booked_in_month, 0
) as total_revenue_per_listings_booked_in_month, ) as total_revenue_per_listings_booked_in_month,
-- CHURN -- -- CHURN --
@ -338,12 +350,12 @@ with
and d.dimension = guest_journeys_with_payment.dimension and d.dimension = guest_journeys_with_payment.dimension
and d.dimension_value = guest_journeys_with_payment.dimension_value and d.dimension_value = guest_journeys_with_payment.dimension_value
left join left join
int_core__mtd_accommodation_metrics accommodations listings
on d.date = accommodations.date on d.date = listings.date
and d.dimension = accommodations.dimension and d.dimension = listings.dimension
and d.dimension_value = accommodations.dimension_value and d.dimension_value = listings.dimension_value
left join left join
int_mtd_deal_metrics deals deals
on d.date = deals.date on d.date = deals.date
and d.dimension = deals.dimension and d.dimension = deals.dimension
and d.dimension_value = deals.dimension_value and d.dimension_value = deals.dimension_value