Skip to content

rosmur/cpkmetrics

Repository files navigation

Process Capability Metrics

A simple utility to calculate Process Capability (Cpk) metrics.

Installation

Standard Installation [Recommended]

Execute the following command in the terminal:

pip install cpkmetrics

NOTE: For macOS/Linux, use pip3 if needed.

The other options for installation are:

Installation/Run with uv

Click to expand

Install with the uv package manager (modern python tooling standard):

uv pip install cpkmetrics

Install From Source

Click to expand Clone this repo and install:
git clone https://github.com/your-username/cpkmetrics.git  # Replace with actual repo URL
cd cpkmetrics
python -m venv venv # Optically create virtual environment - not necessary given the lack of dependencies in this package
source venv/bin/activate # On Windows: .\venv\Scripts\activate (Ignore if you dont create a venv)
pip install -e .

Alternatively, you can also forgo installation and run directly by using the uv package manager's --with feature.

uv run --with cpkmetrics my_python_code.py 

Usage

A basic example calculating process capability metrics for a given mean, standard deviation and spec limits:

from cpkmetrics.process_capability import ProcessCapability

# Example values for mean, stddev, USL, and LSL
mean = 10
stddev = 1
USL = 14
LSL = 6

# Create an instance of the ProcessCapability class with the provided parameters. Instantiation also automatically prints results to the terminal (unless you pass print_results=False arg)
pc = ProcessCapability(mean, stddev, USL, LSL)

This will print out:

| Metric                          | Value   |
|-------------------------------------------|
| Process Capability              | 1.333   |
| Process Capability Index        | 1.333   |
| Process Capability Upper        | 1.333   |
| Process Capability Lower        | 1.333   |
| Process Accuracy                | 0.000   |
| Process Sigma Level             | 4σ      |
| Process Capability Index Rating | Great   |
| Process Accuracy Rating         | Level A |

You can also access individual items directly through the corrresponding property:

cpk = pc.process_capability_index

print(f"The Cpk is {round(cpk, 2)}")
#OUTPUT: The Cpk is 1.33

Further examples can be found here including compatability with dataframes.

Roadmap

  • Skewness and Kurtosis metrics
  • Allow setting threshold values for Cpk and Cpa Ratings
  • Natural language results

Contributing

Contributions are encouraged and welcome. Please note that the intent of this package is to remain very light weight, with no dependencies. Bug fixes, refactors and raising issues are highly encouraged. Please align to the design and engineering practices below and create a PR for contributions.

Design and Engineering Practices

This project intends to have the smallest amount of code possible without sacrificing good design, structure and robust engineering practices that will allow future functionality, extensibility and forkability.

Documentation is copious - to maximize accessibility to AI/ML/SW engineers unfamiliar with statistical process control and for manufacturing/process/hardware engineers unfamiliar with python. Docstrings are detailed to allow for clarity as well as learning. In-line comments document code logic and design notes/decisions.

Project uses a modern toolchain to assist in this:

  • Project Management and Build: pyproject.toml compliant to PEP 751 though uv
  • Testing: pytest and coverage
  • Code Quality: Linting, Formatting through ruff Static Analysis through mypy. Enforced through pre-commmit and GitHub Actions
  • Documentation: Docstrings are enforced with interrogate at 90% threshold
  • AI Usage: No AI was used in the original writing of this repo. However, AI usage in PRs and contributions are fine as long as all code and content is human reviewed

About

A featherweight library to compute process capability metrics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages