From 13f49bf56b3713f97ab30abbf5b4db5ec95802f9 Mon Sep 17 00:00:00 2001 From: fivetran-joemarkiewicz Date: Tue, 12 Oct 2021 22:22:51 -0500 Subject: [PATCH 1/3] reply time updates --- .../int_zendesk__comments_enriched.sql | 20 +++++++++++--- ...desk__ticket_first_reply_time_business.sql | 14 +++++----- .../int_zendesk__ticket_reply_times.sql | 26 ++++++++++++++----- models/zendesk__ticket_metrics.sql | 2 +- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/models/reply_times/int_zendesk__comments_enriched.sql b/models/reply_times/int_zendesk__comments_enriched.sql index 66d9b2e4..b1932b90 100644 --- a/models/reply_times/int_zendesk__comments_enriched.sql +++ b/models/reply_times/int_zendesk__comments_enriched.sql @@ -24,17 +24,29 @@ with ticket_comment as ( on commenter.user_id = ticket_comment.user_id ), add_previous_commenter_role as ( - + /* + In int_zendesk__ticket_reply_times we will only be focusing on reply times between public tickets. + The below union explicitly identifies the previous commentor roles of public and not public comments. + */ select *, coalesce( lag(commenter_role) over (partition by ticket_id order by valid_starting_at) , 'first_comment') - as previous_commenter_role, - first_value(valid_starting_at) over (partition by ticket_id order by valid_starting_at desc, ticket_id rows unbounded preceding) as last_comment_added_at + as previous_commenter_role + from joined + where is_public + + union all + select + *, + 'non_public_comment' as previous_commenter_role from joined + where not is_public ) -select * +select + *, + first_value(valid_starting_at) over (partition by ticket_id order by valid_starting_at desc, ticket_id rows unbounded preceding) as last_comment_added_at from add_previous_commenter_role \ No newline at end of file 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 2d05029c..bb802827 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 @@ -75,13 +75,13 @@ with ticket_reply_times 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 + 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 and ticket_week_end_time >= schedule.start_time_utc diff --git a/models/reply_times/int_zendesk__ticket_reply_times.sql b/models/reply_times/int_zendesk__ticket_reply_times.sql index 51d8b035..ae937c8c 100644 --- a/models/reply_times/int_zendesk__ticket_reply_times.sql +++ b/models/reply_times/int_zendesk__ticket_reply_times.sql @@ -9,21 +9,35 @@ with ticket_public_comments as ( select ticket_id, valid_starting_at as end_user_comment_created_at, + ticket_created_date, + commenter_role, previous_commenter_role = 'first_comment' as is_first_comment from ticket_public_comments - where commenter_role = 'external_comment' - and ticket_public_comments.previous_commenter_role != 'external_comment' -- we only care about net new end user comments + where (commenter_role = 'external_comment' + and ticket_public_comments.previous_commenter_role != 'external_comment') -- we only care about net new end user comments + or previous_commenter_role = 'first_comment' -- We also want to take into consideration internal first comment replies ), reply_timestamps as ( select - end_user_comments.*, - min(agent_comments.valid_starting_at) as agent_responded_at + end_user_comments.ticket_id, + -- If the commentor was internal and a first comment then we want the ticket created date to be the end user comment created date + -- Otherwise we will want to end user comment created date + case when end_user_comments.commenter_role = 'internal_comment' and end_user_comments.is_first_comment + then end_user_comments.ticket_created_date + else end_user_comments.end_user_comment_created_at + end as end_user_comment_created_at, + end_user_comments.is_first_comment, + -- If the commentor was internal and is the first comment then we want the end user comment to be the responded at date as this is the date the agent responded following the ticket created date + -- Otherwise we want the agent responded at date + min(case when end_user_comments.commenter_role = 'internal_comment' and end_user_comments.is_first_comment + then end_user_comments.end_user_comment_created_at + else agent_comments.valid_starting_at + end) as agent_responded_at from end_user_comments left join ticket_public_comments as agent_comments on agent_comments.ticket_id = end_user_comments.ticket_id and agent_comments.commenter_role = 'internal_comment' - and agent_comments.previous_commenter_role != 'first_comment' -- we only care about net new agent comments and agent_comments.valid_starting_at > end_user_comments.end_user_comment_created_at group by 1,2,3 @@ -36,4 +50,4 @@ with ticket_public_comments as ( 'agent_responded_at', 'second') }} / 60) as reply_time_calendar_minutes from reply_timestamps - order by 1,2 + order by 1,2 \ No newline at end of file diff --git a/models/zendesk__ticket_metrics.sql b/models/zendesk__ticket_metrics.sql index b61232cc..9a54ecad 100644 --- a/models/zendesk__ticket_metrics.sql +++ b/models/zendesk__ticket_metrics.sql @@ -99,7 +99,7 @@ select ticket_work_time_calendar.requester_wait_time_in_calendar_minutes, ticket_work_time_calendar.agent_work_time_in_calendar_minutes, ticket_work_time_calendar.on_hold_time_in_calendar_minutes, - ticket_comments.count_internal_comments as total_agent_replies, + coalesce(ticket_comments.count_agent_comments, 0) as total_agent_replies, --Should more likely be removed case when ticket_enriched.is_requester_active = true and ticket_enriched.requester_last_login_at is not null then ({{ dbt_utils.datediff("ticket_enriched.requester_last_login_at", dbt_utils.current_timestamp(), 'second') }} /60) From d7c5a8b5bf1edda5e373cf9fb47d7a5b9df35295 Mon Sep 17 00:00:00 2001 From: fivetran-joemarkiewicz Date: Mon, 18 Oct 2021 14:50:44 -0500 Subject: [PATCH 2/3] comment removal --- models/zendesk__ticket_metrics.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/zendesk__ticket_metrics.sql b/models/zendesk__ticket_metrics.sql index 9a54ecad..332ed37e 100644 --- a/models/zendesk__ticket_metrics.sql +++ b/models/zendesk__ticket_metrics.sql @@ -99,7 +99,7 @@ select ticket_work_time_calendar.requester_wait_time_in_calendar_minutes, ticket_work_time_calendar.agent_work_time_in_calendar_minutes, ticket_work_time_calendar.on_hold_time_in_calendar_minutes, - coalesce(ticket_comments.count_agent_comments, 0) as total_agent_replies, --Should more likely be removed + coalesce(ticket_comments.count_agent_comments, 0) as total_agent_replies, case when ticket_enriched.is_requester_active = true and ticket_enriched.requester_last_login_at is not null then ({{ dbt_utils.datediff("ticket_enriched.requester_last_login_at", dbt_utils.current_timestamp(), 'second') }} /60) From 75cbb957f05f17e9a46119bb1f87312adbd95524 Mon Sep 17 00:00:00 2001 From: fivetran-joemarkiewicz Date: Wed, 20 Oct 2021 09:26:48 -0500 Subject: [PATCH 3/3] first comment lookback to ticket created date --- models/reply_times/int_zendesk__ticket_reply_times.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/reply_times/int_zendesk__ticket_reply_times.sql b/models/reply_times/int_zendesk__ticket_reply_times.sql index ae937c8c..30018352 100644 --- a/models/reply_times/int_zendesk__ticket_reply_times.sql +++ b/models/reply_times/int_zendesk__ticket_reply_times.sql @@ -23,7 +23,7 @@ with ticket_public_comments as ( end_user_comments.ticket_id, -- If the commentor was internal and a first comment then we want the ticket created date to be the end user comment created date -- Otherwise we will want to end user comment created date - case when end_user_comments.commenter_role = 'internal_comment' and end_user_comments.is_first_comment + case when end_user_comments.is_first_comment then end_user_comments.ticket_created_date else end_user_comments.end_user_comment_created_at end as end_user_comment_created_at,