diff --git a/integration_tests/tests/integrity/metrics_count_match.sql b/integration_tests/tests/integrity/metrics_count_match.sql new file mode 100644 index 00000000..715176c4 --- /dev/null +++ b/integration_tests/tests/integrity/metrics_count_match.sql @@ -0,0 +1,24 @@ + +{{ config( + tags="fivetran_validations", + enabled=var('fivetran_validation_tests_enabled', false) +) }} + +-- check that all the tickets are accounted for in the metrics +with stg_count as ( + select + count(*) as stg_ticket_count + from {{ ref('stg_zendesk__ticket') }} +), + +metric_count as ( + select + count(*) as metric_ticket_count + from source + from {{ ref('zendesk__ticket_metrics') }} +) + +select * +from stg_count +join metric_count + on stg_ticket_count != metric_ticket_count \ No newline at end of file diff --git a/models/agent_work_time/int_zendesk__ticket_work_time_business.sql b/models/agent_work_time/int_zendesk__ticket_work_time_business.sql index 01c0ae18..7725165b 100644 --- a/models/agent_work_time/int_zendesk__ticket_work_time_business.sql +++ b/models/agent_work_time/int_zendesk__ticket_work_time_business.sql @@ -63,7 +63,7 @@ with ticket_historical_status as ( ), weeks as ( - {{ dbt_utils.generate_series(208) }} + {{ dbt_utils.generate_series(52) }} ), weeks_cross_ticket_full_solved_time as ( -- because time is reported in minutes since the beginning of the week, we have to split up time spent on the ticket into calendar weeks @@ -99,14 +99,14 @@ with ticket_historical_status as ( schedule.end_time_utc as schedule_end_time, least(ticket_week_end_time, schedule.end_time_utc) - greatest(weekly_periods.ticket_week_start_time, schedule.start_time_utc) as scheduled_minutes from weekly_periods - join schedule on - ticket_week_start_time <= schedule.end_time_utc + join schedule + on ticket_week_start_time <= schedule.end_time_utc and ticket_week_end_time >= schedule.start_time_utc and weekly_periods.schedule_id = schedule.schedule_id -- this chooses the Daylight Savings Time or Standard Time version of the schedule -- We have everything calculated within a week, so take us to the appropriate week first by adding the week_number * minutes-in-a-week to the minute-mark where we start and stop counting for the week - and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_end_time', from_date_or_timestamp='start_week_date') }} as {{ dbt.type_timestamp() }}) > cast(schedule.valid_from as {{ dbt.type_timestamp() }}) - and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_start_time', from_date_or_timestamp='start_week_date') }} as {{ dbt.type_timestamp() }}) < cast(schedule.valid_until as {{ dbt.type_timestamp() }}) + and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_end_time', from_date_or_timestamp='start_week_date') }} as date) > cast(schedule.valid_from as date) + and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_start_time', from_date_or_timestamp='start_week_date') }} as date) < cast(schedule.valid_until as date) ), business_minutes as ( diff --git a/models/reply_times/int_zendesk__ticket_first_reply_time_business.sql b/models/reply_times/int_zendesk__ticket_first_reply_time_business.sql index 8ab35ea6..f148ca06 100644 --- a/models/reply_times/int_zendesk__ticket_first_reply_time_business.sql +++ b/models/reply_times/int_zendesk__ticket_first_reply_time_business.sql @@ -57,7 +57,7 @@ with ticket_reply_times as ( ), weeks as ( - {{ dbt_utils.generate_series(208) }} + {{ dbt_utils.generate_series(52) }} ), weeks_cross_ticket_first_reply as ( -- because time is reported in minutes since the beginning of the week, we have to split up time spent on the ticket into calendar weeks @@ -102,6 +102,6 @@ with ticket_reply_times as ( ) select ticket_id, - sum(scheduled_minutes) as first_reply_time_business_minutes + sum(scheduled_minutes) as first_reply_time_business_minutes from intercepted_periods group by 1 \ No newline at end of file diff --git a/models/resolution_times/int_zendesk__ticket_first_resolution_time_business.sql b/models/resolution_times/int_zendesk__ticket_first_resolution_time_business.sql index 90a3fb13..f61e69b7 100644 --- a/models/resolution_times/int_zendesk__ticket_first_resolution_time_business.sql +++ b/models/resolution_times/int_zendesk__ticket_first_resolution_time_business.sql @@ -46,7 +46,7 @@ with ticket_resolution_times_calendar as ( ), weeks as ( - {{ dbt_utils.generate_series(208) }} + {{ dbt_utils.generate_series(52) }} ), weeks_cross_ticket_first_resolution_time as ( -- because time is reported in minutes since the beginning of the week, we have to split up time spent on the ticket into calendar weeks @@ -72,22 +72,24 @@ with ticket_resolution_times_calendar as ( ), intercepted_periods as ( - select ticket_id, - week_number, - weekly_periods.schedule_id, - ticket_week_start_time, - ticket_week_end_time, - schedule.start_time_utc as schedule_start_time, - schedule.end_time_utc as schedule_end_time, - least(ticket_week_end_time, schedule.end_time_utc) - greatest(ticket_week_start_time, schedule.start_time_utc) as scheduled_minutes + select + ticket_id, + week_number, + weekly_periods.schedule_id, + ticket_week_start_time, + ticket_week_end_time, + schedule.start_time_utc as schedule_start_time, + schedule.end_time_utc as schedule_end_time, + least(ticket_week_end_time, schedule.end_time_utc) - greatest(ticket_week_start_time, schedule.start_time_utc) as scheduled_minutes from weekly_periods - join schedule on ticket_week_start_time <= schedule.end_time_utc + join schedule + on ticket_week_start_time <= schedule.end_time_utc and ticket_week_end_time >= schedule.start_time_utc and weekly_periods.schedule_id = schedule.schedule_id -- this chooses the Daylight Savings Time or Standard Time version of the schedule -- We have everything calculated within a week, so take us to the appropriate week first by adding the week_number * minutes-in-a-week to the minute-mark where we start and stop counting for the week - and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_end_time', from_date_or_timestamp='start_week_date') }} as {{ dbt.type_timestamp() }}) > cast(schedule.valid_from as {{ dbt.type_timestamp() }}) - and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_start_time', from_date_or_timestamp='start_week_date') }} as {{ dbt.type_timestamp() }}) < cast(schedule.valid_until as {{ dbt.type_timestamp() }}) + and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_end_time', from_date_or_timestamp='start_week_date') }} as date) > cast(schedule.valid_from as date) + and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_start_time', from_date_or_timestamp='start_week_date') }} as date) < cast(schedule.valid_until as date) ) diff --git a/models/resolution_times/int_zendesk__ticket_full_resolution_time_business.sql b/models/resolution_times/int_zendesk__ticket_full_resolution_time_business.sql index 414ab654..fe4df912 100644 --- a/models/resolution_times/int_zendesk__ticket_full_resolution_time_business.sql +++ b/models/resolution_times/int_zendesk__ticket_full_resolution_time_business.sql @@ -45,7 +45,7 @@ with ticket_resolution_times_calendar as ( ), weeks as ( - {{ dbt_utils.generate_series(208) }} + {{ dbt_utils.generate_series(52) }} ), weeks_cross_ticket_full_resolution_time as ( -- because time is reported in minutes since the beginning of the week, we have to split up time spent on the ticket into calendar weeks @@ -85,8 +85,8 @@ with ticket_resolution_times_calendar as ( and weekly_periods.schedule_id = schedule.schedule_id -- this chooses the Daylight Savings Time or Standard Time version of the schedule -- We have everything calculated within a week, so take us to the appropriate week first by adding the week_number * minutes-in-a-week to the minute-mark where we start and stop counting for the week - and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_end_time', from_date_or_timestamp='start_week_date') }} as {{ dbt.type_timestamp() }}) > cast(schedule.valid_from as {{ dbt.type_timestamp() }}) - and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_start_time', from_date_or_timestamp='start_week_date') }} as {{ dbt.type_timestamp() }}) < cast(schedule.valid_until as {{ dbt.type_timestamp() }}) + and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_end_time', from_date_or_timestamp='start_week_date') }} as date) > cast(schedule.valid_from as date) + and cast( {{ dbt.dateadd(datepart='minute', interval='week_number * (7*24*60) + ticket_week_start_time', from_date_or_timestamp='start_week_date') }} as date) < cast(schedule.valid_until as date) )