Updated model

This commit is contained in:
Joaquin Ossa 2025-02-13 17:13:05 +01:00
parent 68c21458c2
commit a00a4b4e4b
6 changed files with 229 additions and 170 deletions

View file

@ -16,34 +16,6 @@ with
int_core__booking_service_detail as (
select * from {{ ref("int_core__booking_service_detail") }}
),
int_core__bookings as (select * from {{ ref("int_core__bookings") }}),
expanded_booking_services as (
select distinct
id_booking,
trim(unnested_service) as service_name,
service_status,
service_detail_updated_at_utc
from
int_core__booking_service_detail,
lateral unnest(string_to_array(service_name, ' OR ')) as unnested_service
),
ranked_booking_services as (
select
id_booking,
service_name,
service_status,
service_detail_updated_at_utc,
row_number() over (
partition by id_booking, service_name
order by service_detail_updated_at_utc desc -- Prioritize the most recent date
) as row_num
from expanded_booking_services
),
unnested_booking_services as (
select id_booking, service_name, service_status
from ranked_booking_services
where row_num = 1
),
bundle_services as (
select
bs.id_user_product_bundle,
@ -75,7 +47,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.
@ -96,7 +68,7 @@ with
group by 1
),
accommodations as (
select distinct
select
bs.service_display_name,
count(distinct apb.id_accommodation) as number_accommodations,
count(
@ -119,14 +91,113 @@ with
),
bookings as (
select
ub.service_name as service_display_name,
count(distinct ub.id_booking) as number_bookings,
{{ count_bookings_by_service_status() }}
from unnested_booking_services ub
sd.service_name as service_display_name,
count(distinct sd.id_booking) as number_bookings,
count(
distinct case
when
upper(sd.service_status) = {{ var("protected_service_status") }}
then sd.id_booking
else null
end
) as number_protected_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("rejected_service_status") }}
then sd.id_booking
else null
end
) as number_rejected_bookings,
count(
distinct case
when
upper(sd.service_status) = {{ var("no_checks_service_status") }}
then sd.id_booking
else null
end
) as number_no_checks_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("no_flags_service_status") }}
then sd.id_booking
else null
end
) as number_no_flags_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("paid_service_status") }}
then sd.id_booking
else null
end
) as number_paid_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("pending_service_status") }}
then sd.id_booking
else null
end
) as number_pending_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("unknown_service_status") }}
then sd.id_booking
else null
end
) as number_unknown_status_bookings,
count(
distinct case
when
upper(sd.service_status)
= {{ var("partially_protected_service_status") }}
then sd.id_booking
else null
end
) as number_partially_protected_bookings,
count(
distinct case
when
upper(sd.service_status)
= {{ var("not_protected_service_status") }}
then sd.id_booking
else null
end
) as number_not_protected_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("not_paid_service_status") }}
then sd.id_booking
else null
end
) as number_not_paid_bookings,
count(
distinct case
when
upper(sd.service_status) = {{ var("confirmed_service_status") }}
then sd.id_booking
else null
end
) as number_confirmed_bookings,
count(
distinct case
when
upper(sd.service_status)
= {{ var("for_review_service_status") }}
then sd.id_booking
else null
end
) as number_for_review_bookings,
count(
distinct case
when upper(sd.service_status) = {{ var("flagged_service_status") }}
then sd.id_booking
else null
end
) as number_flagged_bookings
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
@ -151,4 +222,4 @@ select
b.number_flagged_bookings
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

View file

