Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smart Sampling Planner

A Python command-line tool that determines acceptance sampling plans for Quality Control inspections, based on the ISO 2859-1 / ANSI Z1.4 standard (sampling procedures for inspection by attributes).

Given a Lot Size, Inspection Level, AQL, and Inspection Type, the tool calculates:

  • Sample Size Code Letter
  • Sample Size
  • Acceptance Number (Ac)
  • Rejection Number (Re)

CLI Run Example


The Problem This Solves

Quality Control inspectors routinely need to determine how many units to sample from a production lot, and what defect counts trigger acceptance or rejection of the whole lot. This is normally done by manually looking up values across several dense, cross-referenced tables in the ISO 2859-1 / ANSI Z1.4 standard -- a process that is slow and prone to human error, especially when a table cell requires following an "arrow" reference to a different row.

This tool automates that lookup, including the standard's arrow-following logic, so an inspector gets a correct, unambiguous answer in seconds.


Why This Was Hard to Build

The official standard tables are not available as structured, machine-readable data anywhere -- they exist only as scanned/printed pages in the standard document itself. Building the underlying data set required:

  • Manually transcribing three large master tables (Normal, Tightened, and Reduced inspection), each with 16-17 sample size code letters across 26 AQL columns.
  • Correctly encoding the standard's "arrow" cells (⇧ / ⇩), which mean "use the plan from a different code letter row for this AQL" rather than providing a value directly.
  • Catching and correcting several transcription errors along the way (including a full column misalignment) through cross-verification against the source tables -- since an incorrect Ac/Re value would silently produce a wrong accept/reject decision.

Some cells in the Reduced inspection table (Table 2-C) were derived from a verified structural pattern rather than being individually re-confirmed against the source, and are flagged with _needs_verification in the data files pending a final manual check.


Features

  • Interactive CLI with input validation (no crashes on bad input)
  • Case-insensitive input matching
  • Follows the standard's arrow-reference logic automatically
  • Colored, formatted terminal output (via rich)
  • Clear error messages for invalid or undefined combinations
  • Unit-tested core logic (19+ tests)

Installation

git clone https://github.com/hadiii1i/smart-sampling-planner.git
cd smart-sampling-planner
python -m venv venv
venv\Scripts\activate      # Windows
# source venv/bin/activate  # macOS/Linux
pip install -r requirements.txt

Usage

python main.py

You will be prompted for:

  1. Lot Size -- total number of items in the lot
  2. Inspection Level -- S1-S4 (special) or I-III (general, II is the default)
  3. Inspection Type -- normal / tightened / reduced
  4. AQL -- Acceptable Quality Limit, as a percentage

Project Structure


Project Structure

smart-sampling-planner/
├── data/                          # Standard tables as structured JSON
│   ├── code_letter_table.json
│   ├── sampling_normal_table2A.json
│   ├── sampling_tightened_table2B.json
│   └── sampling_reduced_table2C.json
├── src/
│   ├── code_letter.py             # Lot Size + Level -> Code Letter
│   ├── sample_plan.py             # Code Letter + AQL -> Sample Size, Ac, Re
│   └── cli.py                     # Interactive command-line interface
├── tests/
│   ├── test_code_letter.py
│   └── test_sample_plan.py
├── main.py                        # Entry point
└── requirements.txt

Running Tests

python -m pytest

All Tests Passing


Standard Reference and Disclaimer

This tool implements the sampling plan logic described in ISO 2859-1 / ANSI/ASQ Z1.4 (sampling procedures and tables for inspection by attributes). It is an independent, unofficial implementation created for educational and portfolio purposes.

The official standard documents are copyrighted and must be purchased from ISO or ASQ for authoritative reference. This project does not reproduce or distribute the standard's text or scanned tables -- only the numeric Ac/Re values needed for calculation, transcribed and verified by the author.

This tool is not a substitute for official quality engineering judgment or a licensed copy of the standard. Values in the Reduced inspection table are pending final verification (see _needs_verification flags in data/sampling_reduced_table2C.json) and should be independently confirmed before use in a production quality system.


Roadmap

  • Final verification of Table 2-C (Reduced) rows D-R
  • Automatic switching between Normal/Tightened/Reduced based on lot history
  • Tkinter desktop version
  • Web version (Flask/FastAPI)
  • SQLite-backed inspection history and reporting

Author

Built by Hadi Yabari as a first Python project, with a focus on professional development workflow (Git, virtual environments, modular architecture, unit testing) alongside real-world Quality Engineering domain logic.

About

A Python application for generating acceptance sampling plans based on ANSI/ASQ Z1.4 and ISO 2859-1 standards.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages