66
77from .engine import audit_text , load_checklist , validate_checklist
88from .reporting import ensure_reports_dir , write_json_report , write_md_report
9+ from .summary import build_batch_summary_payload , write_summary_csv , write_summary_json
10+
11+ PACKAGE_ROOT = Path (__file__ ).resolve ().parents [2 ] # .../src
12+ PROJECT_ROOT = PACKAGE_ROOT .parent # repo root
13+ DEFAULT_CHECKLIST = PROJECT_ROOT / "data" / "checklist.yml"
914
1015
1116def _read_text (path : Path ) -> str :
1217 return path .read_text (encoding = "utf-8" )
1318
1419
15- def cmd_audit_file (args : argparse .Namespace ) -> int :
16- checklist = load_checklist (Path (args .checklist ))
17- errs = validate_checklist (checklist )
18- if errs :
20+ def _print_checklist_warnings (checklist_path : str ) -> tuple [object , int ]:
21+ p = Path (checklist_path )
22+ if not p .exists ():
23+ raise FileNotFoundError (
24+ f"Checklist not found at: { p } \n "
25+ f"Run from repo root or pass --checklist explicitly.\n "
26+ f"Default expected: { DEFAULT_CHECKLIST } "
27+ )
28+
29+ checklist = load_checklist (p )
30+ warnings = validate_checklist (checklist )
31+ if warnings :
1932 print ("Checklist warnings:" )
20- for e in errs :
21- print (f"- { e } " )
33+ for w in warnings :
34+ print (f"- { w } " )
2235 print ()
36+ return checklist , len (warnings )
37+
38+
39+ def cmd_audit_file (args : argparse .Namespace ) -> int :
40+ checklist , _ = _print_checklist_warnings (args .checklist )
2341
2442 in_path = Path (args .path )
2543 text = _read_text (in_path )
@@ -40,13 +58,7 @@ def cmd_audit_file(args: argparse.Namespace) -> int:
4058
4159
4260def cmd_audit_batch (args : argparse .Namespace ) -> int :
43- checklist = load_checklist (Path (args .checklist ))
44- errs = validate_checklist (checklist )
45- if errs :
46- print ("Checklist warnings:" )
47- for e in errs :
48- print (f"- { e } " )
49- print ()
61+ checklist , _ = _print_checklist_warnings (args .checklist )
5062
5163 in_dir = Path (args .dir )
5264 out_dir = Path (args .out_dir )
@@ -57,46 +69,61 @@ def cmd_audit_batch(args: argparse.Namespace) -> int:
5769 print (f"No .txt transcripts found in { in_dir } " )
5870 return 1
5971
72+ results = []
6073 passed = 0
74+
6175 for p in files :
6276 payload = audit_text (_read_text (p ), checklist , source_name = p .name )
77+ results .append (payload )
78+
6379 write_json_report (out_dir / f"{ p .stem } .json" , payload )
6480 write_md_report (out_dir / f"{ p .stem } .md" , payload )
81+
6582 if payload ["result" ]["score" ]["passed" ]:
6683 passed += 1
6784
85+ summary_payload = build_batch_summary_payload (results )
86+ write_summary_json (out_dir / "batch_summary.json" , summary_payload )
87+ write_summary_csv (out_dir / "batch_summary.csv" , summary_payload )
88+
6889 print (f"Audited { len (files )} transcripts. Passed { passed } /{ len (files )} ." )
90+ print (f"Saved: { out_dir / 'batch_summary.json' } " )
91+ print (f"Saved: { out_dir / 'batch_summary.csv' } " )
6992 return 0
7093
7194
7295def cmd_checklist_validate (args : argparse .Namespace ) -> int :
7396 checklist = load_checklist (Path (args .checklist ))
74- errs = validate_checklist (checklist )
75- if not errs :
97+ warnings = validate_checklist (checklist )
98+ if not warnings :
7699 print ("Checklist looks good ✅" )
77100 return 0
101+
78102 print ("Checklist issues / warnings:" )
79- for e in errs :
80- print (f"- { e } " )
103+ for w in warnings :
104+ print (f"- { w } " )
81105 return 0
82106
83107
84108def build_parser () -> argparse .ArgumentParser :
85- p = argparse .ArgumentParser (prog = "ops-qa-auditor" , description = "Ops QA checklist-based transcript auditor." )
109+ p = argparse .ArgumentParser (
110+ prog = "ops-qa-auditor" ,
111+ description = "Ops QA checklist-based transcript auditor." ,
112+ )
86113 sub = p .add_subparsers (dest = "command" , required = True )
87114
88115 audit = sub .add_parser ("audit" , help = "Audit transcripts against a checklist." )
89116 audit_sub = audit .add_subparsers (dest = "mode" , required = True )
90117
91118 f = audit_sub .add_parser ("file" , help = "Audit a single transcript file." )
92119 f .add_argument ("path" , help = "Path to transcript (.txt)" )
93- f .add_argument ("--checklist" , default = "data/checklist.yml" , help = "Path to checklist.yml" )
120+ f .add_argument ("--checklist" , default = str ( DEFAULT_CHECKLIST ) , help = "Path to checklist.yml" )
94121 f .add_argument ("--out-dir" , default = "reports" , help = "Output directory for reports" )
95122 f .set_defaults (func = cmd_audit_file )
96123
97124 b = audit_sub .add_parser ("batch" , help = "Audit all .txt transcripts in a folder." )
98125 b .add_argument ("dir" , help = "Directory containing .txt transcripts" )
99- b .add_argument ("--checklist" , default = "data/checklist.yml" , help = "Path to checklist.yml" )
126+ b .add_argument ("--checklist" , default = str ( DEFAULT_CHECKLIST ) , help = "Path to checklist.yml" )
100127 b .add_argument ("--out-dir" , default = "reports" , help = "Output directory for reports" )
101128 b .set_defaults (func = cmd_audit_batch )
102129
0 commit comments