Merged PR 5001: Payouts amounts attributed to Bookings

# Description

Adds monetary value in terms of payouts for further understanding of the potential impact on improving the flagging.

# 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.
- [X] I have checked for DRY opportunities with other models and docs.
- [X] I've picked the right materialization for the affected models.

# Other

- [ ] Check if a full-refresh is required after this PR is merged.

Related work items: #29284
This commit is contained in:
Oriol Roqué Paniagua 2025-04-16 06:48:39 +00:00
parent e981cc1739
commit 4922fce426
2 changed files with 81 additions and 3 deletions

View file

@ -26,7 +26,7 @@ with
deduplicated_incidents as (
select
id_booking,
sum(accepted_amount_in_gbp) as booking_accepted_amount_in_gbp,
sum(submitted_payout_amount_in_gbp) as submitted_payout_amount_in_gbp,
case
when sum(submitted_payout_amount_in_gbp) > 0 then true else false
end as has_submitted_payout,
@ -89,7 +89,10 @@ with
ndpb.is_booking_flagged_as_risk,
case when di.id_booking is not null then true else false end as has_claim,
coalesce(di.has_submitted_payout, false) as has_submitted_payout,
coalesce(di.is_incident_finished, false) as is_incident_finished
coalesce(di.is_incident_finished, false) as is_incident_finished,
coalesce(
submitted_payout_amount_in_gbp, 0
) as submitted_payout_amount_in_gbp
from new_dash_protected_bookings ndpb
left join deduplicated_incidents di on ndpb.id_booking = di.id_booking
)
@ -216,5 +219,42 @@ select
and has_submitted_payout
and has_claim
and is_incident_finished
) as completed_no_risk_with_submitted_payout_bookings
) as completed_no_risk_with_submitted_payout_bookings,
-- ADDITIONAL PAYOUT INPUT - FOR CONFUSION MATRIX 2: RISK vs. PAYOUT --
-- Total amount paid for all bookings
sum(submitted_payout_amount_in_gbp) as total_amount_paid_in_gbp,
-- Amount paid from completed bookings
sum(submitted_payout_amount_in_gbp) filter (
where is_booking_completed
) as completed_amount_paid_in_gbp,
-- Amount paid from not completed bookings
sum(submitted_payout_amount_in_gbp) filter (
where not is_booking_completed
) as not_completed_amount_paid_in_gbp,
-- Completed with Risk, Incident is finished and with Submitted Payout --
-- True Positives - How much did we pay?
sum(submitted_payout_amount_in_gbp) filter (
where
is_booking_completed
and is_booking_flagged_as_risk
and has_claim
and has_submitted_payout
and is_incident_finished
) as completed_risk_with_submitted_payout_amount_paid_in_gbp,
-- Completed without Risk and with Submitted Payout
-- False Negative - How much did we pay?
sum(submitted_payout_amount_in_gbp) filter (
where
is_booking_completed
and not is_booking_flagged_as_risk
and has_submitted_payout
and has_claim
and is_incident_finished
) as completed_no_risk_with_submitted_payout_amount_paid_in_gbp
from bookings_with_incidents

View file

@ -2868,6 +2868,12 @@ models:
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: completed_not_awaiting_resolution_bookings
column_B: completed_risk_with_submitted_payout_bookings + completed_no_risk_without_submitted_payout_bookings + completed_risk_without_submitted_payout_bookings + completed_no_risk_with_submitted_payout_bookings
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: total_amount_paid_in_gbp
column_B: completed_amount_paid_in_gbp + not_completed_amount_paid_in_gbp
- dbt_expectations.expect_column_pair_values_to_be_equal:
column_A: completed_amount_paid_in_gbp
column_B: completed_risk_with_submitted_payout_amount_paid_in_gbp + completed_no_risk_with_submitted_payout_amount_paid_in_gbp
columns:
- name: total_bookings
@ -3018,6 +3024,38 @@ models:
For the submitted payout-based performance analysis, this would be
the false negative.
- name: total_amount_paid_in_gbp
data_type: numeric
description: |
Total amount paid in GBP in terms of Resolutions Payouts for all
Bookings.
- name: completed_amount_paid_in_gbp
data_type: numeric
description: |
Total amount paid in GBP in terms of Resolutions Payouts for Completed
Bookings.
- name: not_completed_amount_paid_in_gbp
data_type: numeric
description: |
Total amount paid in GBP in terms of Resolutions Payouts for
Bookings that are not completed, for reference.
- name: completed_risk_with_submitted_payout_amount_paid_in_gbp
data_type: numeric
description: |
Total amount paid in GBP in terms of Resolutions Payouts for Completed
Bookings that have been flagged as at Risk AND that have had a
submitted payout, with the claim being in a finished status.
- name: completed_no_risk_with_submitted_payout_amount_paid_in_gbp
data_type: numeric
description: |
Total amount paid in GBP in terms of Resolutions Payouts for Completed
Bookings that have NOT been flagged as at Risk AND that have had a
submitted payout, with the claim being in a finished status.
- name: int_flagging_performance_analysis
description: |
Provides a basic statistical analysis with binary classification metrics