Commit graph

778 commits

Author SHA1 Message Date
Oriol Roqué Paniagua
afc20f0e20 Merged PR 2519: mtd bookings with 2 dimensions
# Description
This is a first idea of how I'd like to add dimensionality in the KPIs for the mtd models. For the moment, I keep deal_id apart, so I just touch the "mtd" models, that so far only contained "global" metrics.

In this case I include the listing segmentation (0, 1-5, 6-20, etc) in the bookings. To do this, I created 2 new fields: dimension and dimension_values.
I also created a "master" table with `date` - `dimension` - `dimension_value` called `int_dates_mtd_by_dimension`

Important notes:
- I force a hardcode in `int_mtd_vs_previous_year_metrics`. This is to not break production.
- You will notice how repetitive the code is starting to look. My intention with this PR is that we are happy with this approach on the naming, the strategy for joins, etc. If that's ok, next step is going to be doing macros on top. Think of the state of `int_core__mtd_booking_metrics` as the "compiled version" of the macro that should come afterwards.

# 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.
- [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: #19325
2024-08-08 09:11:01 +00:00
Oriol Roqué Paniagua
7177b41e19 Merged PR 2516: Create host_user and user_role in intermediate
# Description

Adds 2 new tables:
- `int_core__user_role`: contains the relationship of a given user has a role.
- `int_core__user_host`: based on the previous table, it selects the users and main information from those users that are considered as hosts according to the role they have.

Note: I needed to change the test in stg. A user, generally, can have no role, one role, or multiple roles. Thus we cannot propagate this information in the unified_user model.

# 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: #19513
2024-08-07 14:28:34 +00:00
Oriol Roqué Paniagua
ad7d94b604 Merged PR 2511: Adding stg_core__role and stg_core__user_role in staging
# Description

Adds Role and UserRole in staging, in dedicated tables.
Open to discussion if you want me to directly apply this at User table level instead of having them in staging as standalone tables. Otherwise, staying with this PR as is, next step would be to integrate these roles in unified_user and create a dedicated user_host table in intermediate

# 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: #19513
2024-08-07 13:17:31 +00:00
Oriol Roqué Paniagua
94bdc53adf Merged PR 2498: Materialise int_dates_mtd and int_dates_by_deal as table to improve performance
# Description

Materialise int_dates_mtd and int_dates_by_deal as tables. This should improve the run speed as seen in local by quite a bit, and hopefully provide a better starting point for adding new dimensionality on business kpis.

I also documented these 2 models, that were missing :)

# 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: #19514
2024-08-06 15:03:32 +00:00
Joaquin Ossa
b1bdbc0f39 Merged PR 2459: duplicated_bookings modification
# Description

I modified the model of duplicated_bookings, I saw it had some errors and data that was not being used

# 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: #18875
2024-08-05 09:44:11 +00:00
Joaquin Ossa
7fe2d779e2 Merged PR 2469: Included the exchange rate to GBP in the model
# Description

Included the exchange rate to GBP in the model instead of joining the data inside the PBI report, for both understanding and easier joining

# 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

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

Included the exchange rate to GBP in the model

Related work items: #18875
2024-08-02 11:10:13 +00:00
Joaquin Ossa
a82ab121f1 Deleted an extra line 2024-08-01 16:18:25 +02:00
Joaquin Ossa
02ddac3167 Added a coalesce for the booking_fee_in_gbp calculation for old cases where there is no preferred currency for the user_guest 2024-08-01 16:15:48 +02:00
Joaquin Ossa
25e657014a Modified filter and table used 2024-08-01 14:32:45 +02:00
Joaquin Ossa
0281e6e72e Included the exchange rate to GBP in the model 2024-08-01 12:58:36 +02:00
Joaquin Ossa
161f4c1645 Merged PR 2467: Added host_booking_fees model to report
# Description

New model for report host_fees

# 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

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

Related work items: #18875
2024-08-01 10:01:54 +00:00
Joaquin Ossa
a75a4e9763 Added host_booking_fees model to report 2024-07-31 17:35:14 +02:00
Joaquin Ossa
adefe2d3ce Merged PR 2465: Creating model host_booking_fees
# Description

New model to replace in the host_fees report which is now including currencies

# 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: #18875
2024-07-31 15:19:12 +00:00
Joaquin Ossa
646ff7276a Added function to get false instead of null in is_duplicate_booking 2024-07-31 16:38:33 +02:00
Joaquin Ossa
78ffefb145 Thanks Uri for the catch, then when id_user_guest is NULL it won't be considered a duplicate. 2024-07-31 16:23:27 +02:00
Joaquin Ossa
6cb06b73cd Modified how stg_core__booking was being called and some typo errors 2024-07-31 15:32:54 +02:00
Joaquin Ossa
00e7554300 Creation of host_booking_fees 2024-07-31 15:16:15 +02:00
Joaquin Ossa
c4fc81d934 Included tests 2024-07-31 12:48:57 +02:00
Joaquin Ossa
9996368e22 I modified the model of duplicated_bookings, I saw it had some errors and data that was not being used 2024-07-31 12:44:54 +02:00
Pablo Martin
7ec5d91c6a Merge branch 'master' of ssh.dev.azure.com:v3/guardhog/Data/data-dwh-dbt-project 2024-07-30 16:26:42 +02:00
Pablo Martin
67087cc7cb pr template 2024-07-30 16:24:36 +02:00
Oriol Roqué Paniagua
65ebd8c2d2 Merged PR 2441: KPIs - Customer Segmentation based on listings
This PR creates a new model int_core__mtd_accommodation_segmentation that provides the customer segments based on listing activity:
- 0
- 1-5
- 6-20
- 21-60
- 61+

For end of April 2024, the volume distribution on number of deals and total listings booked is:
![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/2441/attachments/image.png)
For information, I estimate that around 3% of listings with bookings are missed, according to the data displayed in the KPIs for 30th April 2024. This is because we enforce deal-based categorisation (same happens with the deal view, anyway)

Related work items: #19325
2024-07-30 13:21:08 +00:00
Oriol Roqué Paniagua
b79df1b42e Merged PR 2433: Remove Deposit payments from Guest Payments metric
After discussion with Pablo on the fact that Deposits are only with status "Paid" for a given time before they get Cancelled or Refunded, we just believe it's best to remove the Deposits amount from the Guest Payments metric. In any case, this does not represent a Revenue source... This was discovered while doing the data quality assessment for revenue figures ([here](https://www.notion.so/knowyourguest-superhog/Data-quality-assessment-DWH-vs-Finance-revenue-figures-6e3d6b75cdd4463687de899da8aab6fb))

Before, `total_guest_payments_in_gbp` was a standalone metric that computed any payment by the guest with status paid. We were computing revenue based on the `total_guest_income_in_gbp`, which mainly was the sum of waiver payments, deposit fees (not deposit itself!) and check in hero fees.

Mainly what I did is:
- remove the existing `total_guest_payments_in_gbp` in the source models (int_core__xxx_guest_payments_xxx)
- rename the already existing `total_guest_income_in_gbp` to `total_guest_payments_in_gbp`

Related work items: #18787, #18914
2024-07-29 15:15:09 +00:00
Oriol Roqué Paniagua
b5e5160d67 Merged PR 2432: Exposing revenue metrics on the by deal view
Exposes the following metrics on the "by deal" view of business kpis:
1. Invoiced Booking Fees
1. Invoiced Listing Fees
1. Invoiced Verification Fees
1. Invoiced Guesty Fees
1. Invoiced E-Deposit Fees
1. Deposit Fees
1. Waiver Amount Paid by Guests
1. Waiver Amount Paid back to Hosts
1. Waiver Net Fees
1. Check-In Hero Amount Paid by Guests

This PR does not impact the visualisation in the dashboard, meaning, metrics won't automatically appear for users and needs an additional change in the PBI reporting.

Related work items: #18914
2024-07-29 14:54:50 +00:00
Oriol Roqué Paniagua
756d1c54d5 Merged PR 2429: Business KPIs - Revenue details
Exposes the following metrics:
1. Invoiced Booking Fees
1. Invoiced Listing Fees
1. Invoiced Verification Fees
1. Invoiced Guesty Fees
1. Invoiced E-Deposit Fees
1. Deposit Fees
1. Waiver Amount Paid by Guests
1. Waiver Amount Paid back to Hosts
1. Check-In Hero Amount Paid by Guests

This PR is only for Global metrics, the one by deal id will follow separately.
Keep in mind that merging this PR will make the data appear in the report.

Related work items: #18914
2024-07-29 13:16:19 +00:00
Oriol Roqué Paniagua
7e9b3733c8 Merged PR 2425: Fix model documentation names
Fix model documentation names after last PR, it triggered some warnings since the name was not correct. My bad :)

 ![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/2425/attachments/image.png)

