Commit saved model

This commit is contained in:
Joaquin Ossa 2024-11-09 15:21:20 +01:00
parent 98ba74481a
commit eec21fe5da
4 changed files with 115 additions and 75 deletions

View file

@ -1,3 +1,5 @@
{% set starting_date = "('2020-01-01')" %}
with with
unique_dimensions as ( unique_dimensions as (
select distinct has_payment, has_id_check select distinct has_payment, has_id_check
@ -6,3 +8,4 @@ with
select d.date_day, ud.has_payment, ud.has_id_check select d.date_day, ud.has_payment, ud.has_id_check
from {{ ref("int_dates") }} as d from {{ ref("int_dates") }} as d
cross join unique_dimensions as ud cross join unique_dimensions as ud
where d.date_day >= {{ starting_date }}

View file

@ -9,7 +9,6 @@ select
-- Unique Key -- -- Unique Key --
icvp.payment_paid_date_utc as date, icvp.payment_paid_date_utc as date,
coalesce(icuh.id_deal, 'UNSET') as id_deal, coalesce(icuh.id_deal, 'UNSET') as id_deal,
'With Payment' as has_payment,
case case
when icv.id_verification is null then 'W/O Id Check' else 'With Id Check' when icv.id_verification is null then 'W/O Id Check' else 'With Id Check'
end as has_id_check, end as has_id_check,
@ -77,4 +76,4 @@ left join
on icuh.id_deal = icmas.id_deal on icuh.id_deal = icmas.id_deal
and icvp.payment_paid_date_utc = icmas.date and icvp.payment_paid_date_utc = icmas.date
where upper(icvp.payment_status) = {{ var("paid_payment_state") }} where upper(icvp.payment_status) = {{ var("paid_payment_state") }}
group by 1, 2, 3, 4, 5, 6 group by 1, 2, 3, 4, 5

View file

@ -1,9 +1,11 @@
{% set has_payment_true = "('With Payment')" %}
with with
guest_kpis as ( guest_journey_metrics as (
select select
dd.date_day as date, gj.date,
dd.has_payment, gj.has_payment,
dd.has_id_check, gj.has_id_check,
sum( sum(
gj.created_guest_journeys_not_cancelled gj.created_guest_journeys_not_cancelled
) as created_guest_journeys_not_cancelled, ) as created_guest_journeys_not_cancelled,
@ -23,63 +25,109 @@ with
sum(gj.average_csat_score * gj.count_csat_score) sum(gj.average_csat_score * gj.count_csat_score)
/ sum(gj.count_csat_score) / sum(gj.count_csat_score)
else null else null
end as average_csat_score, end as average_csat_score
from {{ ref("int_kpis__metric_daily_check_in_attributed_guest_journeys") }} gj
group by gj.date, gj.has_payment, gj.has_id_check
),
guest_payment_metrics as (
select
gp.date,
gp.has_id_check,
sum(gp.deposit_fees_in_gbp) as deposit_fees_in_gbp, sum(gp.deposit_fees_in_gbp) as deposit_fees_in_gbp,
sum(gp.waiver_payments_in_gbp) as waiver_payments_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.checkin_cover_fees_in_gbp) as checkin_cover_fees_in_gbp,
sum(gp.total_guest_payments_in_gbp) as total_guest_payments_in_gbp sum(gp.total_guest_payments_in_gbp) as total_guest_payments_in_gbp
from {{ ref("int_kpis__dimension_daily_guest_product") }} dd from {{ ref("int_kpis__metric_daily_guest_payments") }} gp
group by gp.date, gp.has_id_check
),
guest_kpis as (
select
dd.date_day,
dd.has_payment,
dd.has_id_check,
gj.created_guest_journeys_not_cancelled,
gj.started_guest_journeys_not_cancelled,
gj.completed_guest_journeys_not_cancelled,
gj.created_guest_journeys,
gj.started_guest_journeys,
gj.completed_guest_journeys,
gj.total_csat_score_count,
gj.average_csat_score,
gp.deposit_fees_in_gbp,
gp.waiver_payments_in_gbp,
gp.checkin_cover_fees_in_gbp,
gp.total_guest_payments_in_gbp
from {{ ref("int_kpis__dimension_date_product_guest") }} dd
left join left join
{{ ref("int_kpis__metric_daily_check_in_attributed_guest_journeys") }} gj guest_journey_metrics gj
on gj.date = dd.date_day on gj.date = dd.date_day
and gj.has_payment = dd.has_payment
and gj.has_id_check = dd.has_id_check
left join left join
{{ ref("int_kpis__metric_daily_guest_payments") }} gp guest_payment_metrics gp
on gj.date = gp.date on gp.date = dd.date_day
and gj.id_deal = gp.id_deal and gp.has_id_check = dd.has_id_check
and gj.has_payment = gp.has_payment and dd.has_payment = {{ has_payment_true }}
and gj.has_id_check = gp.has_id_check
and gj.main_billing_country_iso_3_per_deal
= gp.main_billing_country_iso_3_per_deal
and gj.active_accommodations_per_deal_segmentation
= gp.active_accommodations_per_deal_segmentation
where dd.date_day = '2017-02-28'
group by dd.date_day, dd.has_payment, dd.has_id_check
) )
select select
gk.date, gk.date_day,
gk.has_payment, gk.has_payment,
gk.has_id_check, gk.has_id_check,
gk.created_guest_journeys_not_cancelled, sum(
gk.started_guest_journeys_not_cancelled, gk.created_guest_journeys_not_cancelled
gk.completed_guest_journeys_not_cancelled, ) as created_guest_journeys_not_cancelled,
gk.created_guest_journeys, sum(
gk.started_guest_journeys, gk.started_guest_journeys_not_cancelled
gk.completed_guest_journeys, ) as started_guest_journeys_not_cancelled,
gk.total_csat_score_count, sum(
gk.average_csat_score, gk.completed_guest_journeys_not_cancelled
gk.deposit_fees_in_gbp, ) as completed_guest_journeys_not_cancelled,
gk.waiver_payments_in_gbp, sum(gk.created_guest_journeys) as created_guest_journeys,
gk.checkin_cover_fees_in_gbp, sum(gk.started_guest_journeys) as started_guest_journeys,
gk.total_guest_payments_in_gbp, sum(gk.completed_guest_journeys) as completed_guest_journeys,
sum(gk.total_csat_score_count) as total_csat_score_count,
case
when sum(gk.total_csat_score_count) > 0
then
sum(gk.average_csat_score * gk.total_csat_score_count)
/ sum(gk.total_csat_score_count)
else null
end as average_csat_score,
sum(gk.deposit_fees_in_gbp) as deposit_fees_in_gbp,
sum(gk.waiver_payments_in_gbp) as waiver_payments_in_gbp,
sum(gk.checkin_cover_fees_in_gbp) as checkin_cover_fees_in_gbp,
sum(gk.total_guest_payments_in_gbp) as total_guest_payments_in_gbp,
sum(
gk_py.created_guest_journeys_not_cancelled gk_py.created_guest_journeys_not_cancelled
as created_guest_journeys_not_cancelled_py, ) as py_created_guest_journeys_not_cancelled,
sum(
gk_py.started_guest_journeys_not_cancelled gk_py.started_guest_journeys_not_cancelled
as started_guest_journeys_not_cancelled_py, ) as py_started_guest_journeys_not_cancelled,
sum(
gk_py.completed_guest_journeys_not_cancelled gk_py.completed_guest_journeys_not_cancelled
as completed_guest_journeys_not_cancelled_py, ) as py_completed_guest_journeys_not_cancelled,
gk_py.created_guest_journeys as created_guest_journeys_py, sum(gk_py.created_guest_journeys) as py_created_guest_journeys,
gk_py.started_guest_journeys as started_guest_journeys_py, sum(gk_py.started_guest_journeys) as py_started_guest_journeys,
gk_py.completed_guest_journeys as completed_guest_journeys_py, sum(gk_py.completed_guest_journeys) as py_completed_guest_journeys,
gk_py.total_csat_score_count as total_csat_score_count_py, sum(gk_py.total_csat_score_count) as py_total_csat_score_count,
gk_py.average_csat_score as average_csat_score_py, case
gk_py.deposit_fees_in_gbp as deposit_fees_in_gbp_py, when sum(gk_py.total_csat_score_count) > 0
gk_py.waiver_payments_in_gbp as waiver_payments_in_gbp_py, then
gk_py.checkin_cover_fees_in_gbp as checkin_cover_fees_in_gbp_py, sum(gk_py.average_csat_score * gk_py.total_csat_score_count)
gk_py.total_guest_payments_in_gbp as total_guest_payments_in_gbp_py / sum(gk_py.total_csat_score_count)
else null
end as py_average_csat_score,
sum(gk_py.deposit_fees_in_gbp) as py_deposit_fees_in_gbp,
sum(gk_py.waiver_payments_in_gbp) as py_waiver_payments_in_gbp,
sum(gk_py.checkin_cover_fees_in_gbp) as py_checkin_cover_fees_in_gbp,
sum(gk_py.total_guest_payments_in_gbp) as py_total_guest_payments_in_gbp
from guest_kpis gk from guest_kpis gk
left join left join
guest_kpis gk_py guest_kpis gk_py
on gk.date = gk_py.date + interval '1 year' on gk.date_day = gk_py.date_day + interval '1 year'
and gk.has_payment = gk_py.has_payment and gk.has_payment = gk_py.has_payment
and gk.has_id_check = gk_py.has_id_check and gk.has_id_check = gk_py.has_id_check
-- Here we use a group by because of leap days that generate duplicity when being
-- moved to another year
group by gk.date_day, gk.has_payment, gk.has_id_check

View file

@ -1957,16 +1957,6 @@ models:
tests: tests:
- not_null - not_null
- name: has_payment
data_type: string
description: Has there been any guest payments on the guest journey.
tests:
- not_null
- accepted_values:
values:
- W/O Payment
- With Payment
- name: has_id_check - name: has_id_check
data_type: string data_type: string
description: Does the verification in the guest journey description: Does the verification in the guest journey
@ -5792,7 +5782,7 @@ models:
description: | description: |
Count of listings booked within the past 12 months for a given date, dimension and value. Count of listings booked within the past 12 months for a given date, dimension and value.
- name: int_kpis__dimension_daily_guest_product - name: int_kpis__dimension_date_product_guest
description: | description: |
This model computes a cross join of dates with all combinations of This model computes a cross join of dates with all combinations of
guest products dimensions. guest products dimensions.
@ -5839,18 +5829,18 @@ models:
The unique key corresponds to the deepest granularity of the model, The unique key corresponds to the deepest granularity of the model,
in this case: in this case:
- date, - date_day,
- id_deal, - id_deal,
- has_id_check. - has_id_check.
tests: tests:
- dbt_utils.unique_combination_of_columns: - dbt_utils.unique_combination_of_columns:
combination_of_columns: combination_of_columns:
- date - date_day
- has_payment - has_payment
- has_id_check - has_id_check
columns: columns:
- name: date - name: date_day
data_type: date data_type: date
description: "Date of when Guest Journeys have been completed." description: "Date of when Guest Journeys have been completed."
tests: tests:
@ -5948,73 +5938,73 @@ models:
Sum of total payments paid by guests, without taxes, in GBP Sum of total payments paid by guests, without taxes, in GBP
in a given date and per specified dimension. in a given date and per specified dimension.
- name: created_guest_journeys_not_cancelled_py - name: py_created_guest_journeys_not_cancelled
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys created (excluding canceled bookings) Count of daily guest journeys created (excluding canceled bookings)
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: started_guest_journeys_not_cancelled_py - name: py_started_guest_journeys_not_cancelled
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys started (excluding canceled bookings) Count of daily guest journeys started (excluding canceled bookings)
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: completed_guest_journeys_not_cancelled_py - name: py_completed_guest_journeys_not_cancelled
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys completed (excluding canceled bookings) Count of daily guest journeys completed (excluding canceled bookings)
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: created_guest_journeys_py - name: py_created_guest_journeys
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys created on the same date in the previous year, Count of daily guest journeys created on the same date in the previous year,
segmented by the specified dimension. segmented by the specified dimension.
- name: started_guest_journeys_py - name: py_started_guest_journeys
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys started on the same date in the previous year, Count of daily guest journeys started on the same date in the previous year,
segmented by the specified dimension. segmented by the specified dimension.
- name: completed_guest_journeys_py - name: py_completed_guest_journeys
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys completed on the same date in the previous year, Count of daily guest journeys completed on the same date in the previous year,
segmented by the specified dimension. segmented by the specified dimension.
- name: count_csat_score_py - name: py_count_csat_score
data_type: bigint data_type: bigint
description: | description: |
Count of daily guest journeys with CSAT (customer satisfaction score) Count of daily guest journeys with CSAT (customer satisfaction score)
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: average_csat_score_py - name: py_average_csat_score
data_type: bigint data_type: bigint
description: | description: |
Average daily CSAT score on the same date in the previous year, Average daily CSAT score on the same date in the previous year,
segmented by the specified dimension. segmented by the specified dimension.
- name: deposit_fees_in_gbp_py - name: py_deposit_fees_in_gbp
data_type: decimal data_type: decimal
description: | description: |
Sum of deposit fees paid by guests, excluding taxes, in GBP Sum of deposit fees paid by guests, excluding taxes, in GBP
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: waiver_payments_in_gbp_py - name: py_waiver_payments_in_gbp
data_type: decimal data_type: decimal
description: | description: |
Sum of waiver payments paid by guests, excluding taxes, in GBP Sum of waiver payments paid by guests, excluding taxes, in GBP
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: checkin_cover_fees_in_gbp_py - name: py_checkin_cover_fees_in_gbp
data_type: decimal data_type: decimal
description: | description: |
Sum of check-in cover fees paid by guests, excluding taxes, in GBP Sum of check-in cover fees paid by guests, excluding taxes, in GBP
on the same date in the previous year, segmented by the specified dimension. on the same date in the previous year, segmented by the specified dimension.
- name: total_guest_payments_in_gbp_py - name: py_total_guest_payments_in_gbp
data_type: decimal data_type: decimal
description: | description: |
Sum of total payments paid by guests, excluding taxes, in GBP Sum of total payments paid by guests, excluding taxes, in GBP