Merged PR 3454: Guest payments models for Guest KPIs

# Description

Weekly, monthly and mtd agg for the guest payment models for guest KPIs

# 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.
- [x] 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: #23371
This commit is contained in:
Joaquin Ossa 2024-11-07 12:10:14 +00:00
commit dada9c289a
6 changed files with 298 additions and 5 deletions

View file

@ -117,7 +117,6 @@ Provides a general assignemnt for the Dimensions available for each KPI
{% set additional_dimensions = additional_dimensions + [dim_dash()] %} {% set additional_dimensions = additional_dimensions + [dim_dash()] %}
{% endif %} {% endif %}
{# Add entity-specific dimensions #}
{% if entity_name == "CHECK_IN_ATTRIBUTED_GUEST_JOURNEYS" %} {% if entity_name == "CHECK_IN_ATTRIBUTED_GUEST_JOURNEYS" %}
{% set additional_dimensions = additional_dimensions + [ {% set additional_dimensions = additional_dimensions + [
dim_has_payment(), dim_has_payment(),
@ -125,6 +124,12 @@ Provides a general assignemnt for the Dimensions available for each KPI
] %} ] %}
{% endif %} {% endif %}
{% if entity_name == "GUEST_PAYMENTS" %}
{% set additional_dimensions = additional_dimensions + [
dim_has_id_check(),
] %}
{% endif %}
{# Combine base dimensions with additional dimensions for the specific model #} {# Combine base dimensions with additional dimensions for the specific model #}
{% set dimensions = base_dimensions + additional_dimensions %} {% set dimensions = base_dimensions + additional_dimensions %}
{{ return(dimensions) }} {{ return(dimensions) }}

View file

@ -0,0 +1,27 @@
{% set dimensions = get_kpi_dimensions_per_model("GUEST_PAYMENTS") %}
{{
config(
materialized="table", unique_key=["end_date", "dimension", "dimension_value"]
)
}}
{% for dimension in dimensions %}
select
-- Unique Key --
start_date,
end_date,
{{ dimension.dimension }} as dimension,
{{ dimension.dimension_value }} as dimension_value,
-- Metrics --
sum(deposit_fees_in_gbp) as deposit_fees_in_gbp,
sum(waiver_payments_in_gbp) as waiver_payments_in_gbp,
sum(checkin_cover_fees_in_gbp) as checkin_cover_fees_in_gbp,
sum(total_guest_payments_in_gbp) as total_guest_payments_in_gbp
from {{ ref("int_kpis__metric_weekly_guest_payments") }}
group by 1, 2, 3, 4
{% if not loop.last %}
union all
{% endif %}
{% endfor %}

View file

@ -4,6 +4,7 @@
unique_key=[ unique_key=[
"end_date", "end_date",
"id_deal", "id_deal",
"has_id_check",
"active_accommodations_per_deal_segmentation", "active_accommodations_per_deal_segmentation",
], ],
) )
@ -14,6 +15,7 @@ select
d.first_day_month as start_date, d.first_day_month as start_date,
d.date as end_date, d.date as end_date,
gp.id_deal, gp.id_deal,
gp.has_id_check,
gp.active_accommodations_per_deal_segmentation, gp.active_accommodations_per_deal_segmentation,
-- Dimensions -- -- Dimensions --
gp.main_billing_country_iso_3_per_deal, gp.main_billing_country_iso_3_per_deal,
@ -27,4 +29,4 @@ left join
{{ ref("int_kpis__metric_daily_guest_payments") }} gp {{ ref("int_kpis__metric_daily_guest_payments") }} gp
on date_trunc('month', gp.date)::date = d.first_day_month on date_trunc('month', gp.date)::date = d.first_day_month
where d.is_end_of_month = true and gp.id_deal is not null where d.is_end_of_month = true and gp.id_deal is not null
group by 1, 2, 3, 4, 5 group by 1, 2, 3, 4, 5, 6

View file

@ -4,6 +4,7 @@
unique_key=[ unique_key=[
"end_date", "end_date",
"id_deal", "id_deal",
"has_id_check",
"active_accommodations_per_deal_segmentation", "active_accommodations_per_deal_segmentation",
], ],
) )
@ -14,6 +15,7 @@ select
d.first_day_month as start_date, d.first_day_month as start_date,
d.date as end_date, d.date as end_date,
gp.id_deal, gp.id_deal,
gp.has_id_check,
gp.active_accommodations_per_deal_segmentation, gp.active_accommodations_per_deal_segmentation,
-- Dimensions -- -- Dimensions --
gp.main_billing_country_iso_3_per_deal, gp.main_billing_country_iso_3_per_deal,
@ -28,4 +30,4 @@ left join
on date_trunc('month', gp.date)::date = d.first_day_month on date_trunc('month', gp.date)::date = d.first_day_month
and extract(day from gp.date) <= d.day and extract(day from gp.date) <= d.day
where d.is_month_to_date = true and gp.id_deal is not null where d.is_month_to_date = true and gp.id_deal is not null
group by 1, 2, 3, 4, 5 group by 1, 2, 3, 4, 5, 6