Related work items: #18914
2024-07-29 09:38:44 +00:00
Oriol Roqué Paniagua
1b1b97380a Merged PR 2422: Ensure that guest payments models follow nomenclature
Small refactor to follow up on last week's PR. We removed from the Guest Revenue models the host-takes-waiver aspect, thus these models are now only depending from Core. We just need to migrate it from cross to core.

One small detail as well, since we do not take into account at these models level the host-takes-waiver, technically, I would not call these models revenue but rather Guest Payments. This is why I also took the opportunity to apply this name.

Changes:
- `int_monthly_guest_revenue_by_deal` is now `int_core__monthly_guest_payments_history_by_deal`, and the location has changed from `intermediate.cross` to `intermediate.core`
- `int_mtd_guest_revenue_metrics` is now `int_core__mtd_guest_payments_metrics`, and the location has changed from `intermediate.cross` to `intermediate.core`
- Schema changes, moving these 2 models' documentation with the new naming from Cross to Core
- Provide continuity in following dependants: `int_mtd_vs_previous_year_metrics` and `int_monthly_aggregated_metrics_history_by_deal` now read from the 2 new models respectively. Additionally, the model alias has changed from `guest_revenue` to `guest_payments` to keep consistency.

This PR does not expose new metrics, but should keep the existing ones unaffected.

Related work items: #18914
2024-07-29 09:10:58 +00:00
Oriol Roqué Paniagua
04eb09c318 Merged PR 2413: Adding submetrics of guest revenue by deal
Adding submetrics of guest revenue by deal:

- deposit_fees_in_gbp
- checkin_cover_fees_in_gbp
- waiver_payments_in_gbp

all of this adds up to

- total_guest_income_in_gbp

and the total_guest_revenue_in_gbp is now computed by subtracting waivers paid to hosts, coming from the invoiced model. This also affects the total revenue computation and the weighted metrics.

This PR it's completely equivalent to the [Adding submetrics of guest revenue](https://guardhog.visualstudio.com/Data/_git/data-dwh-dbt-project/pullrequest/2381?path=/models/intermediate/cross/int_mtd_guest_revenue_metrics.sql&_a=files), that was already merged for the global view. The only difference is that this one is for the deal-based part. It does not expose the metrics to the report.

A follow-up PR is expected to apply the correct naming conventions for guest revenue models.

I recommend checking the first commit, the one that applies the changes, and should be easily understandable with the link to the previous PR. There's a couple of additional commits that only affect formatting.

Related work items: #18787, #18914
2024-07-26 10:42:48 +00:00
Joaquin Ossa
da56aa3bb8 Merged PR 2400: Creating model in reporting
Creating model in reporting for check in hero

Related work items: #18190
2024-07-25 09:53:29 +00:00
Joaquin Ossa
bfe224577c Creating model in reporting 2024-07-25 11:34:07 +02:00
Joaquin Ossa
1fc1fc4c06 Merged PR 2392: Created new model with listings with check in hero active
Created new model with listings with check in hero active for the report so users can have access to this more granulated data

Related work items: #18190
2024-07-24 15:32:26 +00:00
Joaquin Ossa
e2fb73d558 Added count distinct 2024-07-24 17:31:25 +02:00
Joaquin Ossa
d08adfd2c0 Created new model with listings with check in hero active 2024-07-24 16:53:16 +02:00
Oriol Roqué Paniagua
fbd2bdd7f4 Merged PR 2381: Adding submetrics of guest revenue
Adding submetrics of guest revenue:
- deposit fees
- checkin cover fees
- waiver payments

all of this adds up to
- guest income

and the revenue is computed by subtracting waivers paid to hosts

Related work items: #18787
2024-07-23 13:50:03 +00:00
Oriol Roqué Paniagua
ee13eda5f3 Merged PR 2354: Main KPIs batch 2 exposure
This PR exposes the following metrics to the Main KPIs business overview report, for both Global + By Deal view:
- Total Revenue
- Total Revenue per Booking Created
- Total Revenue per Guest Journey Created
- Total Revenue per Deals Booked in Month (does not apply on the by deal view)
- Total Revenue per Listings Booked in Month
- Invoiced Operator Revenue
- Host Resolution Payment Count
- Host Resolution Amount Paid

