From 1a7579c8a850d99a6ca522ec7457e3b11850eaaa Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 7 Feb 2025 08:34:20 +0100 Subject: [PATCH 1/9] Commit wip --- .../int_core__new_dash_services_usage.sql | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 models/intermediate/core/int_core__new_dash_services_usage.sql diff --git a/models/intermediate/core/int_core__new_dash_services_usage.sql b/models/intermediate/core/int_core__new_dash_services_usage.sql new file mode 100644 index 0000000..17aba21 --- /dev/null +++ b/models/intermediate/core/int_core__new_dash_services_usage.sql @@ -0,0 +1,93 @@ +with + int_core__user_product_bundle_contains_services as ( + select * from {{ ref("int_core__user_product_bundle_contains_services") }} + ), + int_core__user_host as (select * from {{ ref("int_core__user_host") }}), + int_core__accommodation_to_product_bundle as ( + select * from {{ ref("int_core__accommodation_to_product_bundle") }} + ), + int_core__accommodation as (select * from {{ ref("int_core__accommodation") }}), + 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") }}), + users as ( + select distinct + (bs.product_service_name), count(distinct bs.id_user_host) as number_users + from int_core__user_product_bundle_contains_services bs + inner join + int_core__user_host uh + on bs.id_user_host = uh.id_user_host + and uh.is_test_account is false + group by 1 + ), + accommodations as ( + select distinct + (bs.product_service_name), + count(distinct apb.id_accommodation) as number_accommodations, + count( + distinct case when a.is_active then apb.id_accommodation else null end + ) as number_active_accommodations, + count( + distinct case + when a.is_active is false then apb.id_accommodation else null + end + ) as number_inactive_accommodations + from int_core__user_product_bundle_contains_services bs + left join + int_core__accommodation_to_product_bundle apb + on apb.id_user_product_bundle = bs.id_user_product_bundle + and now() between apb.original_starts_at_utc and coalesce( + apb.original_ends_at_utc, '2050-12-31' + ) + left join int_core__accommodation a on apb.id_accommodation = a.id_accommodation + group by 1 + ), + bookings as ( + select distinct + (bs.product_service_name), + count(distinct bpb.id_booking) as number_bookings, + count( + distinct case + when upper(b.booking_state) = 'APPROVED' + then bpb.id_booking + else null + end + ) as number_approved_bookings, + count( + distinct case + when upper(b.booking_state) = 'CANCELLED' + then bpb.id_booking + else null + end + ) as number_cancelled_bookings, + count( + distinct case + when upper(b.booking_state) = 'FLAGGED' + then bpb.id_booking + else null + end + ) as number_flagged_bookings + from int_core__user_product_bundle_contains_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 + group by 1 + ) +select + u.product_service_name, + u.number_users, + a.number_accommodations, + a.number_active_accommodations, + a.number_inactive_accommodations, + b.number_bookings, + b.number_approved_bookings, + b.number_cancelled_bookings, + b.number_flagged_bookings +from users u +left join accommodations a on u.product_service_name = a.product_service_name +left join bookings b on u.product_service_name = b.product_service_name From 78e005e8fa71be8b1eeea148d85c67f8be22f3d6 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 7 Feb 2025 12:37:32 +0100 Subject: [PATCH 2/9] New dash service usage model --- .../int_core__new_dash_services_usage.sql | 21 +++++- models/intermediate/core/schema.yml | 73 +++++++++++++++++++ .../core/stg_core__user_product_bundle.sql | 2 +- 3 files changed, 92 insertions(+), 4 deletions(-) diff --git a/models/intermediate/core/int_core__new_dash_services_usage.sql b/models/intermediate/core/int_core__new_dash_services_usage.sql index 17aba21..7161805 100644 --- a/models/intermediate/core/int_core__new_dash_services_usage.sql +++ b/models/intermediate/core/int_core__new_dash_services_usage.sql @@ -2,6 +2,9 @@ with int_core__user_product_bundle_contains_services as ( select * from {{ ref("int_core__user_product_bundle_contains_services") }} ), + int_core__user_product_bundle as ( + select * from {{ ref("int_core__user_product_bundle") }} + ), int_core__user_host as (select * from {{ ref("int_core__user_host") }}), int_core__accommodation_to_product_bundle as ( select * from {{ ref("int_core__accommodation_to_product_bundle") }} @@ -11,10 +14,22 @@ with select * from {{ ref("int_core__booking_to_product_bundle") }} ), int_core__bookings as (select * from {{ ref("int_core__bookings") }}), + bundle_services as ( + select id_user_product_bundle, id_user_host, product_service_name + from int_core__user_product_bundle_contains_services + union all + select + id_user_product_bundle, + id_user_host, + coalesce( + replace(protection_display_name, ' ', ''), 'BASICSCREENING' + ) as product_service_name + from int_core__user_product_bundle + ), users as ( select distinct (bs.product_service_name), count(distinct bs.id_user_host) as number_users - from int_core__user_product_bundle_contains_services bs + from bundle_services bs inner join int_core__user_host uh on bs.id_user_host = uh.id_user_host @@ -33,7 +48,7 @@ with when a.is_active is false then apb.id_accommodation else null end ) as number_inactive_accommodations - from int_core__user_product_bundle_contains_services bs + from bundle_services bs left join int_core__accommodation_to_product_bundle apb on apb.id_user_product_bundle = bs.id_user_product_bundle @@ -68,7 +83,7 @@ with else null end ) as number_flagged_bookings - from int_core__user_product_bundle_contains_services bs + from bundle_services bs left join int_core__booking_to_product_bundle bpb on bpb.id_user_product_bundle = bs.id_user_product_bundle diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index b8be2dd..c56a0ad 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -5165,3 +5165,76 @@ models: - name: chose_checkin_cover data_type: boolean description: "Boolean value indicating if the guest chose CheckIn Cover." + + - name: int_core__new_dash_services_usage + description: "This model contains the usage of the services in New Dash. + This usage is displayed by different levels, such as the number of users, + accommodations and bookings." + + columns: + - name: product_service_name + data_type: text + description: "The name of the product service." + data_tests: + - not_null + - accepted_values: + values: + - "BASICSCREENING" + - "SCREENINGPLUS" + - "IDVERIFICATION" + - "SEXOFFENDERSCHECK" + - "BASICDAMAGEDEPOSIT" + - "BASICWAIVER" + - "WAIVERPLUS" + - "WAIVERPRO" + - "BASICPROTECTION" + - "PROTECTIONPLUS" + - "PROTECTIONPRO" + + - name: number_users + data_type: bigint + description: + "Number of user accounts that have a bundle that considers this service. + The fact that a user has a bundle with the service included does not mean + that the service is active or used. Each user can associate any of their + bundles with any of their accommodations." + + - name: number_accommodations + data_type: bigint + description: + "Number of accommodations or listings that have a bundle that considers + this service." + + - name: number_active_accommodations + data_type: bigint + description: + "Number of accommodations or listings that have a bundle that considers + this service and are active." + + - name: number_inactive_accommodations + data_type: bigint + description: + "Number of accommodations or listings that have a bundle that considers + this service and are inactive." + + - name: number_bookings + data_type: bigint + description: "Number of bookings that have a bundle that considers this service." + + - name: number_approved_bookings + data_type: bigint + description: + "Number of bookings that have a bundle that considers this service and + are approved." + + - name: number_cancelled_bookings + data_type: bigint + description: + "Number of bookings that have a bundle that considers this service and + are cancelled." + + - name: number_flagged_bookings + data_type: bigint + description: + "Number of bookings that have a bundle that considers this service and + are flagged." diff --git a/models/staging/core/stg_core__user_product_bundle.sql b/models/staging/core/stg_core__user_product_bundle.sql index fcf8280..05027e0 100644 --- a/models/staging/core/stg_core__user_product_bundle.sql +++ b/models/staging/core/stg_core__user_product_bundle.sql @@ -1,4 +1,4 @@ -with +id_with raw_user_product_bundle as ( select * from {{ source("core", "UserProductBundle") }} ), From 1c6f23f269c7e6e72f0273d44d703327b32a7fdf Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 7 Feb 2025 12:40:22 +0100 Subject: [PATCH 3/9] fix commit --- models/staging/core/stg_core__user_product_bundle.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/staging/core/stg_core__user_product_bundle.sql b/models/staging/core/stg_core__user_product_bundle.sql index 05027e0..fcf8280 100644 --- a/models/staging/core/stg_core__user_product_bundle.sql +++ b/models/staging/core/stg_core__user_product_bundle.sql @@ -1,4 +1,4 @@ -id_with +with raw_user_product_bundle as ( select * from {{ source("core", "UserProductBundle") }} ), From 25a89208c45ed32b7133c42ef487fa6caace7ed4 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 7 Feb 2025 15:15:17 +0100 Subject: [PATCH 4/9] Addressed comments --- dbt_project.yml | 12 +++ ...> int_core__new_dash_services_offered.sql} | 37 ++++++---- .../core/int_core__new_dash_user_overview.sql | 7 +- ..._user_product_bundle_contains_services.sql | 3 +- models/intermediate/core/schema.yml | 37 ++++++---- .../core/core__new_dash_services_offered.sql | 15 ++++ models/reporting/core/schema.yml | 73 +++++++++++++++++++ 7 files changed, 148 insertions(+), 36 deletions(-) rename models/intermediate/core/{int_core__new_dash_services_usage.sql => int_core__new_dash_services_offered.sql} (70%) create mode 100644 models/reporting/core/core__new_dash_services_offered.sql diff --git a/dbt_project.yml b/dbt_project.yml index 66b8d79..f92b14c 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -69,6 +69,18 @@ vars: # States should be strings in capital letters. Models need to force an upper() "cancelled_booking_state": "'CANCELLED'" + # Booking state variables + # States should be strings in capital letters. Models need to force an upper() + "approved_booking_state": "'APPROVED'" + + # Booking state variables + # States should be strings in capital letters. Models need to force an upper() + "flagged_booking_state": "'FLAGGED'" + # Payment state variables # States should be strings in capital letters. Models need to force an upper() "paid_payment_state": "'PAID'" + + # Protection service state variables + # States should be strings in capital letters. Models need to force an upper() + "default_service": "'BASIC SCREENING'" diff --git a/models/intermediate/core/int_core__new_dash_services_usage.sql b/models/intermediate/core/int_core__new_dash_services_offered.sql similarity index 70% rename from models/intermediate/core/int_core__new_dash_services_usage.sql rename to models/intermediate/core/int_core__new_dash_services_offered.sql index 7161805..829194e 100644 --- a/models/intermediate/core/int_core__new_dash_services_usage.sql +++ b/models/intermediate/core/int_core__new_dash_services_offered.sql @@ -9,36 +9,38 @@ with int_core__accommodation_to_product_bundle as ( select * from {{ ref("int_core__accommodation_to_product_bundle") }} ), + int_core__new_dash_users as (select * from {{ ref("int_core__new_dash_users") }}), int_core__accommodation as (select * from {{ ref("int_core__accommodation") }}), 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") }}), bundle_services as ( - select id_user_product_bundle, id_user_host, product_service_name + select id_user_product_bundle, id_user_host, product_service_display_name from int_core__user_product_bundle_contains_services + -- Union of all product services with all protection plan services. + -- This is because there are basically two types of services: product services + -- and protection plan services and they are stored in different tables. union all select id_user_product_bundle, id_user_host, coalesce( - replace(protection_display_name, ' ', ''), 'BASICSCREENING' - ) as product_service_name + protection_display_name, {{ var("default_service") }} + ) as product_service_display_name from int_core__user_product_bundle ), users as ( select distinct - (bs.product_service_name), count(distinct bs.id_user_host) as number_users + (bs.product_service_display_name), + count(distinct bs.id_user_host) as number_users from bundle_services bs - inner join - int_core__user_host uh - on bs.id_user_host = uh.id_user_host - and uh.is_test_account is false + inner join int_core__user_host uh on bs.id_user_host = uh.id_user_host group by 1 ), accommodations as ( select distinct - (bs.product_service_name), + (bs.product_service_display_name), count(distinct apb.id_accommodation) as number_accommodations, count( distinct case when a.is_active then apb.id_accommodation else null end @@ -56,29 +58,30 @@ with apb.original_ends_at_utc, '2050-12-31' ) left join int_core__accommodation a on apb.id_accommodation = a.id_accommodation + inner join int_core__new_dash_users ndu on bs.id_user_host = ndu.id_user_host group by 1 ), bookings as ( select distinct - (bs.product_service_name), + (bs.product_service_display_name), count(distinct bpb.id_booking) as number_bookings, count( distinct case - when upper(b.booking_state) = 'APPROVED' + when upper(b.booking_state) = {{ var("approved_booking_state") }} then bpb.id_booking else null end ) as number_approved_bookings, count( distinct case - when upper(b.booking_state) = 'CANCELLED' + when upper(b.booking_state) = {{ var("cancelled_booking_state") }} then bpb.id_booking else null end ) as number_cancelled_bookings, count( distinct case - when upper(b.booking_state) = 'FLAGGED' + when upper(b.booking_state) = {{ var("flagged_booking_state") }} then bpb.id_booking else null end @@ -91,10 +94,11 @@ with int_core__bookings b on b.id_booking = bpb.id_booking and b.is_duplicate_booking is false + inner join int_core__new_dash_users ndu on bs.id_user_host = ndu.id_user_host group by 1 ) select - u.product_service_name, + u.product_service_display_name, u.number_users, a.number_accommodations, a.number_active_accommodations, @@ -104,5 +108,6 @@ select b.number_cancelled_bookings, b.number_flagged_bookings from users u -left join accommodations a on u.product_service_name = a.product_service_name -left join bookings b on u.product_service_name = b.product_service_name +left join + accommodations a on u.product_service_display_name = a.product_service_display_name +left join bookings b on u.product_service_display_name = b.product_service_display_name diff --git a/models/intermediate/core/int_core__new_dash_user_overview.sql b/models/intermediate/core/int_core__new_dash_user_overview.sql index 7fa2e24..a719f18 100644 --- a/models/intermediate/core/int_core__new_dash_user_overview.sql +++ b/models/intermediate/core/int_core__new_dash_user_overview.sql @@ -1,4 +1,3 @@ -{% set product_bundles_without_paid_service = "('BASIC SCREENING')" %} with int_core__user_product_bundle as ( select * from {{ ref("int_core__user_product_bundle") }} @@ -43,7 +42,7 @@ with distinct case when atpb.user_product_bundle_name - not in {{ product_bundles_without_paid_service }} + not in ({{ var("default_service") }}) then atpb.id_accommodation else null end @@ -52,7 +51,7 @@ with distinct case when atpb.user_product_bundle_name - not in {{ product_bundles_without_paid_service }} + not in ({{ var("default_service") }}) and atpb.has_no_end_date = true then atpb.id_accommodation else null @@ -72,7 +71,7 @@ with distinct case when btpb.user_product_bundle_name - not in {{ product_bundles_without_paid_service }} + not in ({{ var("default_service") }}) then btpb.id_booking else null end diff --git a/models/intermediate/core/int_core__user_product_bundle_contains_services.sql b/models/intermediate/core/int_core__user_product_bundle_contains_services.sql index cdd3b8f..5dd9363 100644 --- a/models/intermediate/core/int_core__user_product_bundle_contains_services.sql +++ b/models/intermediate/core/int_core__user_product_bundle_contains_services.sql @@ -11,7 +11,8 @@ select pb.id_product_bundle, ps.id_product_service, pb.product_bundle_name, - ps.product_service_name + ps.product_service_name, + ps.product_service_display_name from stg_core__user_product_bundle pb cross join stg_core__product_service ps where diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index c56a0ad..7267fe4 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -3023,6 +3023,13 @@ models: data_tests: - not_null + - name: product_service_display_name + data_type: string + description: | + The display name of the product service. + data_tests: + - not_null + - name: int_core__product_service_to_price description: | This model provides the information related to the prices of the different @@ -5166,30 +5173,30 @@ models: data_type: boolean description: "Boolean value indicating if the guest chose CheckIn Cover." - - name: int_core__new_dash_services_usage - description: "This model contains the usage of the services in New Dash. - This usage is displayed by different levels, such as the number of users, + - name: int_core__new_dash_services_offered + description: "This model contains the the services offered in New Dash. + This offers are displayed by different levels, such as the number of users, accommodations and bookings." columns: - - name: product_service_name + - name: product_service_display_name data_type: text description: "The name of the product service." data_tests: - not_null - accepted_values: values: - - "BASICSCREENING" - - "SCREENINGPLUS" - - "IDVERIFICATION" - - "SEXOFFENDERSCHECK" - - "BASICDAMAGEDEPOSIT" - - "BASICWAIVER" - - "WAIVERPLUS" - - "WAIVERPRO" - - "BASICPROTECTION" - - "PROTECTIONPLUS" - - "PROTECTIONPRO" + - "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 diff --git a/models/reporting/core/core__new_dash_services_offered.sql b/models/reporting/core/core__new_dash_services_offered.sql new file mode 100644 index 0000000..dabcafc --- /dev/null +++ b/models/reporting/core/core__new_dash_services_offered.sql @@ -0,0 +1,15 @@ +with + int_core__new_dash_services_offered as ( + select * from {{ ref("int_core__new_dash_services_offered") }} + ) +select + product_service_display_name as product_service_display_name, + number_users as number_users, + number_accommodations as number_accommodations, + 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 +from int_core__new_dash_services_offered diff --git a/models/reporting/core/schema.yml b/models/reporting/core/schema.yml index 1bd106a..a28ea10 100644 --- a/models/reporting/core/schema.yml +++ b/models/reporting/core/schema.yml @@ -1567,3 +1567,76 @@ models: - name: chose_checkin_cover data_type: boolean description: "Boolean value indicating if the guest chose CheckIn Cover." + + - name: core__new_dash_services_offered + description: "This model contains the the services offered in New Dash. + This offers are displayed by different levels, such as the number of users, + accommodations and bookings." + + columns: + - name: product_service_display_name + data_type: text + description: "The name of the product 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 + description: + "Number of user accounts that have a bundle that considers this service. + The fact that a user has a bundle with the service included does not mean + that the service is active or used. Each user can associate any of their + bundles with any of their accommodations." + + - name: number_accommodations + data_type: bigint + description: + "Number of accommodations or listings that have a bundle that considers + this service." + + - name: number_active_accommodations + data_type: bigint + description: + "Number of accommodations or listings that have a bundle that considers + this service and are active." + + - name: number_inactive_accommodations + data_type: bigint + description: + "Number of accommodations or listings that have a bundle that considers + this service and are inactive." + + - name: number_bookings + data_type: bigint + description: "Number of bookings that have a bundle that considers this service." + + - name: number_approved_bookings + data_type: bigint + description: + "Number of bookings that have a bundle that considers this service and + are approved." + + - name: number_cancelled_bookings + data_type: bigint + description: + "Number of bookings that have a bundle that considers this service and + are cancelled." + + - name: number_flagged_bookings + data_type: bigint + description: + "Number of bookings that have a bundle that considers this service and + are flagged." From 25aa153eed7f0cedc800b21572b9ce8ff65be727 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Fri, 7 Feb 2025 15:20:22 +0100 Subject: [PATCH 5/9] Added end_of_time variable --- dbt_project.yml | 3 +++ .../intermediate/core/int_core__new_dash_services_offered.sql | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/dbt_project.yml b/dbt_project.yml index f92b14c..94fd499 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -65,6 +65,9 @@ vars: # KPIs Start Date. This is the date from which we start calculating KPIs. "kpis_start_date": "'2022-04-01'" + # A distant future date to use as a default when cutoff values are missing. + "end_of_time": "'2050-12-31'" + # Booking state variables # States should be strings in capital letters. Models need to force an upper() "cancelled_booking_state": "'CANCELLED'" 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 829194e..33bcbc1 100644 --- a/models/intermediate/core/int_core__new_dash_services_offered.sql +++ b/models/intermediate/core/int_core__new_dash_services_offered.sql @@ -55,7 +55,7 @@ with int_core__accommodation_to_product_bundle apb on apb.id_user_product_bundle = bs.id_user_product_bundle and now() between apb.original_starts_at_utc and coalesce( - apb.original_ends_at_utc, '2050-12-31' + apb.original_ends_at_utc, {{ var("end_of_time") }} ) left join int_core__accommodation a on apb.id_accommodation = a.id_accommodation inner join int_core__new_dash_users ndu on bs.id_user_host = ndu.id_user_host From 560531aa1efa7adb3ee75bb10b9a428eb7c2464d Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 10 Feb 2025 08:09:22 +0100 Subject: [PATCH 6/9] Addressed comments --- dbt_project.yml | 6 --- .../int_core__new_dash_services_offered.sql | 42 +++++++++++++------ models/intermediate/core/schema.yml | 6 +-- .../core/core__new_dash_services_offered.sql | 2 +- models/reporting/core/schema.yml | 6 +-- 5 files changed, 36 insertions(+), 26 deletions(-) diff --git a/dbt_project.yml b/dbt_project.yml index 94fd499..529ec70 100644 --- a/dbt_project.yml +++ b/dbt_project.yml @@ -71,13 +71,7 @@ vars: # Booking state variables # States should be strings in capital letters. Models need to force an upper() "cancelled_booking_state": "'CANCELLED'" - - # Booking state variables - # States should be strings in capital letters. Models need to force an upper() "approved_booking_state": "'APPROVED'" - - # Booking state variables - # States should be strings in capital letters. Models need to force an upper() "flagged_booking_state": "'FLAGGED'" # Payment state variables 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 33bcbc1..784a4bd 100644 --- a/models/intermediate/core/int_core__new_dash_services_offered.sql +++ b/models/intermediate/core/int_core__new_dash_services_offered.sql @@ -16,7 +16,10 @@ with ), int_core__bookings as (select * from {{ ref("int_core__bookings") }}), bundle_services as ( - select id_user_product_bundle, id_user_host, product_service_display_name + select + id_user_product_bundle, + id_user_host, + product_service_name as service_display_name from int_core__user_product_bundle_contains_services -- Union of all product services with all protection plan services. -- This is because there are basically two types of services: product services @@ -27,20 +30,24 @@ with id_user_host, coalesce( protection_display_name, {{ var("default_service") }} - ) as product_service_display_name + ) as service_display_name from int_core__user_product_bundle ), users as ( select distinct - (bs.product_service_display_name), - count(distinct bs.id_user_host) as number_users + bs.service_display_name, count(distinct bs.id_user_host) as number_users from bundle_services bs - inner join int_core__user_host uh on bs.id_user_host = uh.id_user_host + inner join + int_core__user_host uh + on bs.id_user_host = uh.id_user_host + and uh.is_user_in_new_dash = true + and uh.is_missing_id_deal = false + and uh.is_test_account = false group by 1 ), accommodations as ( select distinct - (bs.product_service_display_name), + bs.service_display_name, count(distinct apb.id_accommodation) as number_accommodations, count( distinct case when a.is_active then apb.id_accommodation else null end @@ -58,12 +65,17 @@ with apb.original_ends_at_utc, {{ var("end_of_time") }} ) left join int_core__accommodation a on apb.id_accommodation = a.id_accommodation - inner join int_core__new_dash_users ndu on bs.id_user_host = ndu.id_user_host + inner join + int_core__user_host uh + on bs.id_user_host = uh.id_user_host + and uh.is_user_in_new_dash = true + and uh.is_missing_id_deal = false + and uh.is_test_account = false group by 1 ), bookings as ( select distinct - (bs.product_service_display_name), + bs.service_display_name, count(distinct bpb.id_booking) as number_bookings, count( distinct case @@ -94,11 +106,16 @@ with int_core__bookings b on b.id_booking = bpb.id_booking and b.is_duplicate_booking is false - inner join int_core__new_dash_users ndu on bs.id_user_host = ndu.id_user_host + inner join + int_core__user_host uh + on bs.id_user_host = uh.id_user_host + and uh.is_user_in_new_dash = true + and uh.is_missing_id_deal = false + and uh.is_test_account = false group by 1 ) select - u.product_service_display_name, + u.service_display_name, u.number_users, a.number_accommodations, a.number_active_accommodations, @@ -108,6 +125,5 @@ select b.number_cancelled_bookings, b.number_flagged_bookings from users u -left join - accommodations a on u.product_service_display_name = a.product_service_display_name -left join bookings b on u.product_service_display_name = b.product_service_display_name +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 diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index 7267fe4..ed75db2 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -5175,13 +5175,13 @@ models: - name: int_core__new_dash_services_offered description: "This model contains the the services offered in New Dash. - This offers are displayed by different levels, such as the number of users, + These offers are displayed by different levels, such as the number of users, accommodations and bookings." columns: - - name: product_service_display_name + - name: service_display_name data_type: text - description: "The name of the product service." + description: "The name of the New Dash service." data_tests: - not_null - accepted_values: diff --git a/models/reporting/core/core__new_dash_services_offered.sql b/models/reporting/core/core__new_dash_services_offered.sql index dabcafc..78e870f 100644 --- a/models/reporting/core/core__new_dash_services_offered.sql +++ b/models/reporting/core/core__new_dash_services_offered.sql @@ -3,7 +3,7 @@ with select * from {{ ref("int_core__new_dash_services_offered") }} ) select - product_service_display_name as product_service_display_name, + service_display_name as service_display_name, number_users as number_users, number_accommodations as number_accommodations, number_active_accommodations as number_active_accommodations, diff --git a/models/reporting/core/schema.yml b/models/reporting/core/schema.yml index a28ea10..7be6992 100644 --- a/models/reporting/core/schema.yml +++ b/models/reporting/core/schema.yml @@ -1570,13 +1570,13 @@ models: - name: core__new_dash_services_offered description: "This model contains the the services offered in New Dash. - This offers are displayed by different levels, such as the number of users, + These offers are displayed by different levels, such as the number of users, accommodations and bookings." columns: - - name: product_service_display_name + - name: service_display_name data_type: text - description: "The name of the product service." + description: "The name of the New Dash service." data_tests: - not_null - accepted_values: From 191f837a698f3e040c74d95918f4b6b7a33338fc Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 10 Feb 2025 08:14:02 +0100 Subject: [PATCH 7/9] small fix display_name --- .../intermediate/core/int_core__new_dash_services_offered.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 784a4bd..499cbe9 100644 --- a/models/intermediate/core/int_core__new_dash_services_offered.sql +++ b/models/intermediate/core/int_core__new_dash_services_offered.sql @@ -19,7 +19,7 @@ with select id_user_product_bundle, id_user_host, - product_service_name as service_display_name + product_service_display_name as service_display_name from int_core__user_product_bundle_contains_services -- Union of all product services with all protection plan services. -- This is because there are basically two types of services: product services From e39e17fd212d8c56445ce2cb35d67c85410ecac3 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 10 Feb 2025 08:18:11 +0100 Subject: [PATCH 8/9] finished schema --- models/intermediate/core/schema.yml | 2 +- models/reporting/core/schema.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/models/intermediate/core/schema.yml b/models/intermediate/core/schema.yml index ed75db2..a7e207f 100644 --- a/models/intermediate/core/schema.yml +++ b/models/intermediate/core/schema.yml @@ -5175,7 +5175,7 @@ models: - name: int_core__new_dash_services_offered description: "This model contains the the services offered in New Dash. - These offers are displayed by different levels, such as the number of users, + These offers are displayed by different measures, such as the number of users, accommodations and bookings." columns: diff --git a/models/reporting/core/schema.yml b/models/reporting/core/schema.yml index 7be6992..40aad3e 100644 --- a/models/reporting/core/schema.yml +++ b/models/reporting/core/schema.yml @@ -1570,7 +1570,7 @@ models: - name: core__new_dash_services_offered description: "This model contains the the services offered in New Dash. - These offers are displayed by different levels, such as the number of users, + These offers are displayed by different measures, such as the number of users, accommodations and bookings." columns: From ed696488bf0a183b39d817d191d371fb81476cc2 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Mon, 10 Feb 2025 14:57:46 +0100 Subject: [PATCH 9/9] Updated --- .../int_core__new_dash_services_offered.sql | 59 ++++++++----------- 1 file changed, 26 insertions(+), 33 deletions(-) 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 499cbe9..fd747bd 100644 --- a/models/intermediate/core/int_core__new_dash_services_offered.sql +++ b/models/intermediate/core/int_core__new_dash_services_offered.sql @@ -9,7 +9,6 @@ with int_core__accommodation_to_product_bundle as ( select * from {{ ref("int_core__accommodation_to_product_bundle") }} ), - int_core__new_dash_users as (select * from {{ ref("int_core__new_dash_users") }}), int_core__accommodation as (select * from {{ ref("int_core__accommodation") }}), int_core__booking_to_product_bundle as ( select * from {{ ref("int_core__booking_to_product_bundle") }} @@ -17,32 +16,38 @@ with int_core__bookings as (select * from {{ ref("int_core__bookings") }}), bundle_services as ( select - id_user_product_bundle, - id_user_host, - product_service_display_name as service_display_name - from int_core__user_product_bundle_contains_services - -- Union of all product services with all protection plan services. - -- This is because there are basically two types of services: product services - -- and protection plan services and they are stored in different tables. - union all - select - id_user_product_bundle, - id_user_host, - coalesce( - protection_display_name, {{ var("default_service") }} - ) as service_display_name - from int_core__user_product_bundle - ), - users as ( - select distinct - bs.service_display_name, count(distinct bs.id_user_host) as number_users - from bundle_services bs + bs.id_user_product_bundle, + bs.id_user_host, + bs.product_service_display_name as service_display_name + from int_core__user_product_bundle_contains_services bs inner join int_core__user_host uh on bs.id_user_host = uh.id_user_host and uh.is_user_in_new_dash = true and uh.is_missing_id_deal = false and uh.is_test_account = false + -- Union of all product services with all protection plan services. + -- This is because there are basically two types of services: product services + -- and protection plan services and they are stored in different tables. + union all + select + pb.id_user_product_bundle, + pb.id_user_host, + coalesce( + pb.protection_display_name, {{ var("default_service") }} + ) as service_display_name + from int_core__user_product_bundle pb + inner join + int_core__user_host uh + on pb.id_user_host = uh.id_user_host + and uh.is_user_in_new_dash = true + and uh.is_missing_id_deal = false + and uh.is_test_account = false + ), + users as ( + select distinct + bs.service_display_name, count(distinct bs.id_user_host) as number_users + from bundle_services bs group by 1 ), accommodations as ( @@ -65,12 +70,6 @@ with apb.original_ends_at_utc, {{ var("end_of_time") }} ) left join int_core__accommodation a on apb.id_accommodation = a.id_accommodation - inner join - int_core__user_host uh - on bs.id_user_host = uh.id_user_host - and uh.is_user_in_new_dash = true - and uh.is_missing_id_deal = false - and uh.is_test_account = false group by 1 ), bookings as ( @@ -106,12 +105,6 @@ with int_core__bookings b on b.id_booking = bpb.id_booking and b.is_duplicate_booking is false - inner join - int_core__user_host uh - on bs.id_user_host = uh.id_user_host - and uh.is_user_in_new_dash = true - and uh.is_missing_id_deal = false - and uh.is_test_account = false group by 1 ) select