From 658980e48fb507c8b8f8377c0402c3dd8b28786f Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Tue, 26 Nov 2024 10:33:03 +0100 Subject: [PATCH] Modified name and changed date to group as an argument --- ...or.sql => kpis_daily_outlier_detector.sql} | 10 ++--- models/reporting/kpis/schema.yml | 44 ++++++++++++++----- 2 files changed, 38 insertions(+), 16 deletions(-) rename macros/tests/{kpis_outlier_detector.sql => kpis_daily_outlier_detector.sql} (79%) diff --git a/macros/tests/kpis_outlier_detector.sql b/macros/tests/kpis_daily_outlier_detector.sql similarity index 79% rename from macros/tests/kpis_outlier_detector.sql rename to macros/tests/kpis_daily_outlier_detector.sql index 0f100a5..a2cd7a3 100644 --- a/macros/tests/kpis_outlier_detector.sql +++ b/macros/tests/kpis_daily_outlier_detector.sql @@ -1,13 +1,13 @@ -{% test kpis_outlier_detector( - model, column_name, sigma_threshold=3, days_to_consider=14 +{% test kpis_daily_outlier_detector( + model, date_column, column_name, sigma_threshold=3, days_to_consider=14 ) %} with -- Retrieve recent data based on the defined days_to_consider recent_data as ( - select date_day, {{ column_name }} + select {{ date_column }}, {{ column_name }} from {{ model }} where - date_day between ( + {{ date_column }} between ( current_date - interval '{{ days_to_consider + 1 }} days' ) and (current_date - interval '1 day') ), @@ -27,7 +27,7 @@ > {{ sigma_threshold }} as is_outlier from {{ model }} cross join metrics_stats - where date_day = current_date - interval '1 day' + where {{ date_column }} = current_date - interval '1 day' ) -- Return failing rows if any values are flagged as outliers select * diff --git a/models/reporting/kpis/schema.yml b/models/reporting/kpis/schema.yml index 47cb078..0ab1379 100644 --- a/models/reporting/kpis/schema.yml +++ b/models/reporting/kpis/schema.yml @@ -67,7 +67,9 @@ models: Count of daily guest journeys created, excluding cancelled bookings, in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: created_guest_journeys_not_cancelled + date_column: date_day - name: started_guest_journeys_not_cancelled data_type: bigint @@ -75,7 +77,9 @@ models: Count of daily guest journeys started, excluding cancelled bookings, in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: started_guest_journeys_not_cancelled + date_column: date_day - name: completed_guest_journeys_not_cancelled data_type: bigint @@ -83,7 +87,9 @@ models: Count of daily guest journeys completed, excluding cancelled bookings, in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: completed_guest_journeys_not_cancelled + date_column: date_day - name: created_guest_journeys data_type: bigint @@ -91,7 +97,9 @@ models: Count of daily guest journeys created in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: created_guest_journeys + date_column: date_day - name: started_guest_journeys data_type: bigint @@ -99,7 +107,9 @@ models: Count of daily guest journeys started in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: started_guest_journeys + date_column: date_day - name: completed_guest_journeys data_type: bigint @@ -107,7 +117,9 @@ models: Count of daily guest journeys completed in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: completed_guest_journeys + date_column: date_day - name: total_csat_score_count data_type: bigint @@ -115,7 +127,9 @@ models: Count of daily guest journeys with CSAT (customer satisfaction score) in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: total_csat_score_count + date_column: date_day - name: average_csat_score data_type: bigint @@ -128,7 +142,9 @@ models: Sum of deposit fees paid by guests, without taxes, in GBP in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: deposit_fees_in_gbp + date_column: date_day - name: waiver_payments_in_gbp data_type: decimal @@ -136,7 +152,9 @@ models: Sum of waiver payments paid by guests, without taxes, in GBP in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: waiver_payments_in_gbp + date_column: date_day - name: checkin_cover_fees_in_gbp data_type: decimal @@ -144,7 +162,9 @@ models: Sum of checkin cover fees paid by guests, without taxes, in GBP in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: checkin_cover_fees_in_gbp + date_column: date_day - name: total_guest_payments_in_gbp data_type: decimal @@ -152,7 +172,9 @@ models: Sum of total payments paid by guests, without taxes, in GBP in a given date and per specified dimension. tests: - - kpis_outlier_detector + - kpis_daily_outlier_detector: + column_name: total_guest_payments_in_gbp + date_column: date_day - name: py_created_guest_journeys_not_cancelled data_type: bigint