From 42701b4d2cf6f864169e7b7c321d9a4649a2bbd4 Mon Sep 17 00:00:00 2001 From: Joaquin Ossa Date: Thu, 27 Feb 2025 12:28:09 +0000 Subject: [PATCH] Merged PR 4530: first comment time added # Description First comment time added # Checklist - [x] The edited models and dependants run properly with production data. - [x] The edited models are sufficiently documented. - [x] The edited models contain PK tests, and I've ran and passed them. - [ ] I have checked for DRY opportunities with other models and docs. - [ ] I've picked the right materialization for the affected models. # Other - [ ] Check if a full-refresh is required after this PR is merged. first comment time added Related work items: #27812 --- .../resolutions/int_resolutions__incidents.sql | 8 ++++++++ models/intermediate/resolutions/schema.yml | 8 ++++++++ models/reporting/resolutions/resolutions__incidents.sql | 1 + models/reporting/resolutions/schema.yml | 8 ++++++++ models/staging/resolutions/stg_resolutions__incidents.sql | 4 ++++ 5 files changed, 29 insertions(+) diff --git a/models/intermediate/resolutions/int_resolutions__incidents.sql b/models/intermediate/resolutions/int_resolutions__incidents.sql index a7e8726..371d672 100644 --- a/models/intermediate/resolutions/int_resolutions__incidents.sql +++ b/models/intermediate/resolutions/int_resolutions__incidents.sql @@ -159,6 +159,14 @@ select lt.first_comment_at_utc, lt.last_comment_at_utc, lt.comment_count, + case + when lt.first_comment_at_utc is not null + then + ( + extract(epoch from (lt.first_comment_at_utc - i.created_at_utc)) / 3600 + )::decimal(19, 4) + else null + end as time_to_first_comment_in_hours, lt.first_status_at_utc, lt.last_status_at_utc, case diff --git a/models/intermediate/resolutions/schema.yml b/models/intermediate/resolutions/schema.yml index a018db3..02bba04 100644 --- a/models/intermediate/resolutions/schema.yml +++ b/models/intermediate/resolutions/schema.yml @@ -71,6 +71,14 @@ models: data_type: bigint description: "Number of comments submitted on the incident." + - name: time_to_first_comment_in_hours + data_type: numeric + description: "Time taken to reach the client for the first time." + data_tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: true + - name: first_status_at_utc data_type: timestamp description: "Timestamp of the first status change on the incident." diff --git a/models/reporting/resolutions/resolutions__incidents.sql b/models/reporting/resolutions/resolutions__incidents.sql index 4b97413..0d9a803 100644 --- a/models/reporting/resolutions/resolutions__incidents.sql +++ b/models/reporting/resolutions/resolutions__incidents.sql @@ -17,6 +17,7 @@ select first_comment_at_utc as first_comment_at_utc, last_comment_at_utc as last_comment_at_utc, comment_count as comment_count, + time_to_first_comment_in_hours as time_to_first_comment_in_hours, first_status_at_utc as first_status_at_utc, last_status_at_utc as last_status_at_utc, resolution_time_in_hours as resolution_time_in_hours, diff --git a/models/reporting/resolutions/schema.yml b/models/reporting/resolutions/schema.yml index cac8c09..c44983a 100644 --- a/models/reporting/resolutions/schema.yml +++ b/models/reporting/resolutions/schema.yml @@ -71,6 +71,14 @@ models: data_type: bigint description: "Number of comments submitted on the incident." + - name: time_to_first_comment_in_hours + data_type: numeric + description: "Time taken to reach the client for the first time." + data_tests: + - dbt_expectations.expect_column_values_to_be_between: + min_value: 0 + strictly: true + - name: first_status_at_utc data_type: timestamp description: "Timestamp of the first status change on the incident." diff --git a/models/staging/resolutions/stg_resolutions__incidents.sql b/models/staging/resolutions/stg_resolutions__incidents.sql index af62730..e3c75ee 100644 --- a/models/staging/resolutions/stg_resolutions__incidents.sql +++ b/models/staging/resolutions/stg_resolutions__incidents.sql @@ -3,6 +3,8 @@ -- Many of them don't have the same necessary fields as the current model. -- The same happens with the 'ManualFormWeb' document_version. {% set old_or_manual_documents = ("OLDCLAIMTOINCIDENTMODEL", "MANUALFORMWEB") %} +-- Test or cancelled incidents are not considered in the reporting. +{% set tests_or_cancelled_incidents = "ARCHIVED" %} with raw_incident as (select * from {{ source("resolutions", "incident") }}), @@ -267,3 +269,5 @@ from deduped_verifications where upper({{ adapter.quote("documents") }} ->> 'DocumentVersion') not in {{ old_or_manual_documents }} + and upper({{ adapter.quote("documents") }} ->> 'CurrentStatusName') + <> '{{ tests_or_cancelled_incidents }}'