Replace hardcoded Keboola-specific metrics card in Data Catalog with dynamic Jinja template that renders whatever metric YAMLs exist in docs/metrics/. Add 10 sample e-commerce metric definitions across 4 categories (revenue, customers, marketing, support) that align with the sample data generator tables. Key changes: - MetricParser: new category colors + dynamic sql_* field discovery - _load_metrics_data(): scans docs/metrics/*/*.yml with prod fallback - catalog.html: 240 lines hardcoded HTML -> 35 lines Jinja loop - metric_modal.js: regex-based category class removal, new categories - 21 tests validating YAML schema, parser, and loader
45 lines
1.3 KiB
YAML
45 lines
1.3 KiB
YAML
- name: average_order_value
|
|
display_name: Average Order Value
|
|
category: revenue
|
|
type: average
|
|
unit: USD
|
|
grain: monthly
|
|
time_column: order_date
|
|
table: orders
|
|
tables:
|
|
- orders
|
|
- customers
|
|
expression: "AVG(total_amount)"
|
|
description: "Average monetary value per order. Key indicator of customer purchasing behavior and pricing effectiveness. Joins to customers for segmentation."
|
|
dimensions:
|
|
- channel
|
|
- customer_segment
|
|
- product_category
|
|
- is_first_order
|
|
notes:
|
|
- "Calculated only on completed orders"
|
|
- "Joins to customers table via customer_id for segment analysis"
|
|
- "Useful to compare AOV by new vs returning customers"
|
|
synonyms:
|
|
- aov
|
|
- avg_basket_size
|
|
sql: |
|
|
SELECT
|
|
DATE_TRUNC('month', o.order_date) AS month,
|
|
AVG(o.total_amount) AS avg_order_value,
|
|
COUNT(*) AS order_count
|
|
FROM orders o
|
|
WHERE o.status = 'completed'
|
|
GROUP BY 1
|
|
ORDER BY 1
|
|
sql_by_segment: |
|
|
SELECT
|
|
DATE_TRUNC('month', o.order_date) AS month,
|
|
c.segment AS customer_segment,
|
|
AVG(o.total_amount) AS avg_order_value,
|
|
COUNT(*) AS order_count
|
|
FROM orders o
|
|
JOIN customers c ON o.customer_id = c.customer_id
|
|
WHERE o.status = 'completed'
|
|
GROUP BY 1, 2
|
|
ORDER BY 1, 3 DESC
|