#!/usr/bin/env python3
"""Score a filled ISO 9001 gap worksheet (from gap_template.py) and list the gaps by severity.
Scoring: met = 1, partial = 0.5, not-met = 0; n/a rows are excluded. Gap grades mirror how a
certification auditor would likely grade them:
GA001 major core clause not met (system element missing: scope, processes, policy, objectives,
risks, document control, suppliers, release, nonconforming output, audit, review, CAPA)
GA002 minor other clause not met
GA003 minor partial implementation
GA004 check marked met but no evidence written (an auditor will ask for it)
GA005 error n/a on a clause that cannot be excluded (only 7.1.5, 8.3, 8.5.3, 8.5.5 may be)
GA006 check clause missing from the sheet or status blank / unknown
Verdict: READY (no majors, >= 90%), CLOSE (no majors, >= 75%), NOT READY otherwise.
Usage:
python gap_score.py gap.csv
python gap_score.py gap.csv --json
cat gap.csv | python gap_score.py -
Exit codes: 0 no major gaps, 1 major gaps or errors, 2 usage or read error.
"""
import argparse
import csv
import json
import sys
from _clauses import BY_CLAUSE, CLAUSES, MAY_NOT_APPLY
SCORE = {"met": 1.0, "partial": 0.5, "not-met": 0.0}
ALIASES = {"yes": "met", "y": "met", "compliant": "met", "no": "not-met", "n": "not-met", "not met": "not-met",
"missing": "not-met", "part": "partial", "partially": "partial", "na": "n/a", "not applicable": "n/a"}
RANK = {"error": 0, "major": 1, "minor": 2, "check": 3}
def read_rows(path):
fh = sys.stdin if path == "-" else open(path, newline="", encoding="utf-8-sig")
with fh:
rows = list(csv.DictReader(fh))
if rows and not {"clause", "status"} <= set(rows[0]):
raise ValueError("CSV needs at least 'clause' and 'status' columns (see gap_template.py)")
return rows
def assess(rows):
findings, seen, scores = [], set(), {}
for r in rows:
clause = (r.get("clause") or "").strip()
if clause not in BY_CLAUSE:
continue
seen.add(clause)
_, title, _, doc, core = BY_CLAUSE[clause]
status = (r.get("status") or "").strip().lower()
status = ALIASES.get(status, status)
evidence = (r.get("evidence") or "").strip()
label = f"{clause} {title}"
if status == "n/a":
if clause not in MAY_NOT_APPLY:
findings.append(("GA005", "error", label, "marked n/a but this requirement always applies; "
"only 7.1.5, 8.3, 8.5.3, 8.5.5 can be justified as not applicable in 4.3"))
elif not evidence:
findings.append(("GA006", "check", label, "n/a needs a justification recorded in the scope (4.3)"))
continue
if status not in SCORE:
findings.append(("GA006", "check", label, f"status {status or 'blank'!r}; use met, partial, not-met or n/a"))
continue
scores[clause] = SCORE[status]
need = f" (needs a {doc.replace('maintain', 'document').replace('retain', 'record')})" if doc else ""
if status == "not-met":
sev = "major" if core else "minor"
findings.append(("GA001" if core else "GA002", sev, label, f"not implemented{need}"))
elif status == "partial":
findings.append(("GA003", "minor", label, f"partially implemented{need}: {evidence or 'no detail given'}"))
elif not evidence:
findings.append(("GA004", "check", label, "marked met with no evidence; name the document, record or interview"))
for clause, title, *_ in CLAUSES:
if clause not in seen:
findings.append(("GA006", "check", f"{clause} {title}", "missing from the worksheet"))
findings.sort(key=lambda f: (RANK[f[1]], [int(x) for x in f[2].split()[0].split(".")]))
return scores, findings
def section_scores(scores):
out = {}
for sec in "4 5 6 7 8 9 10".split():
vals = [v for c, v in scores.items() if c.split(".")[0] == sec]
if vals:
out[sec] = round(100 * sum(vals) / len(vals), 1)
return out
def verdict(pct, findings):
majors = sum(f[1] in ("major", "error") for f in findings)
if majors:
return "NOT READY"
return "READY" if pct >= 90 else "CLOSE" if pct >= 75 else "NOT READY"
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("csv", help="filled worksheet, or - for stdin")
ap.add_argument("--json", action="store_true", help="machine-readable output")
a = ap.parse_args()
try:
rows = read_rows(a.csv)
except (OSError, ValueError, csv.Error) as e:
print(f"error: {e}", file=sys.stderr)
return 2
scores, findings = assess(rows)
pct = round(100 * sum(scores.values()) / len(scores), 1) if scores else 0.0
sections = section_scores(scores)
v = verdict(pct, findings)
counts = {s: sum(f[1] == s for f in findings) for s in RANK}
if a.json:
print(json.dumps({"readiness_pct": pct, "verdict": v, "sections": sections, "counts": counts,
"findings": [dict(zip(("code", "severity", "clause", "message"), f)) for f in findings]}, indent=2))
else:
print(f"Readiness: {pct}% across {len(scores)} assessed clauses -> {v}")
print("By section: " + " ".join(f"{s}: {p:g}%" for s, p in sections.items()))
print(f"Gaps: {counts['major']} major, {counts['minor']} minor, {counts['error']} errors, {counts['check']} to check\n")
for code, sev, label, msg in findings:
print(f"{code} [{sev}] {label}: {msg}")
return 1 if counts["major"] or counts["error"] else 0
if __name__ == "__main__":
sys.exit(main())
8d-problem-solving-report-writer
Write and review 8D problem-solving reports for customer complaints and serious nonconformities (automotive and aerospace practice: Ford Global 8D, VDA, GM, Stellantis formats): D0 emergency response, D1 cross-functional team and champion, D2 problem description with 5W2H and is / is-not and no cause in the statement, D3 interim containment within 24 hours with verification and clean point, D4 verified occurrence and escape (non-detection) root causes plus systemic cause, D5 permanent corrective actions for each cause verified before implementation, D6 implementation, validation with production data and removal of containment, D7 PFMEA, control plan and read-across to similar products, D8 closure and recognition. Checks an 8D discipline by discipline for missing content, human-error root causes, missing escape cause or action, late containment and dates out of order.
acceptance-sampling-plan-selector
Select and evaluate acceptance sampling plans for incoming, in-process and final inspection: ANSI/ASQ Z1.4 / ISO 2859-1 single sampling under normal inspection (code letter from lot size and inspection level I, II, III, S-1 to S-4; sample size, Ac and Re from AQL, following the table's arrows to the correct plan; 100% when n reaches the lot size; AQLs above 10 per 100 units), operating characteristic curves (Pa at any quality, producer's quality level, indifference point, LTPD, AOQ and AOQL, binomial or hypergeometric), plans designed from producer and consumer risk, and c = 0 zero-acceptance plans. Covers AQL choice by defect class, switching rules between normal, tightened and reduced inspection, when sampling is not appropriate, and random sampling.
approved-supplier-list-manager
Manage and audit an approved supplier list (ASL) / external provider register for ISO 9001 8.4.1, IATF 16949 8.4 and AS9100 8.4.1: supplier status (approved, conditional, probation, pending, disqualified), scope of approval by commodity and process, risk class, certification and expiry, re-evaluation intervals by risk, conditions with end dates, single-source contingency, approver and customer-directed sources. Audits the list for expired or expiring certificates, overdue re-evaluations, conditional or probation status past its decision date, high-risk suppliers without the required certification, single-source suppliers without backup and missing approvers, and checks purchase orders for suppliers that are off-list, disqualified or pending, or buying outside the approved scope. Covers ERP blocks, PO requirements, off-list and emergency purchases.
apqp-phase-planner
Plan and track Advanced Product Quality Planning (AIAG APQP 3rd edition, IATF 16949) for a new or changed automotive part: back-schedule the five phases (plan and define, product design, process design, product and process validation, launch and feedback) from the start-of-production date by program complexity, with overlap, PPAP lead and safe-launch period; list the deliverables and gate for each phase (DFMEA, DVP&R, feasibility, process flow, PFMEA, control plans, MSA, Ppk, run at rate, PPAP, safe launch, lessons learned); adjust for build-to-print suppliers; flag compressed timelines and late or untracked deliverables against a status list. Covers gate reviews, red/yellow/green status reporting, run at rate and safe-launch exit criteria.
as9100-gap-analyzer
Run an AS9100D / EN 9100:2018 gap analysis for aviation, space and defence suppliers on the requirements added to ISO 9001: on-time delivery and conformity focus, management representative, ethics and human-factors awareness, operational planning and operational risk management, configuration management, product safety, counterfeit-part prevention, special requirements, critical items and key characteristics, external provider register and flow-down, FOD prevention, tooling and NC program control, special process validation, first article inspection (AS9102), traceability, in-service data and nonconforming product control. Generates and scores a worksheet, grades missing core controls as major, and checks invalid n/a claims. Covers AS9101/AS9104, OASIS, AS9102 FAI forms, counterfeit standards (AS5553, AS6174, AS6081), NADCAP and the planned IA9100 transition.
audit-report-writer
Write internal, supplier and pre-certification audit reports with the content ISO 19011:2018 6.5 expects: audit objectives, scope, criteria with revisions, dates, team and auditees, method and sampling statement, specific strengths, findings table and three-part finding details (requirement, evidence, statement), conclusion on the degree of fulfilment of criteria, diverging opinions, follow-up deadlines and distribution. Builds a Markdown report from a JSON audit record, generates the conclusion from the findings (major / minor / none) and flags reports missing required content or findings without clause or evidence. Covers conclusion wording, closing meetings, response expectations and verifying corrective actions.