(args: argparse.Namespace)
| 88 | |
| 89 | |
| 90 | def handle_analysis_command(args: argparse.Namespace) -> int: |
| 91 | results = _filtered_results(args) |
| 92 | |
| 93 | if args.analysis_command == "summary": |
| 94 | payload = summarize_results(results) |
| 95 | return _emit_json(payload, args.output) |
| 96 | |
| 97 | if args.analysis_command == "export-csv": |
| 98 | payload = summarize_results(results) |
| 99 | rows = export_summary_rows(payload) |
| 100 | _write_csv(Path(args.output), rows) |
| 101 | return 0 |
| 102 | |
| 103 | if args.analysis_command == "matrix": |
| 104 | payload = build_metric_matrix( |
| 105 | results, |
| 106 | rows_field=args.rows, |
| 107 | cols_field=args.cols, |
| 108 | metric=args.metric, |
| 109 | ) |
| 110 | if args.output: |
| 111 | output_path = Path(args.output) |
| 112 | if output_path.suffix.lower() == ".csv": |
| 113 | _write_matrix_csv(output_path, args.rows, payload) |
| 114 | return 0 |
| 115 | return _emit_json(payload, output_path) |
| 116 | return _emit_json(payload, None) |
| 117 | |
| 118 | if args.analysis_command == "history": |
| 119 | payload: list[dict[str, Any]] = [] |
| 120 | for item in results: |
| 121 | record = item.to_dict() |
| 122 | if args.parsed: |
| 123 | record["history_parsed"] = parse_history_entries(item.history) |
| 124 | record["history_steps"] = group_history_steps(item.history) |
| 125 | payload.append(record) |
| 126 | return _emit_json(payload, None) |
| 127 | |
| 128 | if args.analysis_command == "fail-commands": |
| 129 | payload = collect_failed_commands(results, group_by=args.group_by) |
| 130 | return _emit_json(payload, None) |
| 131 | |
| 132 | if args.analysis_command == "fail-reasons": |
| 133 | payload = summarize_failure_reasons(results, group_by=args.group_by) |
| 134 | return _emit_json(payload, None) |
| 135 | |
| 136 | if args.analysis_command == "plot": |
| 137 | matrix = build_metric_matrix( |
| 138 | results, |
| 139 | rows_field=args.x, |
| 140 | cols_field=args.series, |
| 141 | metric=args.metric, |
| 142 | ) |
| 143 | try: |
| 144 | render_grouped_bar_chart( |
| 145 | matrix, |
| 146 | output_path=args.output, |
| 147 | title=args.title, |
no test coverage detected