fixed variable definitions and added comments for currency-less fees
This commit is contained in:
parent
be59ab258a
commit
189e77dd76
2 changed files with 36 additions and 20 deletions
|
|
@ -1,8 +1,8 @@
|
|||
{% set ok_status_fee_calculation = "case when verification_status = 'Approved' or verification_status = 'Flagged' then cast(nightly_fee_local as float) * number_nights else 0 end" %}
|
||||
|
||||
{% set rejected_fee_calculation = (
|
||||
"case when verification_status = 'Rejected' then 0.25 else 0 end"
|
||||
) %}
|
||||
{% 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") }}
|
||||
|
|
@ -17,8 +17,16 @@ with
|
|||
creation_at_utc,
|
||||
verification_status,
|
||||
id_user_host,
|
||||
{{ ok_status_fee_calculation }} as ok_status_fee,
|
||||
{{ rejected_fee_calculation }} as rejected_fee,
|
||||
case
|
||||
when verification_status in {{ ok_status }}
|
||||
then cast(nightly_fee_local as float) * 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
|
||||
|
|
@ -30,17 +38,22 @@ select
|
|||
id_user_host,
|
||||
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(*) as cancelled_ratio,
|
||||
sum(cast(is_cancelled as integer))::decimal
|
||||
/ count(distinct id_booking) as cancelled_ratio,
|
||||
case
|
||||
when sum(cast(is_cancelled as integer))::decimal / count(*) >= 0.05
|
||||
then sum(cast(is_cancelled as integer)) * 0.25
|
||||
when
|
||||
sum(cast(is_cancelled as integer))::decimal / count(distinct id_booking)
|
||||
>= {{ cancellation_threshold }}
|
||||
then sum(cast(is_cancelled as integer)) * {{ cancellation_fee }}
|
||||
else 0
|
||||
end as sum_cancelled_fee,
|
||||
sum(ok_status_fee) as ok_status_fee_sum,
|
||||
sum(rejected_fee) as rejected_fee_sum,
|
||||
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(*) >= 0.05
|
||||
then sum(cast(is_cancelled as integer)) * 0.25
|
||||
when
|
||||
sum(cast(is_cancelled as integer))::decimal / count(distinct id_booking)
|
||||
>= {{ cancellation_threshold }}
|
||||
then sum(cast(is_cancelled as integer)) * {{ cancellation_fee }}
|
||||
else 0
|
||||
end
|
||||
+ sum(ok_status_fee)
|
||||
|
|
|
|||
|
|
@ -2979,17 +2979,20 @@ models:
|
|||
|
||||
- name: sum_cancelled_fee
|
||||
data_type: numeric
|
||||
description: "sum of fees charged for cancelled bookings"
|
||||
description: "sum of fees charged for cancelled bookings
|
||||
(currency-less)"
|
||||
|
||||
- name: ok_status_fee_sum
|
||||
- name: sum_ok_status_fee
|
||||
data_type: double precision
|
||||
description: |
|
||||
"sum of fees charged for bookings with status 'Approved' or 'Flagged'"
|
||||
"sum of fees charged for bookings with status 'Approved' or 'Flagged'
|
||||
(currency-less)"
|
||||
|
||||
- name: rejected_fee_sum
|
||||
- name: sum_rejected_fee
|
||||
data_type: numeric
|
||||
description: "sum of fees charged for rejected bookings"
|
||||
description: "sum of fees charged for rejected bookings
|
||||
(currency-less)"
|
||||
|
||||
- name: total_revenue
|
||||
data_type: double precision
|
||||
description: "total sum of fees charged"
|
||||
description: "total sum of fees charged (currency-less)"
|
||||
Loading…
Add table
Add a link
Reference in a new issue