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

@ -81,6 +81,22 @@ vars:
"not_approved_booking_state": "'NOTAPPROVED'"
"rejected_booking_state": "'REJECTED'"
# New Dash services status variables
# Status should be strings in capital letters. Models need to force an upper()
"protected_service_status": "'PROTECTED'"
"rejected_service_status": "'REJECTED'"
"no_checks_service_status": "'NOCHECKS'"
"no_flags_service_status": "'NOFLAGS'"
"paid_service_status": "'PAID'"
"pending_service_status": "'PENDING'"
"unknown_service_status": "'-'"
"partially_protected_service_status": "'PARTIALLY PROTECTED'"
"not_protected_service_status": "'NOT PROTECTED'"
"not_paid_service_status": "'NOT PAID'"
"confirmed_service_status": "'CONFIRMED'"
"for_review_service_status": "'FORREVIEW'"
"flagged_service_status": "'FLAGGED'"
# Payment state variables
# States should be strings in capital letters. Models need to force an upper()
"paid_payment_state": "'PAID'"

View file

@ -1,28 +0,0 @@
{% macro count_bookings_by_service_status() %}
{% set service_status_map = {
"PROTECTED": "number_protected_bookings",
"REJECTED": "number_rejected_bookings",
"NOCHECKS": "number_no_checks_bookings",
"NOFLAGS": "number_no_flags_bookings",
"PAID": "number_paid_bookings",
"PENDING": "number_pending_bookings",
"-": "number_unknown_status_bookings",
"PARTIALLY PROTECTED": "number_partially_protected_bookings",
"NOT PROTECTED": "number_not_protected_bookings",
"NOT PAID": "number_not_paid_bookings",
"CONFIRMED": "number_confirmed_bookings",
"FORREVIEW": "number_for_review_bookings",
"FLAGGED": "number_flagged_bookings",
} %}
{% for status, alias in service_status_map.items() %}
count(
distinct case
when upper(ub.service_status) = '{{ status }}'
then (ub.id_booking)
else null
end
) as {{ alias }}
{% if not loop.last %}, {% endif %}
{% endfor %}
{% endmacro %}

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: |