Addressed comments
This commit is contained in:
parent
264ce4e203
commit
60dfae5cf4
16 changed files with 147 additions and 236 deletions
|
|
@ -171,16 +171,7 @@ Provides a general assignement for the Dimensions available for each KPI
|
|||
] %}
|
||||
{% endif %}
|
||||
|
||||
{% if entity_name == "NEW_DASH_CREATED_SERVICES" %}
|
||||
{% set additional_dimensions = additional_dimensions + [
|
||||
dim_has_upgraded_service(),
|
||||
dim_new_dash_version(),
|
||||
dim_pricing_service(),
|
||||
dim_pricing_business_type(),
|
||||
] %}
|
||||
{% endif %}
|
||||
|
||||
{% if entity_name == "NEW_DASH_CHARGEABLE_SERVICES" %}
|
||||
{% if entity_name == "NEW_DASH" %}
|
||||
{% set additional_dimensions = additional_dimensions + [
|
||||
dim_has_upgraded_service(),
|
||||
dim_new_dash_version(),
|
||||
|
|
@ -198,24 +189,6 @@ Provides a general assignement for the Dimensions available for each KPI
|
|||
] %}
|
||||
{% endif %}
|
||||
|
||||
{% if entity_name == "NEW_DASH_ACCOMMODATION_OFFERED_SERVICES" %}
|
||||
{% set additional_dimensions = additional_dimensions + [
|
||||
dim_has_upgraded_service(),
|
||||
dim_new_dash_version(),
|
||||
dim_pricing_service(),
|
||||
dim_pricing_business_type(),
|
||||
] %}
|
||||
{% endif %}
|
||||
|
||||
{% if entity_name == "NEW_DASH_CREATED_BOOKINGS" %}
|
||||
{% set additional_dimensions = additional_dimensions + [
|
||||
dim_has_upgraded_service(),
|
||||
dim_new_dash_version(),
|
||||
dim_pricing_service(),
|
||||
dim_pricing_business_type(),
|
||||
] %}
|
||||
{% endif %}
|
||||
|
||||
{# Combine base dimensions with additional dimensions for the specific model #}
|
||||
{% set dimensions = base_dimensions + additional_dimensions %}
|
||||
{{ return(dimensions) }}
|
||||
|
|
|
|||
23
macros/generate_kpis_aggregation.sql
Normal file
23
macros/generate_kpis_aggregation.sql
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{% macro generate_kpis_aggregation(time_granularity, agg_models) %}
|
||||
select
|
||||
d.date,
|
||||
'{{ time_granularity }}' as time_granularity,
|
||||
d.dimension,
|
||||
d.dimension_value
|
||||
{%- for agg_model in agg_models if time_granularity in agg_model["name"] %}
|
||||
{%- for metric in agg_model["metrics"] %}
|
||||
, coalesce({{ ref(agg_model["name"]) }}.{{ metric }}, 0) as {{ metric }}
|
||||
{%- endfor %}
|
||||
{%- endfor %}
|
||||
from all_dates d
|
||||
{%- for agg_model in agg_models if time_granularity in agg_model["name"] %}
|
||||
left join
|
||||
{{ ref(agg_model["name"]) }}
|
||||
on d.date = {{ ref(agg_model["name"]) }}.{{ agg_model["date_field"] }}
|
||||
and d.dimension = {{ ref(agg_model["name"]) }}.dimension
|
||||
and d.dimension_value = {{ ref(agg_model["name"]) }}.dimension_value
|
||||
{%- endfor %}
|
||||
{% if time_granularity == "weekly" %} where d.is_end_of_week
|
||||
{% elif time_granularity == "monthly" %} where d.is_end_of_month
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
|
@ -1,6 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model(
|
||||
"NEW_DASH_ACCOMMODATION_OFFERED_SERVICES"
|
||||
) %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model(
|
||||
"NEW_DASH_ACCOMMODATION_OFFERED_SERVICES"
|
||||
) %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{
|
||||
config(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{
|
||||
config(
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model(
|
||||
"NEW_DASH_ACCOMMODATION_OFFERED_SERVICES"
|
||||
) %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CHARGEABLE_SERVICES") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{
|
||||
config(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_BOOKINGS") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{ config(materialized="table", unique_key=["date", "dimension", "dimension_value"]) }}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH_CREATED_SERVICES") %}
|
||||
{% set dimensions = get_kpi_dimensions_per_model("NEW_DASH") %}
|
||||
|
||||
{{
|
||||
config(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
materialized="table",
|
||||
unique_key=[
|
||||
"date",
|
||||
"id_deal",
|
||||
"id_booking",
|
||||
"id_user_product_bundle",
|
||||
"service_name",
|
||||
"service_business_type",
|
||||
|
|
|
|||
|
|
@ -1,208 +1,129 @@
|
|||
{% set agg_models = [
|
||||
{
|
||||
"name": "int_kpis__agg_daily_new_dash_created_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["created_services"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_daily_new_dash_chargeable_services",
|
||||
"date_field": "date",
|
||||
"metrics": [
|
||||
"total_chargeable_services",
|
||||
"total_chargeable_amount_in_gbp",
|
||||
"unique_chargeable_bookings",
|
||||
"unique_chargeable_listings",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_daily_new_dash_deals_offered_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["deal_with_offered_service_count"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_daily_new_dash_accommodation_offered_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["accommodation_with_offered_service_count"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_daily_new_dash_created_bookings",
|
||||
"date_field": "date",
|
||||
"metrics": ["created_bookings"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_weekly_new_dash_created_services",
|
||||
"date_field": "end_date",
|
||||
"metrics": ["created_services"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_weekly_new_dash_chargeable_services",
|
||||
"date_field": "end_date",
|
||||
"metrics": [
|
||||
"total_chargeable_services",
|
||||
"total_chargeable_amount_in_gbp",
|
||||
"unique_chargeable_bookings",
|
||||
"unique_chargeable_listings",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_weekly_new_dash_deals_offered_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["deal_with_offered_service_count"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_weekly_new_dash_accommodation_offered_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["accommodation_with_offered_service_count"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_weekly_new_dash_created_bookings",
|
||||
"date_field": "end_date",
|
||||
"metrics": ["created_bookings"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_monthly_new_dash_created_services",
|
||||
"date_field": "end_date",
|
||||
"metrics": ["created_services"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_monthly_new_dash_chargeable_services",
|
||||
"date_field": "end_date",
|
||||
"metrics": [
|
||||
"total_chargeable_services",
|
||||
"total_chargeable_amount_in_gbp",
|
||||
"unique_chargeable_bookings",
|
||||
"unique_chargeable_listings",
|
||||
],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_monthly_new_dash_deals_offered_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["deal_with_offered_service_count"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_monthly_new_dash_accommodation_offered_services",
|
||||
"date_field": "date",
|
||||
"metrics": ["accommodation_with_offered_service_count"],
|
||||
},
|
||||
{
|
||||
"name": "int_kpis__agg_monthly_new_dash_created_bookings",
|
||||
"date_field": "end_date",
|
||||
"metrics": ["created_bookings"],
|
||||
},
|
||||
] %}
|
||||
|
||||
with
|
||||
int_kpis__agg_daily_new_dash_created_services as (
|
||||
select * from {{ ref("int_kpis__agg_daily_new_dash_created_services") }}
|
||||
),
|
||||
int_kpis__agg_weekly_new_dash_created_services as (
|
||||
select * from {{ ref("int_kpis__agg_weekly_new_dash_created_services") }}
|
||||
),
|
||||
int_kpis__agg_monthly_new_dash_created_services as (
|
||||
select * from {{ ref("int_kpis__agg_monthly_new_dash_created_services") }}
|
||||
),
|
||||
int_kpis__agg_daily_new_dash_chargeable_services as (
|
||||
select * from {{ ref("int_kpis__agg_daily_new_dash_chargeable_services") }}
|
||||
),
|
||||
int_kpis__agg_weekly_new_dash_chargeable_services as (
|
||||
select * from {{ ref("int_kpis__agg_weekly_new_dash_chargeable_services") }}
|
||||
),
|
||||
int_kpis__agg_monthly_new_dash_chargeable_services as (
|
||||
select * from {{ ref("int_kpis__agg_monthly_new_dash_chargeable_services") }}
|
||||
),
|
||||
int_kpis__agg_daily_new_dash_deals_offered_services as (
|
||||
select * from {{ ref("int_kpis__agg_daily_new_dash_deals_offered_services") }}
|
||||
),
|
||||
int_kpis__agg_weekly_new_dash_deals_offered_services as (
|
||||
select * from {{ ref("int_kpis__agg_weekly_new_dash_deals_offered_services") }}
|
||||
),
|
||||
int_kpis__agg_monthly_new_dash_deals_offered_services as (
|
||||
select * from {{ ref("int_kpis__agg_monthly_new_dash_deals_offered_services") }}
|
||||
),
|
||||
int_kpis__agg_daily_new_dash_accommodation_offered_services as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_daily_new_dash_accommodation_offered_services") }}
|
||||
),
|
||||
int_kpis__agg_weekly_new_dash_accommodation_offered_services as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_weekly_new_dash_accommodation_offered_services") }}
|
||||
),
|
||||
int_kpis__agg_monthly_new_dash_accommodation_offered_services as (
|
||||
select *
|
||||
from {{ ref("int_kpis__agg_monthly_new_dash_accommodation_offered_services") }}
|
||||
),
|
||||
int_kpis__agg_daily_new_dash_created_bookings as (
|
||||
select * from {{ ref("int_kpis__agg_daily_new_dash_created_bookings") }}
|
||||
),
|
||||
int_kpis__agg_weekly_new_dash_created_bookings as (
|
||||
select * from {{ ref("int_kpis__agg_weekly_new_dash_created_bookings") }}
|
||||
),
|
||||
int_kpis__agg_monthly_new_dash_created_bookings as (
|
||||
select * from {{ ref("int_kpis__agg_monthly_new_dash_created_bookings") }}
|
||||
),
|
||||
int_kpis__dimension_dates as (select * from {{ ref("int_kpis__dimension_dates") }}),
|
||||
|
||||
all_dates as (
|
||||
select distinct
|
||||
c.date, c.dimension, c.dimension_value, d.is_end_of_week, d.is_end_of_month
|
||||
from
|
||||
(
|
||||
select date, dimension, dimension_value
|
||||
from int_kpis__agg_daily_new_dash_created_services
|
||||
from {{ ref("int_kpis__agg_daily_new_dash_created_services") }}
|
||||
union all
|
||||
select date, dimension, dimension_value
|
||||
from int_kpis__agg_daily_new_dash_chargeable_services
|
||||
from {{ ref("int_kpis__agg_daily_new_dash_chargeable_services") }}
|
||||
union all
|
||||
select date, dimension, dimension_value
|
||||
from int_kpis__agg_daily_new_dash_deals_offered_services
|
||||
from {{ ref("int_kpis__agg_daily_new_dash_deals_offered_services") }}
|
||||
union all
|
||||
select date, dimension, dimension_value
|
||||
from int_kpis__agg_daily_new_dash_accommodation_offered_services
|
||||
from
|
||||
{{
|
||||
ref(
|
||||
"int_kpis__agg_daily_new_dash_accommodation_offered_services"
|
||||
)
|
||||
}}
|
||||
) c
|
||||
left join int_kpis__dimension_dates d on c.date = d.date
|
||||
)
|
||||
select
|
||||
d.date,
|
||||
'daily' as time_granularity,
|
||||
d.dimension,
|
||||
d.dimension_value,
|
||||
coalesce(
|
||||
deals.deal_with_offered_service_count, 0
|
||||
) as deal_with_offered_service_count,
|
||||
coalesce(
|
||||
accommodation.accommodation_with_offered_service_count, 0
|
||||
) as accommodation_with_offered_service_count,
|
||||
coalesce(created.created_services, 0) as created_services,
|
||||
coalesce(bookings.created_bookings, 0) as created_bookings_count,
|
||||
coalesce(chargeable.total_chargeable_services, 0) as total_chargeable_services,
|
||||
coalesce(
|
||||
chargeable.total_chargeable_amount_in_gbp, 0
|
||||
) as total_chargeable_amount_in_gbp,
|
||||
coalesce(chargeable.unique_chargeable_bookings, 0) as unique_chargeable_bookings,
|
||||
coalesce(chargeable.unique_chargeable_listings, 0) as unique_chargeable_listings
|
||||
from all_dates d
|
||||
left join
|
||||
int_kpis__agg_daily_new_dash_created_services created
|
||||
on d.date = created.date
|
||||
and d.dimension = created.dimension
|
||||
and d.dimension_value = created.dimension_value
|
||||
left join
|
||||
int_kpis__agg_daily_new_dash_chargeable_services chargeable
|
||||
on d.date = chargeable.date
|
||||
and d.dimension = chargeable.dimension
|
||||
and d.dimension_value = chargeable.dimension_value
|
||||
left join
|
||||
int_kpis__agg_daily_new_dash_deals_offered_services deals
|
||||
on d.date = deals.date
|
||||
and d.dimension = deals.dimension
|
||||
and d.dimension_value = deals.dimension_value
|
||||
left join
|
||||
int_kpis__agg_daily_new_dash_accommodation_offered_services accommodation
|
||||
on d.date = accommodation.date
|
||||
and d.dimension = accommodation.dimension
|
||||
and d.dimension_value = accommodation.dimension_value
|
||||
left join
|
||||
int_kpis__agg_daily_new_dash_created_bookings bookings
|
||||
on d.date = bookings.date
|
||||
and d.dimension = bookings.dimension
|
||||
and d.dimension_value = bookings.dimension_value
|
||||
|
||||
select *
|
||||
from ({{ generate_kpis_aggregation("daily", agg_models) }})
|
||||
union all
|
||||
select
|
||||
d.date,
|
||||
'weekly' as time_granularity,
|
||||
d.dimension,
|
||||
d.dimension_value,
|
||||
coalesce(
|
||||
deals.deal_with_offered_service_count, 0
|
||||
) as deal_with_offered_service_count,
|
||||
coalesce(
|
||||
accommodation.accommodation_with_offered_service_count, 0
|
||||
) as accommodation_with_offered_service_count,
|
||||
coalesce(created.created_services, 0) as created_services,
|
||||
coalesce(bookings.created_bookings, 0) as created_bookings_count,
|
||||
coalesce(chargeable.total_chargeable_services, 0) as total_chargeable_services,
|
||||
coalesce(
|
||||
chargeable.total_chargeable_amount_in_gbp, 0
|
||||
) as total_chargeable_amount_in_gbp,
|
||||
coalesce(chargeable.unique_chargeable_bookings, 0) as unique_chargeable_bookings,
|
||||
coalesce(chargeable.unique_chargeable_listings, 0) as unique_chargeable_listings
|
||||
from all_dates d
|
||||
left join
|
||||
int_kpis__agg_weekly_new_dash_created_services created
|
||||
on d.date = created.end_date
|
||||
and d.dimension = created.dimension
|
||||
and d.dimension_value = created.dimension_value
|
||||
left join
|
||||
int_kpis__agg_weekly_new_dash_chargeable_services chargeable
|
||||
on d.date = chargeable.end_date
|
||||
and d.dimension = chargeable.dimension
|
||||
and d.dimension_value = chargeable.dimension_value
|
||||
left join
|
||||
int_kpis__agg_weekly_new_dash_deals_offered_services deals
|
||||
on d.date = deals.date
|
||||
and d.dimension = deals.dimension
|
||||
and d.dimension_value = deals.dimension_value
|
||||
left join
|
||||
int_kpis__agg_weekly_new_dash_accommodation_offered_services accommodation
|
||||
on d.date = accommodation.date
|
||||
and d.dimension = accommodation.dimension
|
||||
and d.dimension_value = accommodation.dimension_value
|
||||
left join
|
||||
int_kpis__agg_weekly_new_dash_created_bookings bookings
|
||||
on d.date = bookings.end_date
|
||||
and d.dimension = bookings.dimension
|
||||
and d.dimension_value = bookings.dimension_value
|
||||
where d.is_end_of_week
|
||||
select *
|
||||
from ({{ generate_kpis_aggregation("weekly", agg_models) }})
|
||||
union all
|
||||
select
|
||||
d.date,
|
||||
'monthly' as time_granularity,
|
||||
d.dimension,
|
||||
d.dimension_value,
|
||||
coalesce(
|
||||
deals.deal_with_offered_service_count, 0
|
||||
) as deal_with_offered_service_count,
|
||||
coalesce(
|
||||
accommodation.accommodation_with_offered_service_count, 0
|
||||
) as accommodation_with_offered_service_count,
|
||||
coalesce(created.created_services, 0) as created_services,
|
||||
coalesce(bookings.created_bookings, 0) as created_bookings_count,
|
||||
coalesce(chargeable.total_chargeable_services, 0) as total_chargeable_services,
|
||||
coalesce(
|
||||
chargeable.total_chargeable_amount_in_gbp, 0
|
||||
) as total_chargeable_amount_in_gbp,
|
||||
coalesce(chargeable.unique_chargeable_bookings, 0) as unique_chargeable_bookings,
|
||||
coalesce(chargeable.unique_chargeable_listings, 0) as unique_chargeable_listings
|
||||
from all_dates d
|
||||
left join
|
||||
int_kpis__agg_monthly_new_dash_created_services created
|
||||
on d.date = created.end_date
|
||||
and d.dimension = created.dimension
|
||||
and d.dimension_value = created.dimension_value
|
||||
left join
|
||||
int_kpis__agg_monthly_new_dash_chargeable_services chargeable
|
||||
on d.date = chargeable.end_date
|
||||
and d.dimension = chargeable.dimension
|
||||
and d.dimension_value = chargeable.dimension_value
|
||||
left join
|
||||
int_kpis__agg_monthly_new_dash_deals_offered_services deals
|
||||
on d.date = deals.date
|
||||
and d.dimension = deals.dimension
|
||||
and d.dimension_value = deals.dimension_value
|
||||
left join
|
||||
int_kpis__agg_monthly_new_dash_accommodation_offered_services accommodation
|
||||
on d.date = accommodation.date
|
||||
and d.dimension = accommodation.dimension
|
||||
and d.dimension_value = accommodation.dimension_value
|
||||
left join
|
||||
int_kpis__agg_monthly_new_dash_created_bookings bookings
|
||||
on d.date = bookings.end_date
|
||||
and d.dimension = bookings.dimension
|
||||
and d.dimension_value = bookings.dimension_value
|
||||
where d.is_end_of_month
|
||||
select *
|
||||
from ({{ generate_kpis_aggregation("monthly", agg_models) }})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue