Commit graph

359 commits

Author SHA1 Message Date
Oriol Roqué Paniagua
b61fe3f70d Merged PR 2522: Don't Repeat Yourself for KPIs - Applied to Bookings
# Description

What's new:
- Creation of `get_kpi_dimensions`: new macro to have a single point of source of configuration for dimensions for the KPIs. It's a way to enforce global variables on-demand. I kind of like this approach and we could do it for Xero models as well :)
- Modification of `int_core__mtd_booking_metrics` and `int_dates_mtd_by_dimension`: removal of duplicated code within the dimension context. Uses Jinja code and applies different configurations depending on the dimension chosen. Still, different metrics are placed in different CTEs. I believe it might be possible to also configure metrics BUT at the cost of over-complexifying the macro logic, so I wouldn't go for it at this stage.

# 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: #19325
2024-08-08 13:19:57 +00:00
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
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
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
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
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
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
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
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
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
Joaquin Ossa
cf467145d0 Fixed schema names 2024-07-12 11:06:09 +02:00
Joaquin Ossa
3001db919a Added models in schema for intermediate 2024-07-12 10:11:51 +02:00
Joaquin Ossa
2bfe3ccf3c Added the new field to int_core__bookings and to int_core__verification_requests 2024-07-11 17:16:51 +02:00
Joaquin Ossa
70c2c5f6bf Removed guests_id and modified query structure 2024-07-11 16:49:24 +02:00
Joaquin Ossa
00502b1597 Removed bookings_id so we have unique values for id_verification_request, added details as to how we classify the hosts 2024-07-11 16:26:41 +02:00
Joaquin Ossa
db04615039 Removed bookings_id so we have unique values for id_verification_request, added details as to how we classify the hosts 2024-07-11 16:19:33 +02:00
Joaquin Ossa
5efd91dfbb Created model int_core__verification_request_booking_source to have easier access to host category type in different models 2024-07-11 15:36:32 +02:00
Oriol Roqué Paniagua
3b75d9eefb Merged PR 2257: Expose guest revenue and guest journey payment metrics
This PR aims to expose the new metrics to the business KPIs report.
The new metrics exposed are, for the global and the by deal view:
- Guest Revenue
- Guest Revenue per Guest Journey Completed
- Guest Revenue per Guest Journey with Payment
- Guest Payments
- Guest Payments per Guest Journey Completed
- Guest Payments per Guest Journey with Payment
- Guest Journey with Payment
- Guest Journey Payment Rate

Changes:
- Silly change on the naming in the by deal view of `payment_rate_guest_journey` to be consistent with the global view.
- Silly change that I miss some GJ payment metric for the view by deal id.
- Added a new number format called `currency_gbp` - only for monetary metrics, available in the schema files
- Usual procedure to publish metrics: for global metrics, add them in the `int_mtd_aggregated_metrics`. I also changed the order of display.
- **Important**: to avoid displaying revenue figures until Xero invoicing is handled, I created a macro called `is_date_before_previous_month` that is called in the reporting equivalent models: `mtd_aggregated_metrics` in the where section and in the `monthly_aggregated_metrics_history_by_deal` as a case-when.

This should allow to expose all new metrics, and enable the publishing of a new update of the business kpis!

Related work items: #18107
2024-07-10 14:17:05 +00:00
Oriol Roqué Paniagua
20e7220ffe Merged PR 2246: KPIs refactor: naming convention and PBI sources replication
Changing naming to follow convention.
This PR has the following changes:
- the model `int_core__mtd_aggregated_metrics` has been moved to cross and changed the name to `int_mtd_aggregated_metrics`
- the model `int_core__monthly_aggregated_metrics_history_by_deal` has been moved to cross and changed the name to `int_monthly_aggregated_metrics_history_by_deal`
- the reporting models `core__mtd_aggregated_metrics` and `core__monthly_aggregated_metrics_history_by_deal` now source the `int_mtd_aggregated_metrics` and `int_monthly_aggregated_metrics_history_by_deal` to avoid breaking the production dashboard
- the reporting models have been duplicated from core into general with the correct names, i.e., `mtd_aggregated_metrics` and `monthly_aggregated_metrics_history_by_deal`
- Documentation has been moved in intermediate and replicated in reporting, adding comments on the currently in use models that are going to die soon.

This will allow for a transition of the PBI dashboard from one source to another. Exposures file still not touched since technically the report is still sourcing the 'legacy' models. Documentation of the refactor here: https://www.notion.so/knowyourguest-superhog/Refactoring-Business-KPIs-5deb6aadddb34884ae90339402ac16e3

Related work items: #18202
2024-07-09 15:14:50 +00:00
Oriol Roqué Paniagua
ca8334f1da Merged PR 2236: Refactor of already exposed metrics: listings, deals and guest journeys
Following yesterday's refactor of booking metrics, this PR provides a refactor of already exposed metrics: listings, deals and guest journeys.
-> Data is consistent with values already exposed.

