e-deposit model WIP

This commit is contained in:
Joaquin Ossa 2024-08-28 09:58:14 +02:00
parent a1e3174700
commit a4dc798f86
2 changed files with 178 additions and 70 deletions

View file

@ -1,52 +1,42 @@
with with
stg_edeposit__verifications as ( stg_edeposit__verifications as (
select * from {{ ref("stg_edeposit__verifications") }} select * from {{ ref("stg_edeposit__verifications") }}
),
edeposit_records as (
select
is_cancelled,
channel,
cast(checkin_at_utc as date) as checkin_date_utc,
cast(checkout_at_utc as date) as checkout_date_utc,
creation_at_utc,
verification_status,
id_user,
case
when verification_status = 'Approved' or verification_status = 'Flagged'
then
cast(nightly_fee_local as float)
* (cast(checkout_at_utc as date) - cast(checkin_at_utc as date))
else 0
end as ok_status_fee,
case
when verification_status = 'Rejected' then 0.25 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 {{ ref("stg_edeposit__verifications") }} -- Use ref() to reference other dbt models
where version = 'V2'
) )
select select
year_month_created, id as id_verification,
year_month_checkout, id_booking,
id_user, id_user,
count(*) as bookings_per_month, id_listing,
sum(cast(is_cancelled as integer)) as cancelled_per_month, version, -- V1 for guesty and V2 for e-deposit verifications
sum(cast(is_cancelled as integer))::decimal / count(*) as cancelled_ratio, verification_status,
case verification_status_reason,
when sum(cast(is_cancelled as integer))::decimal / count(*) >= 0.05 nightly_fee_local,
then sum(cast(is_cancelled as integer)) * 0.25 cast(checkout_at_utc as date) - cast(checkin_at_utc as date) as number_nights,
else 0 email_flag,
end as sum_cancelled_fee, phone_flag,
sum(ok_status_fee) as ok_status_fee_sum, watch_list,
sum(rejected_fee) as rejected_fee_sum, channel,
case checkin_at_utc,
when sum(cast(is_cancelled as integer))::decimal / count(*) >= 0.05 checkout_at_utc,
then sum(cast(is_cancelled as integer)) * 0.25 is_cancelled,
else 0 cancelled_at_utc,
end user_email,
+ sum(ok_status_fee) guest_email,
+ sum(rejected_fee) as total_revenue guest_last_name,
from edeposit_records guest_first_name,
group by year_month_created, year_month_checkout, id_user guest_telephone,
order by year_month_created company_name,
property_manager_name,
property_manager_email,
listing_name,
listing_town,
listing_country,
listing_postcode,
pets_allowed,
level_of_protection_amount,
level_of_protection_currency,
status_updated_at_utc,
updated_at_utc,
creation_at_utc,
created_at_utc
from stg_edeposit__verifications

View file

@ -2781,44 +2781,162 @@ models:
- year_month_created - year_month_created
- year_month_checkout - year_month_checkout
- id_user - id_user
- name: int__verifications
description: ""
columns: columns:
- name: year_month_created - name: id_verification
data_type: text data_type: text
description: "first day of month of created date" description: "unique Superhog generated id for this verification"
tests:
- unique
- not_null
- name: year_month_checkout - name: id_booking
data_type: text data_type: text
description: "first day of month of check-out date" description: "unique Superhog generated id for a booking"
- name: id_user - name: id_user
data_type: text data_type: text
description: "unique id value for user" description: "unique Superhog generated id for a guest"
- name: bookings_per_month - name: id_listing
data_type: bigint data_type: text
description: "total number of bookings" description: "unique Superhog generated id for a listing"
- name: cancelled_per_month - name: version
data_type: bigint data_type: text
description: "number of cancelled bookings" description:
"V1 for guesty verifications
V2 fo e-deposit verifications"
tests:
- accepted_values:
values:
- V1
- V2
- name: cancelled_ratio - name: verification_status
data_type: numeric data_type: text
description: "ratio of cancelled bookings over total bookings" description: "status of the verification"
- name: sum_cancelled_fee - name: verification_status_reason
data_type: numeric data_type: text
description: "sum of fees charged for cancelled bookings" description: ""
- name: ok_status_fee_sum - name: nightly_fee_local
data_type: double precision data_type: text
description: | description: "fee charged per night"
"sum of fees charged for bookings with status 'Approved' or 'Flagged'"
- name: rejected_fee_sum - name: number_nights
data_type: numeric data_type: integer
description: "sum of fees charged for rejected bookings" description: "number of nights for the booking"
- name: total_revenue - name: total_revenue
data_type: double precision data_type: double precision
description: "total sum of fees charged" description: "total sum of fees charged"
- name: email_flag
data_type: text
description: ""
- name: phone_flag
data_type: text
description: ""
- name: watch_list
data_type: text
description: ""
- name: channel
data_type: text
description: ""
- name: checkin_at_utc
data_type: timestamp without time zone
description: ""
- name: checkout_at_utc
data_type: timestamp without time zone
description: ""
- name: is_cancelled
data_type: boolean
description: ""
- name: cancelled_at_utc
data_type: timestamp without time zone
description: ""
- name: user_email
data_type: text
description: ""
- name: guest_email
data_type: text
description: ""
- name: guest_last_name
data_type: text
description: ""
- name: guest_first_name
data_type: text
description: ""
- name: guest_telephone
data_type: text
description: ""
- name: company_name
data_type: text
description: ""
- name: property_manager_name
data_type: text
description: ""
- name: property_manager_email
data_type: text
description: ""
- name: listing_name
data_type: text
description: ""
- name: listing_town
data_type: text
description: ""
- name: listing_country
data_type: text
description: ""
- name: listing_postcode
data_type: text
description: ""
- name: pets_allowed
data_type: boolean
description: ""
- name: level_of_protection_amount
data_type: integer
description: ""
- name: level_of_protection_currency
data_type: text
description: ""
- name: status_updated_at_utc
data_type: timestamp without time zone
description: ""
- name: updated_at_utc
data_type: timestamp without time zone
description: ""
- name: creation_at_utc
data_type: timestamp without time zone
description: ""
- name: created_at_utc
data_type: timestamp without time zone
description: ""