diff --git a/macros/business_kpis_configuration.sql b/macros/business_kpis_configuration.sql index 7fb33c5..8debdfb 100644 --- a/macros/business_kpis_configuration.sql +++ b/macros/business_kpis_configuration.sql @@ -81,10 +81,16 @@ Please note that strings should be encoded with " ' your_value_here ' ", {{ return({"dimension": "'by_dash_source'", "dimension_value": "dash_source"}) }} {% endmacro %} {% macro dim_has_payment() %} - {{ return({"dimension": "'by_has_payment'", "dimension_value": "'has_payment'"}) }} + {{ return({ + "dimension": "'by_has_payment'", + "dimension_value": "case when has_payment then 'True' else 'False' end" + }) }} {% endmacro %} {% macro dim_has_id_check() %} - {{ return({"dimension": "'by_has_id_check'", "dimension_value": "'has_id_check'"}) }} + {{ return({ + "dimension": "'by_has_id_check'", + "dimension_value": "case when has_id_check then 'True' else 'False' end" + }) }} {% endmacro %} /* @@ -114,7 +120,7 @@ Provides a general assignemnt for the Dimensions available for each KPI {% endif %} {# Add entity-specific dimensions #} - {% if entity_name == "GUEST_JOURNEY_METRICS" %} + {% if entity_name == "CHECK_IN_ATTRIBUTED_GUEST_JOURNEYS" %} {% set additional_dimensions = [dim_has_payment(), dim_has_id_check()] %} {% endif %} diff --git a/macros/tests/assert_dimension_completeness.sql b/macros/tests/assert_dimension_completeness.sql index 9dd7531..967bc28 100644 --- a/macros/tests/assert_dimension_completeness.sql +++ b/macros/tests/assert_dimension_completeness.sql @@ -1,35 +1,21 @@ {% test assert_dimension_completeness( - model, column_name, metric_column_names, global_dimension_name="global" + model, column_name, metric_column_name, global_dimension_name="global" ) %} with - - {% for metric_column_name in metric_column_names %} - sum_by_dimension_{{ metric_column_name }} as ( + sum_by_dimension as ( select {{ column_name }}, sum({{ metric_column_name }}) as sum_metric from {{ model }} group by {{ column_name }} ), - global_sum_{{ metric_column_name }} as ( + global_sum as ( select sum({{ metric_column_name }}) as total_metric from {{ model }} where {{ column_name }} = '{{ global_dimension_name }}' - ), - discrepancy_{{ metric_column_name }} as ( - select * - from sum_by_dimension_{{ metric_column_name }}, global_sum_{{ metric_column_name }} - where sum_by_dimension_{{ metric_column_name }}.sum_metric != global_sum_{{ metric_column_name }}.total_metric ) - {% if not loop.last %}, {% endif %} - {% endfor %} - {% for metric_column_name in metric_column_names %} - {% if loop.first %} - select * from discrepancy_{{ metric_column_name }} - {% else %} - union all - select * from discrepancy_{{ metric_column_name }} - {% endif %} - {% endfor %} + select * + from sum_by_dimension, global_sum + where sum_by_dimension.sum_metric != global_sum.total_metric {% endtest %} diff --git a/models/intermediate/kpis/int_kpis__agg_mtd_check_in_attrib_guest_journeys.sql b/models/intermediate/kpis/int_kpis__agg_monthly_check_in_attributed_guest_journeys.sql similarity index 83% rename from models/intermediate/kpis/int_kpis__agg_mtd_check_in_attrib_guest_journeys.sql rename to models/intermediate/kpis/int_kpis__agg_monthly_check_in_attributed_guest_journeys.sql index dbdbc62..8f0ef70 100644 --- a/models/intermediate/kpis/int_kpis__agg_mtd_check_in_attrib_guest_journeys.sql +++ b/models/intermediate/kpis/int_kpis__agg_monthly_check_in_attributed_guest_journeys.sql @@ -1,4 +1,4 @@ -{% set dimensions = get_kpi_dimensions_per_model("GUEST_JOURNEY_METRICS") %} +{% set dimensions = get_kpi_dimensions_per_model("CHECK_IN_ATTRIBUTED_GUEST_JOURNEYS") %} {{ config( @@ -27,9 +27,9 @@ sum(created_guest_journeys) as created_guest_journeys, sum(started_guest_journeys) as started_guest_journeys, sum(completed_guest_journeys) as completed_guest_journeys - from {{ ref("int_kpis__metric_mtd_check_in_attrib_guest_journeys") }} + from {{ ref("int_kpis__metric_monthly_check_in_attributed_guest_journeys") }} group by 1, 2, 3, 4 {% if not loop.last %} union all {% endif %} -{% endfor %} \ No newline at end of file +{% endfor %} diff --git a/models/intermediate/kpis/int_kpis__agg_monthly_check_in_attrib_guest_journeys.sql b/models/intermediate/kpis/int_kpis__agg_mtd_check_in_attributed_guest_journeys.sql similarity index 93% rename from models/intermediate/kpis/int_kpis__agg_monthly_check_in_attrib_guest_journeys.sql rename to models/intermediate/kpis/int_kpis__agg_mtd_check_in_attributed_guest_journeys.sql index 58284ae..c2df07a 100644 --- a/models/intermediate/kpis/int_kpis__agg_monthly_check_in_attrib_guest_journeys.sql +++ b/models/intermediate/kpis/int_kpis__agg_mtd_check_in_attributed_guest_journeys.sql @@ -27,9 +27,9 @@ sum(created_guest_journeys) as created_guest_journeys, sum(started_guest_journeys) as started_guest_journeys, sum(completed_guest_journeys) as completed_guest_journeys - from {{ ref("int_kpis__metric_monthly_check_in_attrib_guest_journeys") }} + from {{ ref("int_kpis__metric_mtd_check_in_attributed_guest_journeys") }} group by 1, 2, 3, 4 {% if not loop.last %} union all {% endif %} -{% endfor %} +{% endfor %} \ No newline at end of file diff --git a/models/intermediate/kpis/int_kpis__metric_daily_check_in_attrib_guest_journeys.sql b/models/intermediate/kpis/int_kpis__metric_daily_check_in_attributed_guest_journeys.sql similarity index 100% rename from models/intermediate/kpis/int_kpis__metric_daily_check_in_attrib_guest_journeys.sql rename to models/intermediate/kpis/int_kpis__metric_daily_check_in_attributed_guest_journeys.sql diff --git a/models/intermediate/kpis/int_kpis__metric_monthly_check_in_attrib_guest_journeys.sql b/models/intermediate/kpis/int_kpis__metric_monthly_check_in_attributed_guest_journeys.sql similarity index 88% rename from models/intermediate/kpis/int_kpis__metric_monthly_check_in_attrib_guest_journeys.sql rename to models/intermediate/kpis/int_kpis__metric_monthly_check_in_attributed_guest_journeys.sql index 8e1f05d..021092a 100644 --- a/models/intermediate/kpis/int_kpis__metric_monthly_check_in_attrib_guest_journeys.sql +++ b/models/intermediate/kpis/int_kpis__metric_monthly_check_in_attributed_guest_journeys.sql @@ -1,7 +1,7 @@ {{ config( materialized="view", - unique_key=["end_date", "id_deal", "has_payment", "has_id_check"], + unique_key=["end_date", "id_deal", "has_payment", "has_id_check", "active_accommodations_per_deal_segmentation"], ) }} @@ -26,7 +26,7 @@ select sum(b.completed_guest_journeys) as completed_guest_journeys from {{ ref("int_kpis__dimension_dates") }} d left join - {{ ref("int_kpis__metric_daily_check_in_attrib_guest_journeys") }} b + {{ ref("int_kpis__metric_daily_check_in_attributed_guest_journeys") }} b on date_trunc('month', b.date)::date = d.first_day_month where d.is_end_of_month = true and b.id_deal is not null group by 1, 2, 3, 4, 5, 6, 7 diff --git a/models/intermediate/kpis/int_kpis__metric_mtd_check_in_attrib_guest_journeys.sql b/models/intermediate/kpis/int_kpis__metric_mtd_check_in_attributed_guest_journeys.sql similarity index 89% rename from models/intermediate/kpis/int_kpis__metric_mtd_check_in_attrib_guest_journeys.sql rename to models/intermediate/kpis/int_kpis__metric_mtd_check_in_attributed_guest_journeys.sql index 09e872e..4c7a5f2 100644 --- a/models/intermediate/kpis/int_kpis__metric_mtd_check_in_attrib_guest_journeys.sql +++ b/models/intermediate/kpis/int_kpis__metric_mtd_check_in_attributed_guest_journeys.sql @@ -1,7 +1,7 @@ {{ config( materialized="view", - unique_key=["end_date", "id_deal", "has_payment", "has_id_check"], + unique_key=["end_date", "id_deal", "has_payment", "has_id_check", "active_accommodations_per_deal_segmentation"], ) }} @@ -26,7 +26,7 @@ select sum(b.completed_guest_journeys) as completed_guest_journeys from {{ ref("int_kpis__dimension_dates") }} d left join - {{ ref("int_kpis__metric_daily_check_in_attrib_guest_journeys") }} b + {{ ref("int_kpis__metric_daily_check_in_attributed_guest_journeys") }} b on date_trunc('month', b.date)::date = d.first_day_month and extract(day from b.date) <= d.day where d.is_month_to_date = true and b.id_deal is not null diff --git a/models/intermediate/kpis/schema.yml b/models/intermediate/kpis/schema.yml index 073c69e..aab888d 100644 --- a/models/intermediate/kpis/schema.yml +++ b/models/intermediate/kpis/schema.yml @@ -480,8 +480,7 @@ models: description: The dimension or granularity of the metrics. tests: - assert_dimension_completeness: - metric_column_names: - - created_bookings + metric_column_name: created_bookings - accepted_values: values: - global @@ -3242,7 +3241,13 @@ models: tests: - not_null - accepted_values: - values: ["0", "01-05", "06-20", "21-60", "61+", "UNSET"] + values: + - "0" + - "01-05" + - "06-20" + - "21-60" + - "61+" + - "UNSET" - name: main_billing_country_iso_3_per_deal data_type: character varying @@ -3332,16 +3337,25 @@ models: The dimension or granularity of the metrics. tests: - assert_dimension_completeness: - metric_column_names: - - created_guest_journeys_not_cancelled - - started_guest_journeys_not_cancelled - - completed_guest_journeys_not_cancelled - - created_guest_journeys - - started_guest_journeys - - completed_guest_journeys + metric_column_name: created_guest_journeys_not_cancelled + - assert_dimension_completeness: + metric_column_name: started_guest_journeys_not_cancelled + - assert_dimension_completeness: + metric_column_name: completed_guest_journeys_not_cancelled + - assert_dimension_completeness: + metric_column_name: created_guest_journeys + - assert_dimension_completeness: + metric_column_name: started_guest_journeys + - assert_dimension_completeness: + metric_column_name: completed_guest_journeys - accepted_values: - values: ["global", "by_deal", "by_has_payment", "by_has_id_check", - "by_billing_country", "by_number_of_listings"] + values: + - global + - by_deal + - by_has_payment + - by_has_id_check + - by_billing_country + - by_number_of_listings - name: dimension_value data_type: text @@ -3461,7 +3475,13 @@ models: tests: - not_null - accepted_values: - values: ["0", "01-05", "06-20", "21-60", "61+", "UNSET"] + values: + - "0" + - "01-05" + - "06-20" + - "21-60" + - "61+" + - "UNSET" - name: main_billing_country_iso_3_per_deal data_type: character varying @@ -3551,16 +3571,25 @@ models: The dimension or granularity of the metrics. tests: - assert_dimension_completeness: - metric_column_names: - - created_guest_journeys_not_cancelled - - started_guest_journeys_not_cancelled - - completed_guest_journeys_not_cancelled - - created_guest_journeys - - started_guest_journeys - - completed_guest_journeys + metric_column_name: created_guest_journeys_not_cancelled + - assert_dimension_completeness: + metric_column_name: started_guest_journeys_not_cancelled + - assert_dimension_completeness: + metric_column_name: completed_guest_journeys_not_cancelled + - assert_dimension_completeness: + metric_column_name: created_guest_journeys + - assert_dimension_completeness: + metric_column_name: started_guest_journeys + - assert_dimension_completeness: + metric_column_name: completed_guest_journeys - accepted_values: - values: ["global", "by_deal", "by_has_payment", "by_has_id_check", - "by_billing_country", "by_number_of_listings"] + values: + - global + - by_deal + - by_has_payment + - by_has_id_check + - by_billing_country + - by_number_of_listings - name: dimension_value data_type: text