Kept basic models to reduce complexity of
models/20125_edeposit_migration_agg_model_reporting
This commit is contained in:
parent
42510bbb4d
commit
fd98f31fdd
4 changed files with 1 additions and 232 deletions
|
|
@ -1,79 +0,0 @@
|
|||
{% set ok_status = ("Approved", "Flagged") %}
|
||||
{% set rejected_status = "Rejected" %}
|
||||
{% set rejected_fee = 0.25 %}
|
||||
{% set cancellation_fee = 0.25 %}
|
||||
{% set cancellation_threshold = 0.05 %}
|
||||
with
|
||||
int_edeposit__verifications as (
|
||||
select * from {{ ref("int_edeposit__verifications") }}
|
||||
),
|
||||
edeposit_records as (
|
||||
select
|
||||
id_booking,
|
||||
is_cancelled,
|
||||
id_user_partner,
|
||||
channel,
|
||||
checkin_date_utc,
|
||||
checkout_date_utc,
|
||||
creation_at_utc,
|
||||
verification_status,
|
||||
case
|
||||
when verification_status in {{ ok_status }}
|
||||
then nightly_fee_local * number_nights
|
||||
else 0
|
||||
end as ok_status_fee,
|
||||
case
|
||||
when verification_status = '{{ rejected_status }}'
|
||||
then {{ rejected_fee }}
|
||||
else 0
|
||||
end as rejected_fee,
|
||||
to_char(creation_at_utc, 'YYYY-MM') as year_month_created,
|
||||
to_char(checkout_at_utc, 'YYYY-MM') as year_month_checkout
|
||||
from int_edeposit__verifications
|
||||
where version = 'V2'
|
||||
),
|
||||
aggregated_partner_booking_metrics as (
|
||||
select
|
||||
id_user_partner,
|
||||
year_month_created,
|
||||
year_month_checkout,
|
||||
count(distinct id_booking) as bookings_per_month,
|
||||
sum(cast(is_cancelled as integer)) as cancelled_per_month,
|
||||
sum(cast(is_cancelled as integer))::decimal
|
||||
/ count(distinct id_booking) as cancelled_ratio,
|
||||
sum(ok_status_fee) as sum_ok_status_fee,
|
||||
sum(rejected_fee) as sum_rejected_fee,
|
||||
case
|
||||
when
|
||||
sum(cast(is_cancelled as integer))::decimal
|
||||
/ count(distinct id_booking)
|
||||
>= {{ cancellation_threshold }}
|
||||
then true
|
||||
else false
|
||||
end as is_cancellation_threshold_surpassed
|
||||
from edeposit_records
|
||||
group by year_month_created, year_month_checkout, id_user_partner
|
||||
)
|
||||
select
|
||||
id_user_partner,
|
||||
year_month_created,
|
||||
year_month_checkout,
|
||||
bookings_per_month,
|
||||
cancelled_per_month,
|
||||
cancelled_ratio,
|
||||
is_cancellation_threshold_surpassed,
|
||||
case
|
||||
when is_cancellation_threshold_surpassed
|
||||
then cancelled_per_month * {{ cancellation_fee }}
|
||||
else 0
|
||||
end as sum_cancelled_fee,
|
||||
sum_ok_status_fee,
|
||||
sum_rejected_fee,
|
||||
sum_ok_status_fee
|
||||
+ sum_rejected_fee
|
||||
+ case
|
||||
when cancelled_ratio >= {{ cancellation_threshold }}
|
||||
then cancelled_per_month * {{ cancellation_fee }}
|
||||
else 0
|
||||
end as total_revenue
|
||||
from aggregated_partner_booking_metrics
|
||||
|
|
@ -180,68 +180,3 @@ models:
|
|||
- name: created_at_utc
|
||||
data_type: timestamp without time zone
|
||||
description: ""
|
||||
|
||||
- name: int_edeposit__agg_fee_per_user
|
||||
description:
|
||||
"This table holds detailed data on revenue generated through e-deposit verifications.
|
||||
Each record provides insights into booking activities per user, including the number
|
||||
of bookings, cancellations, and associated fees within specific months. Each record
|
||||
captures data for bookings created in a particular month along with their corresponding
|
||||
checkout month, allowing for a comprehensive view of the booking lifecycle and associated
|
||||
revenues within those periods."
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- year_month_created
|
||||
- year_month_checkout
|
||||
- id_user_partner
|
||||
columns:
|
||||
- name: id_user_partner
|
||||
data_type: text
|
||||
description: "unique id value for user partner"
|
||||
|
||||
- name: year_month_created
|
||||
data_type: text
|
||||
description: "year and month of created date"
|
||||
|
||||
- name: year_month_checkout
|
||||
data_type: text
|
||||
description: "year and month of check-out date"
|
||||
|
||||
- name: bookings_per_month
|
||||
data_type: bigint
|
||||
description: "total number of bookings"
|
||||
|
||||
- name: cancelled_per_month
|
||||
data_type: bigint
|
||||
description: "number of cancelled bookings"
|
||||
|
||||
- name: cancelled_ratio
|
||||
data_type: numeric
|
||||
description: "ratio of cancelled bookings over total bookings"
|
||||
|
||||
- name: is_cancellation_threshold_surpassed
|
||||
data_type: boolean
|
||||
description: "true if the cancellation ratio is higher than the set threshold"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: sum_cancelled_fee
|
||||
data_type: numeric
|
||||
description: "sum of fees charged for cancelled bookings
|
||||
(currency-less)"
|
||||
|
||||
- name: sum_ok_status_fee
|
||||
data_type: double precision
|
||||
description: |
|
||||
"sum of fees charged for bookings with status 'Approved' or 'Flagged'
|
||||
(currency-less)"
|
||||
|
||||
- name: sum_rejected_fee
|
||||
data_type: numeric
|
||||
description: "sum of fees charged for rejected bookings
|
||||
(currency-less)"
|
||||
|
||||
- name: total_revenue
|
||||
data_type: double precision
|
||||
description: "total sum of fees charged (currency-less)"
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
with
|
||||
int_edeposit__agg_fee_per_user as (
|
||||
select * from {{ ref("int_edeposit__agg_fee_per_user") }}
|
||||
)
|
||||
select
|
||||
year_month_created as year_month_created,
|
||||
year_month_checkout as year_month_checkout,
|
||||
id_user_partner as id_user_partner,
|
||||
bookings_per_month as bookings_per_month,
|
||||
cancelled_per_month as cancelled_per_month,
|
||||
cancelled_ratio as cancelled_ratio,
|
||||
is_cancellation_threshold_surpassed as is_cancellation_threshold_surpassed,
|
||||
sum_cancelled_fee as sum_cancelled_fee,
|
||||
sum_ok_status_fee as sum_ok_status_fee,
|
||||
sum_rejected_fee as sum_rejected_fee,
|
||||
total_revenue as total_revenue
|
||||
from int_edeposit__agg_fee_per_user
|
||||
|
|
@ -1,73 +1,3 @@
|
|||
version: 2
|
||||
|
||||
models:
|
||||
- name: edeposit__agg_fee_per_user
|
||||
description:
|
||||
"This table holds detailed data on revenue generated through e-deposit verifications.
|
||||
Each record provides insights into booking activities per user, including the number
|
||||
of bookings, cancellations, and associated fees within specific months. Each record
|
||||
captures data for bookings created in a particular month along with their corresponding
|
||||
checkout month, allowing for a comprehensive view of the booking lifecycle and associated
|
||||
revenues within those periods."
|
||||
tests:
|
||||
- dbt_utils.unique_combination_of_columns:
|
||||
combination_of_columns:
|
||||
- year_month_created
|
||||
- year_month_checkout
|
||||
- id_user_partner
|
||||
columns:
|
||||
- name: id_user_partner
|
||||
data_type: text
|
||||
description: "unique id value for user partner"
|
||||
test:
|
||||
- not_null
|
||||
|
||||
- name: year_month_created
|
||||
data_type: text
|
||||
description: "year and month of created date"
|
||||
test:
|
||||
- not_null
|
||||
|
||||
- name: year_month_checkout
|
||||
data_type: text
|
||||
description: "year and month of check-out date"
|
||||
test:
|
||||
- not_null
|
||||
|
||||
- name: bookings_per_month
|
||||
data_type: bigint
|
||||
description: "total number of bookings"
|
||||
|
||||
- name: cancelled_per_month
|
||||
data_type: bigint
|
||||
description: "number of cancelled bookings"
|
||||
|
||||
- name: cancelled_ratio
|
||||
data_type: numeric
|
||||
description: "ratio of cancelled bookings over total bookings"
|
||||
|
||||
- name: is_cancellation_threshold_surpassed
|
||||
data_type: boolean
|
||||
description: "true if the cancellation ratio is higher than the set threshold"
|
||||
tests:
|
||||
- not_null
|
||||
|
||||
- name: sum_cancelled_fee
|
||||
data_type: numeric
|
||||
description: "sum of fees charged for cancelled bookings
|
||||
(currency-less)"
|
||||
|
||||
- name: sum_ok_status_fee
|
||||
data_type: double precision
|
||||
description: |
|
||||
"sum of fees charged for bookings with status 'Approved' or 'Flagged'
|
||||
(currency-less)"
|
||||
|
||||
- name: sum_rejected_fee
|
||||
data_type: numeric
|
||||
description: "sum of fees charged for rejected bookings
|
||||
(currency-less)"
|
||||
|
||||
- name: total_revenue
|
||||
data_type: double precision
|
||||
description: "total sum of fees charged (currency-less)"
|
||||
models:
|
||||
Loading…
Add table
Add a link
Reference in a new issue