From a4dc798f868dfd31acf77a8cc3267df1c9ebf169 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Wed, 28 Aug 2024 09:58:14 +0200 Subject: [PATCH] e-deposit model WIP --- .../core/int_core__edeposit_verifications.sql | 82 ++++----- models/intermediate/core/schema.yaml | 166 +++++++++++++++--- 2 files changed, 178 insertions(+), 70 deletions(-) diff --git a/models/intermediate/core/int_core__edeposit_verifications.sql b/models/intermediate/core/int_core__edeposit_verifications.sql index 61a81d0..2292dc9 100644 --- a/models/intermediate/core/int_core__edeposit_verifications.sql +++ b/models/intermediate/core/int_core__edeposit_verifications.sql @@ -1,52 +1,42 @@ with stg_edeposit__verifications as ( 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 - year_month_created, - year_month_checkout, + id as id_verification, + id_booking, id_user, - count(*) 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, - case - when sum(cast(is_cancelled as integer))::decimal / count(*) >= 0.05 - then sum(cast(is_cancelled as integer)) * 0.25 - else 0 - end as sum_cancelled_fee, - sum(ok_status_fee) as ok_status_fee_sum, - sum(rejected_fee) as rejected_fee_sum, - case - when sum(cast(is_cancelled as integer))::decimal / count(*) >= 0.05 - then sum(cast(is_cancelled as integer)) * 0.25 - else 0 - end - + sum(ok_status_fee) - + sum(rejected_fee) as total_revenue -from edeposit_records -group by year_month_created, year_month_checkout, id_user -order by year_month_created + id_listing, + version, -- V1 for guesty and V2 for e-deposit verifications + verification_status, + verification_status_reason, + nightly_fee_local, + cast(checkout_at_utc as date) - cast(checkin_at_utc as date) as number_nights, + email_flag, + phone_flag, + watch_list, + channel, + checkin_at_utc, + checkout_at_utc, + is_cancelled, + cancelled_at_utc, + user_email, + guest_email, + guest_last_name, + guest_first_name, + guest_telephone, + 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 diff --git a/models/intermediate/core/schema.yaml b/models/intermediate/core/schema.yaml index 08fe0ef..b74cd2d 100644 --- a/models/intermediate/core/schema.yaml +++ b/models/intermediate/core/schema.yaml @@ -2781,44 +2781,162 @@ models: - year_month_created - year_month_checkout - id_user + - name: int__verifications + description: "" columns: - - name: year_month_created + - name: id_verification 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 - description: "first day of month of check-out date" + description: "unique Superhog generated id for a booking" - name: id_user data_type: text - description: "unique id value for user" + description: "unique Superhog generated id for a guest" - - name: bookings_per_month - data_type: bigint - description: "total number of bookings" + - name: id_listing + data_type: text + description: "unique Superhog generated id for a listing" - - name: cancelled_per_month - data_type: bigint - description: "number of cancelled bookings" + - name: version + data_type: text + description: + "V1 for guesty verifications + V2 fo e-deposit verifications" + tests: + - accepted_values: + values: + - V1 + - V2 - - name: cancelled_ratio - data_type: numeric - description: "ratio of cancelled bookings over total bookings" + - name: verification_status + data_type: text + description: "status of the verification" - - name: sum_cancelled_fee - data_type: numeric - description: "sum of fees charged for cancelled bookings" + - name: verification_status_reason + data_type: text + description: "" - - name: ok_status_fee_sum - data_type: double precision - description: | - "sum of fees charged for bookings with status 'Approved' or 'Flagged'" + - name: nightly_fee_local + data_type: text + description: "fee charged per night" - - name: rejected_fee_sum - data_type: numeric - description: "sum of fees charged for rejected bookings" + - name: number_nights + data_type: integer + description: "number of nights for the booking" - name: total_revenue data_type: double precision 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: ""