diff --git a/dbt_project.yml b/dbt_project.yml index 35e5ff7..e61362d 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -75,11 +75,6 @@ vars: # States should be strings in capital letters. Models need to force an upper() "cancelled_booking_state": "'CANCELLED'" "approved_booking_state": "'APPROVED'" - "flagged_booking_state": "'FLAGGED'" - "incomplete_information_booking_state": "'INCOMPLETEINFORMATION'" - "no_flags_booking_state": "'NOFLAGS'" - "not_approved_booking_state": "'NOTAPPROVED'" - "rejected_booking_state": "'REJECTED'" # Payment state variables # States should be strings in capital letters. Models need to force an upper() diff --git a/models/intermediate/core/int_core__new_dash_services_offered.sql b/models/intermediate/core/int_core__new_dash_services_offered.sql index f36c3bf..1fa96c6 100644 --- a/models/intermediate/core/int_core__new_dash_services_offered.sql +++ b/models/intermediate/core/int_core__new_dash_services_offered.sql @@ -1,3 +1,17 @@ +{% set protected_service_status = "'PROTECTED'" %} +{% set rejected_service_status = "'REJECTED'" %} +{% set no_checks_service_status = "'NOCHECKS'" %} +{% set no_flags_service_status = "'NOFLAGS'" %} +{% set paid_service_status = "'PAID'" %} +{% set pending_service_status = "'PENDING'" %} +{% set unknown_service_status = "'-'" %} +{% set partially_protected_service_status = "'PARTIALLY PROTECTED'" %} +{% set not_protected_service_status = "'NOT PROTECTED'" %} +{% set not_paid_service_status = "'NOT PAID'" %} +{% set confirmed_service_status = "'CONFIRMED'" %} +{% set for_review_service_status = "'FORREVIEW'" %} +{% set flagged_service_status = "'FLAGGED'" %} + with int_core__user_product_bundle_contains_services as ( select * from {{ ref("int_core__user_product_bundle_contains_services") }} @@ -13,7 +27,9 @@ with int_core__booking_to_product_bundle as ( select * from {{ ref("int_core__booking_to_product_bundle") }} ), - int_core__bookings as (select * from {{ ref("int_core__bookings") }}), + int_core__booking_service_detail as ( + select * from {{ ref("int_core__booking_service_detail") }} + ), bundle_services as ( select bs.id_user_product_bundle, @@ -45,7 +61,7 @@ with and uh.is_test_account = false ), users as ( - select distinct + select bs.service_display_name, count(distinct bs.id_user_host) as number_users, -- Count only users that have at least one active accommodation. @@ -66,7 +82,7 @@ with group by 1 ), accommodations as ( - select distinct + select bs.service_display_name, count(distinct apb.id_accommodation) as number_accommodations, count( @@ -88,73 +104,107 @@ with group by 1 ), bookings as ( - select distinct - bs.service_display_name, - count(distinct bpb.id_booking) as number_bookings, + select + sd.service_name as service_display_name, + count(distinct sd.id_booking) as number_bookings, count( distinct case - when upper(b.booking_state) = {{ var("approved_booking_state") }} - then bpb.id_booking + when upper(sd.service_status) = {{ protected_service_status }} + then sd.id_booking else null end - ) as number_approved_bookings, + ) as number_bookings_with_service_status_protected, count( distinct case - when upper(b.booking_state) = {{ var("cancelled_booking_state") }} - then bpb.id_booking + when upper(sd.service_status) = {{ rejected_service_status }} + then sd.id_booking else null end - ) as number_cancelled_bookings, + ) as number_bookings_with_service_status_rejected, count( distinct case - when upper(b.booking_state) = {{ var("flagged_booking_state") }} - then bpb.id_booking + when upper(sd.service_status) = {{ no_checks_service_status }} + then sd.id_booking else null end - ) as number_flagged_bookings, + ) as number_bookings_with_service_status_no_checks, + count( + distinct case + when upper(sd.service_status) = {{ no_flags_service_status }} + then sd.id_booking + else null + end + ) as number_bookings_with_service_status_no_flags, + count( + distinct case + when upper(sd.service_status) = {{ paid_service_status }} + then sd.id_booking + else null + end + ) as number_bookings_with_service_status_paid, + count( + distinct case + when upper(sd.service_status) = {{ paid_service_status }} + then sd.id_booking + else null + end + ) as number_bookings_with_service_status_pending, + count( + distinct case + when upper(sd.service_status) = {{ unknown_service_status }} + then sd.id_booking + else null + end + ) as number_bookings_with_service_status_unknown_status, count( distinct case when - upper(b.booking_state) - = {{ var("incomplete_information_booking_state") }} - then bpb.id_booking + upper(sd.service_status) + = {{ partially_protected_service_status }} + then sd.id_booking else null end - ) as number_incomplete_information_bookings, + ) as number_bookings_with_service_status_partially_protected, count( distinct case - when upper(b.booking_state) = {{ var("no_flags_booking_state") }} - then bpb.id_booking + when upper(sd.service_status) = {{ not_protected_service_status }} + then sd.id_booking else null end - ) as number_no_flags_bookings, + ) as number_bookings_with_service_status_not_protected, count( distinct case - when - upper(b.booking_state) = {{ var("not_approved_booking_state") }} - then bpb.id_booking + when upper(sd.service_status) = {{ not_paid_service_status }} + then sd.id_booking else null end - ) as number_not_approved_bookings, + ) as number_bookings_with_service_status_not_paid, count( distinct case - when upper(b.booking_state) = {{ var("rejected_booking_state") }} - then bpb.id_booking + when upper(sd.service_status) = {{ confirmed_service_status }} + then sd.id_booking else null end - ) as number_rejected_bookings - from bundle_services bs - left join - int_core__booking_to_product_bundle bpb - on bpb.id_user_product_bundle = bs.id_user_product_bundle - inner join - int_core__bookings b - on b.id_booking = bpb.id_booking - and b.is_duplicate_booking is false + ) as number_bookings_with_service_status_confirmed, + count( + distinct case + when upper(sd.service_status) = {{ for_review_service_status }} + then sd.id_booking + else null + end + ) as number_bookings_with_service_status_for_review, + count( + distinct case + when upper(sd.service_status) = {{ flagged_service_status }} + then sd.id_booking + else null + end + ) as number_bookings_with_service_status_flagged + from int_core__booking_service_detail sd group by 1 ) select - u.service_display_name, + coalesce(u.service_display_name, b.service_display_name) as service_display_name, u.number_users, u.number_users_with_service_applied_in_accommodation, u.number_users @@ -164,13 +214,19 @@ select a.number_active_accommodations, a.number_inactive_accommodations, b.number_bookings, - b.number_approved_bookings, - b.number_cancelled_bookings, - b.number_flagged_bookings, - b.number_incomplete_information_bookings, - b.number_no_flags_bookings, - b.number_not_approved_bookings, - b.number_rejected_bookings + b.number_bookings_with_service_status_protected, + b.number_bookings_with_service_status_rejected, + b.number_bookings_with_service_status_no_checks, + b.number_bookings_with_service_status_no_flags, + b.number_bookings_with_service_status_paid, + b.number_bookings_with_service_status_pending, + b.number_bookings_with_service_status_unknown_status, + b.number_bookings_with_service_status_partially_protected, + b.number_bookings_with_service_status_not_protected, + b.number_bookings_with_service_status_not_paid, + b.number_bookings_with_service_status_confirmed, + b.number_bookings_with_service_status_for_review, + b.number_bookings_with_service_status_flagged from users u left join accommodations a on u.service_display_name = a.service_display_name -left join bookings b on u.service_display_name = b.service_display_name +full outer join bookings b on u.service_display_name = b.service_display_name diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index ee050a2..1d481a9 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -5241,19 +5241,6 @@ models: description: "The name of the New Dash service." data_tests: - not_null - - accepted_values: - values: - - "BASIC SCREENING" - - "SCREENING PLUS" - - "ID VERIFICATION" - - "SEX OFFENDERS CHECK" - - "BASIC DAMAGE DEPOSIT" - - "BASIC WAIVER" - - "WAIVER PLUS" - - "WAIVER PRO" - - "BASIC PROTECTION" - - "PROTECTION PLUS" - - "PROTECTION PRO" - name: number_users data_type: bigint @@ -5302,47 +5289,57 @@ models: data_type: bigint description: "Number of bookings that have a bundle that considers this service." - - name: number_approved_bookings + - name: number_bookings_with_service_status_protected data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are approved." + description: "Number of bookings with status PROTECTED for this service." - - name: number_cancelled_bookings + - name: number_bookings_with_service_status_rejected data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are cancelled." + description: "Number of bookings with status REJECTED for this service." - - name: number_flagged_bookings + - name: number_bookings_with_service_status_no_checks data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are flagged." + description: "Number of bookings with status NO CHECKS for this service." - - name: number_incomplete_information_bookings + - name: number_bookings_with_service_status_no_flags data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - have incomplete information." + description: "Number of bookings with status NO FLAGS for this service." - - name: number_no_flags_bookings + - name: number_bookings_with_service_status_paid data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - have no flags." + description: "Number of bookings with status PAID for this service." - - name: number_not_approved_bookings + - name: number_bookings_with_service_status_pending data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are not approved." + description: "Number of bookings with status PENDING for this service." - - name: number_rejected_bookings + - name: number_bookings_with_service_status_unknown data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are rejected." + description: "Number of bookings with unknown status for this service." + + - name: number_bookings_with_service_status_partially_protected + data_type: bigint + description: "Number of bookings with status PARTIALLY PROTECTED for this service." + + - name: number_bookings_with_service_status_not_protected + data_type: bigint + description: "Number of bookings with status NOT PROTECTED for this service." + + - name: number_bookings_with_service_status_not_paid + data_type: bigint + description: "Number of bookings with status NOT PAID for this service." + + - name: number_bookings_with_service_status_confirmed + data_type: bigint + description: "Number of bookings with status CONFIRMED for this service." + + - name: number_bookings_with_service_status_for_review + data_type: bigint + description: "Number of bookings with status FOR REVIEW for this service." + + - name: number_bookings_with_service_status_flagged + data_type: bigint + description: "Number of bookings with status FLAGGED for this service." - name: int_core__payments description: | diff --git a/models/reporting/core/core__new_dash_services_offered.sql b/models/reporting/core/core__new_dash_services_offered.sql index 9b6de65..44573b4 100644 --- a/models/reporting/core/core__new_dash_services_offered.sql +++ b/models/reporting/core/core__new_dash_services_offered.sql @@ -13,11 +13,30 @@ select number_active_accommodations as number_active_accommodations, number_inactive_accommodations as number_inactive_accommodations, number_bookings as number_bookings, - number_approved_bookings as number_approved_bookings, - number_cancelled_bookings as number_cancelled_bookings, - number_flagged_bookings as number_flagged_bookings, - number_incomplete_information_bookings as number_incomplete_information_bookings, - number_no_flags_bookings as number_no_flags_bookings, - number_not_approved_bookings as number_not_approved_bookings, - number_rejected_bookings as number_rejected_bookings + number_bookings_with_service_status_protected + as number_bookings_with_service_status_protected, + number_bookings_with_service_status_rejected + as number_bookings_with_service_status_rejected, + number_bookings_with_service_status_no_checks + as number_bookings_with_service_status_no_checks, + number_bookings_with_service_status_no_flags + as number_bookings_with_service_status_no_flags, + number_bookings_with_service_status_paid + as number_bookings_with_service_status_paid, + number_bookings_with_service_status_pending + as number_bookings_with_service_status_pending, + number_bookings_with_service_status_unknown_status + as number_bookings_with_service_status_unknown_status, + number_bookings_with_service_status_partially_protected + as number_bookings_with_service_status_partially_protected, + number_bookings_with_service_status_not_protected + as number_bookings_with_service_status_not_protected, + number_bookings_with_service_status_not_paid + as number_bookings_with_service_status_not_paid, + number_bookings_with_service_status_confirmed + as number_bookings_with_service_status_confirmed, + number_bookings_with_service_status_for_review + as number_bookings_with_service_status_for_review, + number_bookings_with_service_status_flagged + as number_bookings_with_service_status_flagged from int_core__new_dash_services_offered diff --git a/models/reporting/core/schema.yml b/models/reporting/core/schema.yml index 949d6d1..aabe81f 100644 --- a/models/reporting/core/schema.yml +++ b/models/reporting/core/schema.yml @@ -1579,19 +1579,6 @@ models: description: "The name of the New Dash service." data_tests: - not_null - - accepted_values: - values: - - "BASIC SCREENING" - - "SCREENING PLUS" - - "ID VERIFICATION" - - "SEX OFFENDERS CHECK" - - "BASIC DAMAGE DEPOSIT" - - "BASIC WAIVER" - - "WAIVER PLUS" - - "WAIVER PRO" - - "BASIC PROTECTION" - - "PROTECTION PLUS" - - "PROTECTION PRO" - name: number_users data_type: bigint @@ -1640,47 +1627,57 @@ models: data_type: bigint description: "Number of bookings that have a bundle that considers this service." - - name: number_approved_bookings + - name: number_bookings_with_service_status_protected data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are approved." + description: "Number of bookings with status PROTECTED for this service." - - name: number_cancelled_bookings + - name: number_bookings_with_service_status_rejected data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are cancelled." + description: "Number of bookings with status REJECTED for this service." - - name: number_flagged_bookings + - name: number_bookings_with_service_status_no_checks data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are flagged." + description: "Number of bookings with status NO CHECKS for this service." - - name: number_incomplete_information_bookings + - name: number_bookings_with_service_status_no_flags data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - have incomplete information." + description: "Number of bookings with status NO FLAGS for this service." - - name: number_no_flags_bookings + - name: number_bookings_with_service_status_paid data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - have no flags." + description: "Number of bookings with status PAID for this service." - - name: number_not_approved_bookings + - name: number_bookings_with_service_status_pending data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are not approved." + description: "Number of bookings with status PENDING for this service." - - name: number_rejected_bookings + - name: number_bookings_with_service_status_unknown data_type: bigint - description: - "Number of bookings that have a bundle that considers this service and - are rejected." + description: "Number of bookings with unknown status for this service." + + - name: number_bookings_with_service_status_partially_protected + data_type: bigint + description: "Number of bookings with status PARTIALLY PROTECTED for this service." + + - name: number_bookings_with_service_status_not_protected + data_type: bigint + description: "Number of bookings with status NOT PROTECTED for this service." + + - name: number_bookings_with_service_status_not_paid + data_type: bigint + description: "Number of bookings with status NOT PAID for this service." + + - name: number_bookings_with_service_status_confirmed + data_type: bigint + description: "Number of bookings with status CONFIRMED for this service." + + - name: number_bookings_with_service_status_for_review + data_type: bigint + description: "Number of bookings with status FOR REVIEW for this service." + + - name: number_bookings_with_service_status_flagged + data_type: bigint + description: "Number of bookings with status FLAGGED for this service." - name: core__payments description: |