Changes:
- for `int_core__mtd_listing_metrics`, `int_core__mtd_deal_metrics` and `int_core__mtd_guest_journey_metrics`:
1. remove the computation of the previous year metric value and the relative increment (last part of the query)
2. re-apply the formatting
- for `int_mtd_vs_previous_year_metrics`:
1. Reference listings, deals and GJ models
2. Include the metrics for these types in the `plain_kpi_combination` CTE
3. Add the computation of previous year and relative increment using the macro
- for `int_core__mtd_aggregated_metrics`
1. Remove and "hardcode" sources since all metrics now depend exclusively of `int_mtd_vs_previous_year_metrics`

This PR does not alter the exposed metrics in the production report. It does not aim to change the name of the reporting/intermediate models that expose the information, it will be done in a separated PR.
Documentation: https://www.notion.so/knowyourguest-superhog/Refactoring-Business-KPIs-5deb6aadddb34884ae90339402ac16e3

Related work items: #18202
2024-07-09 13:00:43 +00:00
Oriol Roqué Paniagua
409ac47591 Merged PR 2232: KPI refactor - 1st step, bookings
First step on refactor of kpis:
- Remove relative incremental vs. previous year computation from the source model (`mtd_booking_metrics`, in this case)
- Aggregate the source mtd global metrics models into a single model: `int_mtd_vs_previous_year_metrics` (to enable multi-source weighted metric computation) and compute previous year value and relative increment. Now this logic is encapsulated into a macro `calculate_safe_relative_increment`, easing readability and providing a bit more robustness.
- End-to-end continuity to not break the existing dashboard display in `int_core__mtd_aggregated_metrics`

This is a substep of the global change. All info can be found in the documentation [here](https://www.notion.so/knowyourguest-superhog/Refactoring-Business-KPIs-5deb6aadddb34884ae90339402ac16e3)

Related work items: #18202
2024-07-08 15:58:36 +00:00
Joaquin Ossa
03dbe60b38 Fixed join on model taking id_verification instead of id_verification_request 2024-07-05 17:24:06 +02:00
Joaquin Ossa
34df8a7ef9 Merged PR 2201: Fixing errors raised by texts
Tiny PR to fix errors raised by texts
2024-07-05 15:12:04 +00:00
Joaquin Ossa
2738c8617d Fixing errors raised by texts 2024-07-04 16:41:41 +02:00
Joaquin Ossa
2efc1d8b65 Merged PR 2178: New model for guests satisfaction report
New model for guests satisfaction report, I included columns to check what is the guest paying for that might be helpful for analysis as well

Related work items: #16947
2024-07-04 10:13:11 +00:00
Joaquin Ossa
2c366414ce Merged PR 2188: Added date of adaptation
Added date of adaptation when hosts first started using check-in cover
2024-07-04 10:08:13 +00:00
Oriol Roqué Paniagua
1781031c9d Merged PR 2195: Computes GJ with Payment and GJ Payment Rate metrics
Adds the following metrics:
- Guest Journey with Payment
- Guest Journey Payment Rate

by both visions (global and by deal id)

**Important**: it does not expose these metrics to the dashboard, this will be done after we have feedback from Ben R. on the paid GJ without GJ completeness. Missing steps to make them appear is to adapt `int_core__mtd_aggregated_metrics` and `int_core__monthly_aggregated_metrics_history_by_deal` and the respective reporting counterparts.

It adapts:
- `int_core__mtd_guest_journey_metrics`
- `int_core__monthly_guest_journey_history_by_deal`

the approaches are similar in the sense that we join with `int_core__verification_payments` and filter by a PAID status, that has been defined in the `dbt_project.yml` in a similar manner as we did with cancelled bookings. It can happen that the same verification request has multiple payments (see screenshot), which in this case we keep the first date in which the paid payment happens. The volume is quite low anyway.

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

```
with pre as (
select
	id_verification_request,
	count(distinct icvp.id_payment) as total_paid_payments
from intermediate.int_core__verification_payments icvp
where icvp.payment_status = 'Paid'
group by 1
)
select
	case when total_paid_payments > 2 then 'more than 2'
	when total_paid_payments = 2 then '2'
	when total_paid_payments = 1 then '1'
	end as payment_volume_category,
	count(1) as vr_volume
from pre
group by 1
order by 2 desc
```

I also added a missing reference in `schema.yaml` int about `int_core__mtd_guest_journey_metrics`

Related work items: #18105
2024-07-04 09:54:41 +00:00
Joaquin Ossa
205bc6534d Modified date name to stick to convention 2024-07-04 08:24:23 +02:00
Joaquin Ossa
6bc26a66ff Changed date name to check_in_cover_added_date and included model in reporting 2024-07-03 17:43:27 +02:00
Joaquin Ossa
5bd6a2c254 Changed case to coalesce 2024-07-03 17:38:00 +02:00
Joaquin Ossa
3b22832d8b Created model in reporting as well with schema 2024-07-03 16:34:33 +02:00
Joaquin Ossa
fb61c69714 Changed names of types of payments for better clarity 2024-07-03 16:23:52 +02:00
Joaquin Ossa
3ce81dfdd1 Fixed the filter for check-in cover verification set and changed named to adopted 2024-07-03 16:16:58 +02:00
Joaquin Ossa
35e4735720 Added date of birth and kept age 2024-07-03 15:18:05 +02:00