v3: gstack-code-gen 生成
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from data.diff_result import VerificationRun
|
||||
|
||||
|
||||
class ReportGenerator:
|
||||
def generate_json(self, run: VerificationRun, p: Path) -> Path:
|
||||
d = {"program": run.program, "status": run.status, "exit_code": run.exit_code,
|
||||
"timestamp": run.timestamp, "duration_s": run.duration_s,
|
||||
"fields_matched": run.fields_matched, "fields_mismatched": run.fields_mismatched,
|
||||
"runner": run.runner, "branch_rate": run.branch_rate, "llm_cost": run.llm_cost,
|
||||
"field_results": [{"field_name": fr.field_name, "status": fr.status,
|
||||
"cobol_value": fr.cobol_value, "java_value": fr.java_value,
|
||||
"suggestion": fr.suggestion} for fr in run.field_results]}
|
||||
p.write_text(json.dumps(d, indent=2))
|
||||
return p
|
||||
|
||||
def generate_html(self, run: VerificationRun, p: Path) -> Path:
|
||||
rows = "".join(
|
||||
f'<tr class="{"pass" if fr.status == "PASS" else "fail"}"><td>{fr.field_name}'
|
||||
f'</td><td>{fr.status}</td><td>{fr.cobol_value}</td><td>{fr.java_value}</td>'
|
||||
f'<td>{fr.suggestion}</td></tr>'
|
||||
for fr in run.field_results)
|
||||
html = f"<!DOCTYPE html><html><head><meta charset=utf-8><title>{run.program}</title>" \
|
||||
f"<style>body{{font-family:monospace;max-width:900px;margin:2rem auto}}" \
|
||||
f".pass{{background:#e6ffe6}}.fail{{background:#ffe6e6}}pre{{background:#f0f0f0;padding:1rem}}" \
|
||||
f"</style></head><body><h1>{run.program}</h1><pre>Status: {run.status} | " \
|
||||
f"Runner: {run.runner} | {run.fields_matched} fields | {run.duration_s}s</pre>" \
|
||||
f"<table border=1 cellpadding=4><tr><th>Field</th><th>Status</th><th>COBOL</th>" \
|
||||
f"<th>Java</th><th>Suggestion</th></tr>{rows}</table></body></html>"
|
||||
p.write_text(html)
|
||||
return p
|
||||
|
||||
def generate_machine_json(self, run: VerificationRun, p: Path) -> Path:
|
||||
d = {"program": run.program, "status": run.status, "exit_code": run.exit_code,
|
||||
"timestamp": run.timestamp, "duration_s": run.duration_s, "runner": run.runner}
|
||||
p.write_text(json.dumps(d))
|
||||
return p
|
||||
Reference in New Issue
Block a user