"""Lab to Code — Is your process capable? Cp and Cpk.

Bottle fill volume, spec 500 +/- 6 mL. 50 bottles measured (simulated with a fixed seed).
Cp  = (USL - LSL) / (6 * sigma)                -> could the process fit, if it were centered?
Cpk = min(USL - mean, mean - LSL) / (3 * sigma) -> does it fit, where it actually is?
"""
import numpy as np

LSL, USL = 494.0, 506.0

rng = np.random.default_rng(7)
fills = rng.normal(loc=503.0, scale=1.2, size=50)   # off-center: mean near 503, not 500

mean = fills.mean()
sigma = fills.std(ddof=1)
cp = (USL - LSL) / (6 * sigma)
cpk = min(USL - mean, mean - LSL) / (3 * sigma)

print(f"mean = {mean:.2f} mL, sigma = {sigma:.2f} mL")
print(f"Cp  = {cp:.2f}")
print(f"Cpk = {cpk:.2f}")
print("capable" if cpk >= 1.33 else "not capable yet: center it first")