View file

@ -0,0 +1,33 @@
{{
config(
materialized="view",
unique_key=[
"end_date",
"id_deal",
"has_id_check",
"active_accommodations_per_deal_segmentation",
],
)
}}
select
-- Unique Key --
d.first_day_week as start_date,
d.date as end_date,
d.week,
gp.id_deal,
gp.has_id_check,
gp.active_accommodations_per_deal_segmentation,
-- Dimensions --
gp.main_billing_country_iso_3_per_deal,
-- Metrics --
sum(gp.deposit_fees_in_gbp) as deposit_fees_in_gbp,
sum(gp.waiver_payments_in_gbp) as waiver_payments_in_gbp,
sum(gp.checkin_cover_fees_in_gbp) as checkin_cover_fees_in_gbp,
sum(gp.total_guest_payments_in_gbp) as total_guest_payments_in_gbp
from {{ ref("int_kpis__dimension_dates") }} d
left join
{{ ref("int_kpis__metric_daily_guest_payments") }} gp
on date_trunc('week', gp.date)::date = d.first_day_week
where d.is_end_of_week = true and gp.id_deal is not null
group by 1, 2, 3, 4, 5, 6, 7

View file

@ -1957,6 +1957,17 @@ models:
tests: tests:
- not_null - not_null
- name: has_id_check
data_type: string
description: Does the verification in the guest journey
includes Government Id Check for the bookings.
tests:
- not_null
- accepted_values:
values:
- W/O Id Check
- With Id Check
- name: active_accommodations_per_deal_segmentation - name: active_accommodations_per_deal_segmentation
data_type: string data_type: string
description: | description: |
@ -2015,6 +2026,7 @@ models:
The unique key corresponds to: The unique key corresponds to:
- end_date, - end_date,
- id_deal, - id_deal,
- has_id_check,
- active_accommodations_per_deal_segmentation. - active_accommodations_per_deal_segmentation.
tests: tests:
@ -2022,6 +2034,7 @@ models:
combination_of_columns: combination_of_columns:
- end_date - end_date
- id_deal - id_deal
- has_id_check
- active_accommodations_per_deal_segmentation - active_accommodations_per_deal_segmentation
columns: columns:
@ -2045,6 +2058,17 @@ models:
tests: tests:
- not_null - not_null
- name: has_id_check
data_type: string
description: Does the verification in the guest journey
includes Government Id Check for the bookings.
tests:
- not_null
- accepted_values:
values:
- W/O Id Check
- With Id Check
- name: active_accommodations_per_deal_segmentation - name: active_accommodations_per_deal_segmentation
data_type: string data_type: string
description: | description: |
@ -2103,6 +2127,7 @@ models:
The unique key corresponds to: The unique key corresponds to:
- end_date, - end_date,
- id_deal, - id_deal,
- has_id_check,
- active_accommodations_per_deal_segmentation. - active_accommodations_per_deal_segmentation.
tests: tests:
@ -2110,6 +2135,7 @@ models:
combination_of_columns: combination_of_columns:
- end_date - end_date
- id_deal - id_deal
- has_id_check
- active_accommodations_per_deal_segmentation - active_accommodations_per_deal_segmentation
columns: columns:
@ -2133,6 +2159,17 @@ models:
tests: tests:
- not_null - not_null
- name: has_id_check
data_type: string
description: Does the verification in the guest journey
includes Government Id Check for the bookings.
tests:
- not_null
- accepted_values:
values:
- W/O Id Check
- With Id Check
- name: active_accommodations_per_deal_segmentation - name: active_accommodations_per_deal_segmentation
data_type: string data_type: string
description: | description: |
@ -2180,6 +2217,113 @@ models:
Sum of accumulated total payments paid by guests, without taxes, Sum of accumulated total payments paid by guests, without taxes,
in GBP in a given month up to the given date and per specified dimension. in GBP in a given month up to the given date and per specified dimension.
- name: int_kpis__metric_weekly_guest_payments
description: |
This model computes the Weekly Guest Payments at the
deepest granularity.
Be aware that any dimension that can change over the monthly period,
such as daily segmentations, are included in the primary key of the
model.
The unique key corresponds to:
- end_date,
- id_deal,
- has_id_check,
- active_accommodations_per_deal_segmentation.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- end_date
- id_deal
- has_id_check
- active_accommodations_per_deal_segmentation
columns:
- name: start_date
data_type: date
description: |
The start date of the time range considered for the metrics in this record.
tests:
- not_null
- name: end_date
data_type: date
description: |
The end date of the time range considered for the metrics in this record.
tests:
- not_null
- name: week
data_type: int
description: ISO week number of the given date.
tests:
- not_null
- name: id_deal
data_type: string
description: Unique identifier of an account.
tests:
- not_null
- name: has_id_check
data_type: string
description: Does the verification in the guest journey
includes Government Id Check for the bookings.
tests:
- not_null
- accepted_values:
values:
- W/O Id Check
- With Id Check
- name: active_accommodations_per_deal_segmentation
data_type: string
description: |
Segment value based on the number of listings booked in 12 months
for a given deal and date.
tests:
- not_null
- accepted_values:
values:
- "0"
- "01-05"
- "06-20"
- "21-60"
- "61+"
- "UNSET"
- name: main_billing_country_iso_3_per_deal
data_type: string
description: |
Main billing country of the host aggregated at Deal level.
tests:
- not_null
- name: deposit_fees_in_gbp
data_type: decimal
description: |
Sum of accumulated deposit fees paid by guests, without taxes,
in GBP in a given week up to the given date and per specified dimension.
- name: waiver_payments_in_gbp
data_type: decimal
description: |
Sum of accumulated waiver payments paid by guests, without taxes,
in GBP in a given week up to the given date and per specified dimension.
- name: checkin_cover_fees_in_gbp
data_type: decimal
description: |
Sum of accumulated checkin cover fees by guests, without taxes,
in GBP in a given week up to the given date and per specified dimension.
- name: total_guest_payments_in_gbp
data_type: decimal
description: |
Sum of accumulated total payments paid by guests, without taxes,
in GBP in a given week up to the given date and per specified dimension.
- name: int_kpis__agg_monthly_guest_payments - name: int_kpis__agg_monthly_guest_payments
description: | description: |
This model computes the dimension aggregation for This model computes the dimension aggregation for
@ -2226,6 +2370,7 @@ models:
- by_number_of_listings - by_number_of_listings
- by_billing_country - by_billing_country
- by_deal - by_deal
- by_has_id_check
- name: dimension_value - name: dimension_value
data_type: string data_type: string
@ -2303,6 +2448,7 @@ models:
- by_number_of_listings - by_number_of_listings
- by_billing_country - by_billing_country
- by_deal - by_deal
- by_has_id_check
- name: dimension_value - name: dimension_value
data_type: string data_type: string
@ -2334,6 +2480,84 @@ models:
The month-to-date total payments paid by guests, without taxes, in GBP The month-to-date total payments paid by guests, without taxes, in GBP
for a given range date, dimension and value. for a given range date, dimension and value.
- name: int_kpis__agg_weekly_guest_payments
description: |
This model computes the dimension aggregation for
Weekly Guest Payments.
The primary key of this model is end_date, dimension
and dimension_value.
tests:
- dbt_utils.unique_combination_of_columns:
combination_of_columns:
- end_date
- dimension
- dimension_value
columns:
- name: start_date
data_type: date
description: |
The start date of the time range considered for the metrics in this record.
tests:
- not_null
- name: end_date
data_type: date
description: |
The end date of the time range considered for the metrics in this record.
tests:
- not_null
- name: dimension
data_type: string
description: The dimension or granularity of the metrics.
tests:
- assert_dimension_completeness:
metric_column_names:
- deposit_fees_in_gbp
- waiver_payments_in_gbp
- checkin_cover_fees_in_gbp
- total_guest_payments_in_gbp
- accepted_values:
values:
- global
- by_number_of_listings
- by_billing_country
- by_deal
- by_has_id_check
- name: dimension_value
data_type: string
description: The value or segment available for the selected dimension.
tests:
- not_null
- name: deposit_fees_in_gbp
data_type: decimal
description: |
The weekly deposit fees paid by guests, without taxes, in GBP
for a given range date, dimension and value.
- name: waiver_payments_in_gbp
data_type: decimal
description: |
The weekly waiver payments paid by guests, without taxes, in GBP
for a given range date, dimension and value.
- name: checkin_cover_fees_in_gbp
data_type: decimal
description: |
The weekly checkin cover fees paid by guests, without taxes, in GBP
for a given range date, dimension and value.
- name: total_guest_payments_in_gbp
data_type: decimal
description: |
The weekly total payments paid by guests, without taxes, in GBP
for a given range date, dimension and value.
- name: int_kpis__metric_daily_check_out_bookings - name: int_kpis__metric_daily_check_out_bookings
description: | description: |
This model computes the Daily Check-out Bookings at the deepest granularity. This model computes the Daily Check-out Bookings at the deepest granularity.