{"id":33275752,"url":"https://github.com/trungbac11/self-serving-customer-metrics","last_synced_at":"2025-11-17T08:01:33.419Z","repository":{"id":324279520,"uuid":"1096675190","full_name":"trungbac11/self-serving-customer-metrics","owner":"trungbac11","description":null,"archived":false,"fork":false,"pushed_at":"2025-11-14T19:49:07.000Z","size":18042,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-14T21:26:14.160Z","etag":null,"topics":["duckdb","pyyaml","sql"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/trungbac11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-14T19:24:41.000Z","updated_at":"2025-11-14T19:49:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/trungbac11/self-serving-customer-metrics","commit_stats":null,"previous_names":["trungbac11/self-serving-customer-metrics"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/trungbac11/self-serving-customer-metrics","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungbac11%2Fself-serving-customer-metrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungbac11%2Fself-serving-customer-metrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungbac11%2Fself-serving-customer-metrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungbac11%2Fself-serving-customer-metrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/trungbac11","download_url":"https://codeload.github.com/trungbac11/self-serving-customer-metrics/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/trungbac11%2Fself-serving-customer-metrics/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":284846185,"owners_count":27072533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-17T02:00:06.431Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["duckdb","pyyaml","sql"],"created_at":"2025-11-17T08:01:03.773Z","updated_at":"2025-11-17T08:01:33.414Z","avatar_url":"https://github.com/trungbac11.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SELF-SERVING-CUSTOMER-METRICS\n\n**Context**: The Data Analysts in our team currently depend on data engineers to implement data pipelines for new customer metrics. This creates a bottleneck and slows down analysis.\n\n**Goal**: to build a simple prototype for that system.\n\n**Objective**: A lightweight prototype system that allows Data Analysts to define customer metrics using YAML + SQL, with automatic materialization in DuckDB.\n\n## Setup instructions\n### Prerequisites\n- Python 3.12+\n- Using Linux\n\n### Installation Steps\n1. **Clone the project**  `git clone https://github.com/trungbac11/self-serving-customer-metrics.git`\n\n2. **Create virtual enviroments**\n`python -m venv venv`\n\n3. **Active**\n`source venv/bin/activate`\n\n4. **Install dependencies:**\n`pip install --upgrade pip`\n`pip install -r requirements.txt`\n\n5. **Initialize the database into DuckDB:**\n`python src/setup_database.py`\n\n## Development guideline\n\n### Project Structure\n``` text\nproject/\n├── data/                   # Source CSV files\n├── metrics/               # Metric definitions (YAML)\n│   ├── lifetime_revenue.yaml\n│   ├── avg_order_revenue.yaml\n│   └── customer_geography.yaml\n├── src/                   # Python scripts\n│   ├── validate_yaml.py   # YAML validation\n│   ├── run_metrics.py     # Metric execution\n│   ├── setup_database.py  # DB initialization\n│   └── clean_database.py # DB cleanup\n├── requirements.txt       # Dependencies\n└── README.md              # Documentation\n```\n\n### Script Execution Guide\n\n#### Database Initialization:\n`python src/setup_database.py`\n\n#### Metric Definition Validation:\n`python src/validate_yaml.py`\n\n#### Metric Calculation and Storage:\n`python src/run_metrics.py`\n\n#### Database Cleanup:\n`python src/clean_database.py`\n\n### System Testing\n#### Validation Test Cases\n- Test with missing required fields\n\n- Test with invalid YAML syntax\n\n- Test with malformed SQL queries\n\n- Test with valid complete metric definitions\n\n#### Error Handling\n- All scripts include try-catch blocks for proper error handling\n\n- Validation provides clear error messages for debugging\n\n- Execution script continues processing other metrics if one fails\n\n#### Maintenance\n- Regular dependency updates: `pip install -r requirements.txt --upgrade`\n\n- Database cleanup when needed: `python src/clean_database.py`\n\n- Backup important data before major changes\n\n## How to add a new metric\n**Step 1: Create YAML Metric Definition**\n- Create a new .yaml file in the metrics/ directory with this structure\n\n**Step 2: Validate the Metric**\n- Run validation to check for errors: `python src/validate_yaml.py`\n\n**Step 3:  Execute the Metric**\n- Run the metric to create the table in DuckDB: `python src/run_metrics.py`\n\n**This will:**\n- Read all YAML files from /metrics\n- Execute each SQL query against DuckDB\n- Create or replace tables named after each metric\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrungbac11%2Fself-serving-customer-metrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrungbac11%2Fself-serving-customer-metrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrungbac11%2Fself-serving-customer-metrics/lists"}