commit wip

This commit is contained in:
Joaquin Ossa 2025-02-21 19:16:28 +01:00
parent 47d9b6f292
commit 29755961e6

View file

@ -2,7 +2,7 @@ with
stg_resolutions__incidents as ( stg_resolutions__incidents as (
select * from {{ ref("stg_resolutions__incidents") }} select * from {{ ref("stg_resolutions__incidents") }}
), ),
comments_timeline as ( logs_timeline as (
select select
i.id_incident, i.id_incident,
( (
@ -16,8 +16,34 @@ with
from jsonb_array_elements(i.comment_logs::jsonb) comment from jsonb_array_elements(i.comment_logs::jsonb) comment
order by (comment ->> 'CreatedDate')::timestamp desc order by (comment ->> 'CreatedDate')::timestamp desc
limit 1 limit 1
) as last_comment_date ) as last_comment_date,
(
select count(*) from jsonb_array_elements(i.comment_logs::jsonb) comment
) as comment_count,
(
select count(*)
from jsonb_array_elements(i.damage_report_items::jsonb) items
) as number_damaged_items,
from stg_resolutions__incidents i from stg_resolutions__incidents i
),
damage_reported_items as (
select
i.id_incident,
jsonb_array_elements(i.documents -> 'DamageReport' -> 'Items') as item
from stg_resolutions__incidents i
)
damage_report_amounts as (
select
id_incident,
sum((corrective_measures ->> 'Amount')::numeric) as asked_repair_amount,
sum(
(corrective_measures ->> 'SettlementAmount')::numeric
) as accepted_amount,
from
parsed_data,
jsonb_array_elements(item -> 'CorrectiveMeasures') as corrective_measures
group by id_incident
) )
select select