Keep in mind Global view will be displaying these metrics once this is merged. I also changed a bit the order of the metric display.
Note that Billable Bookings are not included.

I recommend to review by 1) checking the first commit. This is almost the same as the previous abandoned PR that @<Joaquin Ossa> you already checked on Tuesday. I added a second commit, to be checked later, which basically fixes some stupid issues that if one of the source of revenue is null, then total revenue is null. This is specially critical for the view by deal, since most of them do not have revenue from APIs - thus all total revenue figures were null...

Related work items: #18108, #18109, #18110, #18719
2024-07-19 09:14:30 +00:00
Oriol Roqué Paniagua
361ad31299 Merged PR 2353: Computing and propagating APIs revenue metrics
Computing and propagating APIs revenue metrics.
I retrieved the revenues linked to Guesty and e-deposits. The sum of those are considered the total API revenue at this stage.
These 3 metrics are available in upper layers (not exposed yet to the report), just to fix the total revenue computation, which now includes APIs revenue

Related work items: #18719
2024-07-19 07:30:42 +00:00
Oriol Roqué Paniagua
b16cb172b6 Merged PR 2349: Retrieve account for xero invoices, credit notes and sales denom mart
Discussing with Jamie on how I can retrieve the information from Xero for E-deposit and Guesty, he told me that these go to a dedicated account. Since these are invoiced, they do not go to the bank transactions.
Specifically:
- 220 - E-Deposit Fees
- 219 - Guesty Fees
- 221 - Guesty Administration fee

After debugging the data (and getting confirmation from Jamie that indeed we were having invoices on e-deposit), I see that this info is available in the original json from staging. This PR aims just to retrieve these 3 fields:
- id_account
- account_code
- account_name

This will be used later on to retrieve the rest of API KPIs

