agnes-the-ai-analyst/docs/metrics/customers/customer_count.yml
Petr 5a84473213 Add dynamic Business Metrics with sample e-commerce definitions
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
2026-03-10 22:38:44 +01:00

39 lines
1.1 KiB
YAML

- name: customer_count
display_name: Customer Count
category: customers
type: count_distinct
unit: customers
grain: monthly
time_column: created_at
table: customers
expression: "COUNT(DISTINCT customer_id)"
description: "Total number of unique customers. Tracks customer base growth over time. Counts distinct customer records based on registration date."
dimensions:
- segment
- region
- acquisition_channel
notes:
- "Counts only active customers (not deleted or merged)"
- "A customer is counted in the month of their first registration"
- "Segment is assigned based on lifetime spend thresholds"
synonyms:
- total_customers
- customer_base
- active_customers
sql: |
SELECT
DATE_TRUNC('month', created_at) AS month,
COUNT(DISTINCT customer_id) AS new_customers
FROM customers
WHERE status = 'active'
GROUP BY 1
ORDER BY 1
sql_by_segment: |
SELECT
segment,
COUNT(DISTINCT customer_id) AS customer_count,
AVG(lifetime_value) AS avg_ltv
FROM customers
WHERE status = 'active'
GROUP BY 1
ORDER BY 2 DESC