data alert fix

This commit is contained in:
Joaquin 2025-06-10 13:58:50 +02:00
parent dc0abe6098
commit e85de15d22
4 changed files with 25 additions and 47 deletions

View file

@ -12,23 +12,10 @@ select
atpb.id_user_product_bundle, atpb.id_user_product_bundle,
upb.id_user_host, upb.id_user_host,
upb.product_bundle_display_name as user_product_bundle_name, upb.product_bundle_display_name as user_product_bundle_name,
atpb.starts_at_utc as original_starts_at_utc, atpb.starts_at_utc,
atpb.ends_at_utc as original_ends_at_utc, atpb.ends_at_utc,
/* date(atpb.starts_at_utc) as starts_date_utc,
The following is to ensure that we cap the reporting to the date(atpb.ends_at_utc) as ends_date_utc,
dates in which these product bundles could have been active.
For analysis and reporting purposes, it is encouraged to use
the effective fields (start_date and end_date) rather than the
backend ones (named as original_starts_at and original_ends_at).
*/
greatest(
date(atpb.starts_at_utc), upb.effective_start_date_utc
) as effective_start_date_utc,
case
when atpb.has_no_end_date
then null
else greatest(date(atpb.ends_at_utc), upb.effective_end_date_utc)
end as effective_end_date_utc,
atpb.has_no_end_date, atpb.has_no_end_date,
upb.product_bundle_services, upb.product_bundle_services,
upb.is_custom_bundle, upb.is_custom_bundle,

View file

@ -68,11 +68,11 @@ with
count( count(
distinct case distinct case
when when
atpb.effective_start_date_utc <= current_date atpb.starts_date_utc <= current_date
and coalesce( and (
atpb.effective_end_date_utc, {{ var("end_of_time") }} atpb.ends_date_utc >= current_date
or atpb.has_no_end_date = true
) )
>= current_date
then atpb.id_accommodation then atpb.id_accommodation
else null else null
end end
@ -80,11 +80,11 @@ with
count( count(
distinct case distinct case
when when
atpb.effective_start_date_utc <= current_date atpb.starts_date_utc <= current_date
and coalesce( and (
atpb.effective_end_date_utc, {{ var("end_of_time") }} atpb.ends_date_utc >= current_date
or atpb.has_no_end_date = true
) )
>= current_date
and atpb.user_product_bundle_name and atpb.user_product_bundle_name
not in ({{ var("default_service") }}) not in ({{ var("default_service") }})
then atpb.id_accommodation then atpb.id_accommodation

View file

@ -2183,42 +2183,33 @@ models:
description: | description: |
The name of the Product Bundle. The name of the Product Bundle.
- name: original_starts_at_utc - name: starts_at_utc
data_type: timestamp data_type: timestamp
description: | description: |
Timestamp of when this Product Bundle is assigned into an Accommodation was Timestamp of when this Product Bundle is assigned into an Accommodation was
active for the first time, according to the Backend. active for the first time, according to the Backend.
Keep in mind that this timestamp can be before the migration of the user, thus
effective_start_date_utc might be better for reporting and analysis purposes.
data_tests: data_tests:
- not_null - not_null
- name: original_ends_at_utc - name: ends_at_utc
data_type: timestamp data_type: timestamp
description: | description: |
Timestamp of when this Product Bundle is assigned into an Accommodation was Timestamp of when this Product Bundle is assigned into an Accommodation was
active for the last time, according to the Backend. If null it means that active for the last time, according to the Backend. If null it means that
it's currently active. it's currently active.
Keep in mind that this timestamp can be before the migration of the user, thus
effective_end_date_utc might be better for reporting and analysis purposes.
- name: effective_start_date_utc - name: starts_date_utc
data_type: date data_type: date
description: | description: |
Effective date of when this Product Bundle is assigned into an Accommodation was The date when this Product Bundle was first assigned to the Accommodation.
active for the first time.
It takes into account the fact that a User needs to be migrated in order for
the Product Bundle to be active in the Accommodation. In case of doubt, use this date.
data_tests: data_tests:
- not_null - not_null
- name: effective_end_date_utc - name: ends_date_utc
data_type: date data_type: date
description: | description: |
Effective date of when this Product Bundle is assigned into an Accommodation was The date when this Product Bundle was last active for the Accommodation.
active for the last time. If null it means that it's currently active. If null, it means the Product Bundle is currently active.
It takes into account the fact that a User needs to be migrated in order for
the Product Bundle to be active in the Accommodation. In case of doubt, use this date.
- name: has_no_end_date - name: has_no_end_date
data_type: boolean data_type: boolean

View file

@ -16,11 +16,11 @@ with
select select
*, *,
row_number() over ( row_number() over (
partition by id_accommodation, effective_start_date_utc partition by id_accommodation, starts_date_utc
order by order by
effective_start_date_utc desc, -- Prefers the latest effective start date starts_date_utc desc, -- Prefers the latest effective start date
original_starts_at_utc desc, -- In case of ties, prefers the most recent original start starts_at_utc desc, -- In case of ties, prefers the most recent original start
coalesce(original_ends_at_utc, {{ var("end_of_time") }}) desc coalesce(ends_at_utc, {{ var("end_of_time") }}) desc
) as rn ) as rn
from {{ ref("int_core__accommodation_to_product_bundle") }} from {{ ref("int_core__accommodation_to_product_bundle") }}
) )
@ -51,8 +51,8 @@ inner join
inner join inner join
latest_daily_bundle as ldb latest_daily_bundle as ldb
on bs.id_user_product_bundle = ldb.id_user_product_bundle on bs.id_user_product_bundle = ldb.id_user_product_bundle
and date >= ldb.effective_start_date_utc and date >= ldb.starts_date_utc
and date < coalesce(ldb.effective_end_date_utc, {{ var("end_of_time") }}) and (date < ldb.ends_date_utc or ldb.has_no_end_date = true)
and ldb.rn = 1 and ldb.rn = 1
left join left join
{{ ref("int_kpis__dimension_daily_accommodation") }} as icmas {{ ref("int_kpis__dimension_daily_accommodation") }} as icmas