Skip to content

A framework for quickly creating metrics using easy-to-edit YAML configs and reusable methods to filter, calculate, and transform data.

License

Notifications You must be signed in to change notification settings

nhsengland/quick_metric

Repository files navigation

Quick Metric

RAP Status: Gold Python: 3.10 | 3.11 | 3.12 Code Style: Ruff Linting: Ruff Testing: tox pre-commit licence: MIT licence: OGL3 Tests and Linting Documentation build with Material for MkDocs

Welcome to Quick Metric - a framework for quickly creating metrics using easy-to-edit YAML configs and reusable methods to filter, calculate, and transform data.

Installation

# Clone the repository
git clone <repository-url>
cd quick_metric

# Create virtual environment and install
uv venv && source .venv/bin/activate
uv pip install -e .

Quick Start

from quick_metric import metric_method, generate_metrics
import pandas as pd

# 1. Define custom metrics
@metric_method
def count_records(data):
    return len(data)

@metric_method
def mean_value(data, column='value'):
    return data[column].mean()

# 2. Create data and config
data = pd.DataFrame({'category': ['A', 'B', 'A'], 'value': [10, 20, 30]})
config = {
    'category_a_metrics': {
        'method': ['count_records', 'mean_value'],
        'filter': {'category': 'A'}
    }
}

# 3. Generate metrics
results = generate_metrics(data, config)
print(results['category_a_metrics']['count_records'])  # 2
print(results['category_a_metrics']['mean_value'])     # 20.0

Key Features

  • Simple decorator: Register metrics with @metric_method
  • Flexible configuration: Use dictionaries or YAML files
  • Multiple output formats: Nested dict, DataFrame, records, or flat DataFrame
  • Advanced filtering: Complex data filtering with logical operators
  • Pipeline integration: Works with oops-its-a-pipeline workflows

Documentation

📚 Full Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.


Quick Metric - Making data metrics simple, configurable, and maintainable! 🚀

About

A framework for quickly creating metrics using easy-to-edit YAML configs and reusable methods to filter, calculate, and transform data.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published