@ -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_protected_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."
- name: number_incomplete_information_bookings
data_type: bigint
description:
"Number of bookings that have a bundle that considers this service and
have incomplete information."
- name: number_no_flags_bookings
data_type: bigint
description:
"Number of bookings that have a bundle that considers this service and
have no flags."
- name: number_not_approved_bookings
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 PROTECTED for this service."
- name: number_rejected_bookings
data_type: bigint
description:
"Number of bookings that have a bundle that considers this service and
are rejected."
description: "Number of bookings with status REJECTED for this service."
- name: number_no_checks_bookings
data_type: bigint
description: "Number of bookings with status NO CHECKS for this service."
- name: number_no_flags_bookings
data_type: bigint
description: "Number of bookings with status NO FLAGS for this service."
- name: number_paid_bookings
data_type: bigint
description: "Number of bookings with status PAID for this service."
- name: number_pending_bookings
data_type: bigint
description: "Number of bookings with status PENDING for this service."
- name: number_unknown_status_bookings
data_type: bigint
description: "Number of bookings with unknown status for this service."
- name: number_partially_protected_bookings
data_type: bigint
description: "Number of bookings with status PARTIALLY PROTECTED for this service."
- name: number_not_protected_bookings
data_type: bigint
description: "Number of bookings with status NOT PROTECTED for this service."
- name: number_not_paid_bookings
data_type: bigint
description: "Number of bookings with status NOT PAID for this service."
- name: number_confirmed_bookings
data_type: bigint
description: "Number of bookings with status CONFIRMED for this service."
- name: number_for_review_bookings
data_type: bigint
description: "Number of bookings with status FOR REVIEW for this service."
- name: number_flagged_bookings
data_type: bigint
description: "Number of bookings with status FLAGGED for this service."
- name: int_core__payments
description: |

View file

@ -13,11 +13,17 @@ 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_protected_bookings as number_protected_bookings,
number_rejected_bookings as number_rejected_bookings,
number_no_checks_bookings as number_no_checks_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_paid_bookings as number_paid_bookings,
number_pending_bookings as number_pending_bookings,
number_unknown_status_bookings as number_unknown_status_bookings,
number_partially_protected_bookings as number_partially_protected_bookings,
number_not_protected_bookings as number_not_protected_bookings,
number_not_paid_bookings as number_not_paid_bookings,
number_confirmed_bookings as number_confirmed_bookings,
number_for_review_bookings as number_for_review_bookings,
number_flagged_bookings as number_flagged_bookings
from int_core__new_dash_services_offered

View file

@ -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_protected_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."
- name: number_incomplete_information_bookings
data_type: bigint
description:
"Number of bookings that have a bundle that considers this service and
have incomplete information."
- name: number_no_flags_bookings
data_type: bigint
description:
"Number of bookings that have a bundle that considers this service and
have no flags."
- name: number_not_approved_bookings
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 PROTECTED for this service."
- name: number_rejected_bookings
data_type: bigint
description:
"Number of bookings that have a bundle that considers this service and
are rejected."
description: "Number of bookings with status REJECTED for this service."
- name: number_no_checks_bookings
data_type: bigint
description: "Number of bookings with status NO CHECKS for this service."
- name: number_no_flags_bookings
data_type: bigint
description: "Number of bookings with status NO FLAGS for this service."
- name: number_paid_bookings
data_type: bigint
description: "Number of bookings with status PAID for this service."
- name: number_pending_bookings
data_type: bigint
description: "Number of bookings with status PENDING for this service."
- name: number_unknown_status_bookings
data_type: bigint
description: "Number of bookings with unknown status for this service."
- name: number_partially_protected_bookings
data_type: bigint
description: "Number of bookings with status PARTIALLY PROTECTED for this service."
- name: number_not_protected_bookings
data_type: bigint
description: "Number of bookings with status NOT PROTECTED for this service."
- name: number_not_paid_bookings
data_type: bigint
description: "Number of bookings with status NOT PAID for this service."
- name: number_confirmed_bookings
data_type: bigint
description: "Number of bookings with status CONFIRMED for this service."
- name: number_for_review_bookings
data_type: bigint
description: "Number of bookings with status FOR REVIEW for this service."
- name: number_flagged_bookings
data_type: bigint
description: "Number of bookings with status FLAGGED for this service."
- name: core__payments
description: |