#!/usr/bin/env python3
"""Analyse layered process audit results: compliance, repeat failures, stale questions and layer gaps.
Results CSV columns: date, layer, area, auditor, question_id, result (pass/fail/na), corrected (yes/no)
Optional column: question (text).
Reports:
compliance % by area, by layer and by question
LR001 high repeat failure: same question fails in the same area >= --repeat times -> open a CAPA
LR002 medium failure not corrected on the spot and no follow-up recorded
LR003 medium layer gap: layer 1 pass rate is >= 15 points above layers 2-3 in an area (check rigour)
LR004 low question passed every time over >= --stale audits -> rotate or retire it
Usage:
python lpa_results.py results.csv
python lpa_results.py results.csv --repeat 3 --stale 20
Exit codes: 0 no high findings, 1 high findings, 2 read error.
"""
import argparse
import csv
import sys
from collections import defaultdict
def pct(p, n):
return 100 * p / n if n else 0.0
def main():
ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
ap.add_argument("csv", help="results CSV, or - for stdin")
ap.add_argument("--repeat", type=int, default=3, help="failures of one question in one area that trigger LR001")
ap.add_argument("--stale", type=int, default=20, help="all-pass answers after which a question is stale")
a = ap.parse_args()
try:
fh = sys.stdin if a.csv == "-" else open(a.csv, newline="", encoding="utf-8-sig")
with fh:
rows = list(csv.DictReader(fh))
except (OSError, csv.Error) as e:
print(f"error: {e}", file=sys.stderr)
return 2
need = {"layer", "area", "question_id", "result"}
if not rows or not need <= set(rows[0]):
print(f"error: CSV needs columns {', '.join(sorted(need))}", file=sys.stderr)
return 2
by = {k: defaultdict(lambda: [0, 0]) for k in ("area", "layer", "question_id")}
area_layer = defaultdict(lambda: [0, 0])
fails = defaultdict(int)
text = {}
findings = []
for r in rows:
res = (r["result"] or "").strip().lower()
if res not in ("pass", "fail"):
continue
ok = res == "pass"
q, area, layer = r["question_id"].strip(), r["area"].strip(), r["layer"].strip()
text[q] = (r.get("question") or "").strip()
for k, v in (("area", area), ("layer", layer), ("question_id", q)):
by[k][v][0] += ok
by[k][v][1] += 1
area_layer[(area, "1" if layer == "1" else "2+")][0] += ok
area_layer[(area, "1" if layer == "1" else "2+")][1] += 1
if not ok:
fails[(q, area)] += 1
if (r.get("corrected") or "").strip().lower() not in ("yes", "y", "true"):
findings.append(("LR002", "medium", f"{r.get('date', '')} {area} {q}: failed, not corrected on the spot - record the follow-up action"))
total_p = sum(v[0] for v in by["area"].values())
total_n = sum(v[1] for v in by["area"].values())
print(f"Overall compliance: {pct(total_p, total_n):.1f}% ({total_n} answers)\n")
for k, label in (("area", "Area"), ("layer", "Layer")):
print(f"{label:<14}{'Answers':>8}{'Compliance':>12}")
for v, (p, n) in sorted(by[k].items()):
print(f"{v:<14}{n:>8}{pct(p, n):>11.1f}%")
print()
print(f"{'Question':<10}{'Answers':>8}{'Compliance':>12} Text")
for q, (p, n) in sorted(by["question_id"].items(), key=lambda kv: pct(*kv[1])):
print(f"{q:<10}{n:>8}{pct(p, n):>11.1f}% {text.get(q, '')[:60]}")
if p == n and n >= a.stale:
findings.append(("LR004", "low", f"{q}: passed all {n} times - rotate in a new question on a current risk"))
for (q, area), n in sorted(fails.items()):
if n >= a.repeat:
findings.append(("LR001", "high", f"{q} failed {n} times in {area} - systemic: open a corrective action"))
for area in sorted({k[0] for k in area_layer}):
l1, l2 = area_layer.get((area, "1")), area_layer.get((area, "2+"))
if l1 and l2 and l1[1] and l2[1] and pct(*l1) - pct(*l2) >= 15:
findings.append(("LR003", "medium", f"{area}: layer 1 finds {pct(*l1):.0f}% compliance, higher layers {pct(*l2):.0f}% - coach layer 1 on what to check"))
order = {"high": 0, "medium": 1, "low": 2}
print()
for code, sev, msg in sorted(findings, key=lambda f: (order[f[1]], f[0])):
print(f"{code} [{sev}] {msg}")
return 1 if any(f[1] == "high" for f in findings) 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.