Related work items: #18719
2024-07-18 15:47:14 +00:00
Oriol Roqué Paniagua
e250763a1c Merged PR 2317: Exposing first_day_month for business kpis
This PR exposes the field first_day_month in the business KPIs, for the Global view. It's just to be able to properly display graphs, since it's quite confusing doing it so by last_day_month (see screenshot)![image.png](https://guardhog.visualstudio.com/4148d95f-4b6d-4205-bcff-e9c8e0d2ca65/_apis/git/repositories/54ac356f-aad7-46d2-b62c-e8c5b3bb8ebf/pullRequests/2317/attachments/image.png)

Related work items: #18580
2024-07-16 09:14:38 +00:00
Oriol Roqué Paniagua
0df5209bac Merged PR 2305: Propagates billable bookings kpis in intermediate
Propagates billable bookings kpis in intermediate. Does not expose any metric to the report.

Changes:
- Retrieval and computation of previous_year and relative_increment for global view (mtd models)
- Retrieval as is for deal view

Related work items: #18111
2024-07-15 12:32:18 +00:00
Oriol Roqué Paniagua
0ac9f479da Merged PR 2301: KPIs Billable Bookings 1st version
This PR computes KPIs for Billable Bookings for both views (Global, by deal id)
It's the 1st version, mainly because numbers are not fully in-line with Jamie's export and I'd like to understand why. It uses booking_charge_events, as suggested by Pablo. In the meantime, I'm debugging the differences based on the invoicing export tool that provides Finance first rough numbers before amendment.

In any case, it can be used for a first rough idea.

Related work items: #18111
2024-07-15 10:59:37 +00:00
Oriol Roqué Paniagua
bf473ab971 Merged PR 2292: Propagate invoicing metrics for KPIs
This PR aims to propagate the invoicing metrics through the DWH. It does not expose them to users, yet.

This PR effectively computes the following metrics, for both the "global" view (MTD) and the "by deal" view (by_deal):
- Invoiced Operator Revenue
- Host Resolution Count of Payments
- Host Resolution Amount Paid

With these 3 new metrics, we're able to combine them with the existing ones to compute:
- Total Revenue
- Total Revenue per Booking Created
- Total Revenue per Guest Journey Created
- Total Revenue per Deal Booked in Month
- Total Revenue per Listings Booked in Month

You'll also note that I've included standalone metrics for booking fees, listing fees, verification fees and waiver payments. This will not be exposed in this batch 2, but based on the conversation with Finance, will clearly make it for batch 3. I just find it easier to add it now, since it's straight forward.

Main changes:
- `int_mtd_vs_previous_year_metrics` now computes all the above mentioned metrics
- `int_monthly_aggregated_metrics_history_by_deal` now computes all the above mentioned metrics, except Total Revenue per Deal Booked in Month since it does not make sense for the deal view. Additionally, I took the opportunity to include the missing metrics from listings (accommodations). The goal is not necessarily to display them, but at least compute it on our side.

Additional changes:
- In `int_xero__mtd_invoicing_metrics` and `int_xero__monthly_invoicing_history_by_deal`, there's a very silly name change to keep the same convention for fees: from `xero_operator_net_fees` to `xero_operator_net_fees_in_gbp`
- I applied additional changes in `int_monthly_aggregated_metrics_history_by_deal` with the goal to keep the same format as we have in `int_mtd_vs_previous_year_metrics`, this meaning:
1 - explicit alias naming (from `gj` to `guest_journeys`)
2 - keep a similar arrangement of metrics, and clearly separate scopes depending on the metric type
3 - Re-apply autoformatting

Related work items: #18108, #18109, #18110
2024-07-15 07:33:55 +00:00
Joaquin Ossa
698756e0f7 Merged PR 2295: Added booking_source to reporting model core__guest_satisfaction_responses
Added booking_source to reporting model core__guest_satisfaction_responses

Related work items: #17200
2024-07-15 07:08:57 +00:00
Joaquin Ossa
93a4664332 Added booking_source to reporting model core__guest_satisfaction_responses 2024-07-15 08:54:11 +02:00
Joaquin Ossa
506cb8043c Merged PR 2289: Added verification_request_booking_source to int_core__guest_satisfaction_res...
Added verification_request_booking_source to int_core__guest_satisfaction_responses model

Related work items: #17200
2024-07-12 13:20:23 +00:00
Oriol Roqué Paniagua
8a639413f1 Merged PR 2290: Refactor mtd joins to improve performance
Refactor mtd joins to improve performance, as stated in the ticket:

We noticed that some of the new models for MTD purposes (KPIs reporting) take quite a bit of time to run some simple joins.

The main reason is that there's a double join that can be simplified. The current state is:

```
from int_dates_mtd d
        inner join
            sometable t
            on extract(year from t.table_date) = d.year
            and extract(month from t.table_date) = d.month
            and extract(day from t.table_date) <= d.day
```

and it can be changed to:

```
from int_dates_mtd d
        inner join
            sometable t
            ​on date_trunc('month', t.table_date)::date = d.first_day_month
            and extract(day from t.table_date) <= d.day
```

which is way faster, and keeps the same computation

Related work items: #18330
2024-07-12 12:53:00 +00:00
Joaquin Ossa
5f05b725b9 Removed database sources on select 2024-07-12 13:11:56 +02:00
Joaquin Ossa
a837760382 Changed staging to intermediate 2024-07-12 12:45:46 +02:00
Joaquin Ossa
4d5af3ba21 Added verification_request_booking_source to int_core__guest_satisfaction_responses model 2024-07-12 12:38:52 +02:00
Oriol Roqué Paniagua
2130226939 Merged PR 2284: KPIs: computing invoicing metrics from Xero
This PR creates 2 new models on intermediate, xero:
- int_xero__mtd_invoicing_metrics (global view)
- int_xero__monthly_invoicing_history_by_deal (by deal view)

This allows for the computation of host metrics (operators), as well as host resolution payments. This will enable in the future to compute total revenue and weighted revenue metrics.
The data displayed from the previous months in the mtd_invoicing_metrics is consistent with 1) revenue figures displayed in business overview for Host tab, as well as Guest tab for Waiver Payments; and 2) host payment figures displayed in the accounting reports.

**Note 1**: the variables at this stage are reused in these models, as well as many other Xero models. We still need to handle the refactor ticket on Xero related reports. This is not under the scope of this PR.

**Note 2**: we noticed that the strategy for mtd models to do a double year, month extraction join is badly performant. Actually, resolution payments subquery was not performing at all with this logic. So it has been changed to a date_trunc('month', related_date)::date = d.first_day_month strategy which works much faster. I'll add a standalone PR to refactor the remaining mtd models separately later

Related work items: #18108, #18110
2024-07-12 10:05:49 +00:00
Joaquin Ossa
725dadd0a3 Merged PR 2275: Created model int_core__verification_request_booking_source to have easier ac...
Created model int_core__verification_request_booking_source to have easier access to host category type in different models

Related work items: #17200
2024-07-12 09:12:28 +00:00