Spaces:
Running
Running
Create score_report.py
Browse files
src/aibom_generator/score_report.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
from typing import Dict
|
3 |
+
|
4 |
+
def render_score_html(score_report: Dict[str, any]) -> str:
|
5 |
+
html = f"""
|
6 |
+
<html>
|
7 |
+
<head>
|
8 |
+
<title>AIBOM Score Report</title>
|
9 |
+
<style>
|
10 |
+
body {{ font-family: Arial, sans-serif; margin: 20px; }}
|
11 |
+
h2 {{ color: #2c3e50; }}
|
12 |
+
table {{ border-collapse: collapse; width: 50%; margin-bottom: 20px; }}
|
13 |
+
th, td {{ border: 1px solid #ccc; padding: 8px; text-align: left; }}
|
14 |
+
th {{ background-color: #f9f9f9; }}
|
15 |
+
ul {{ list-style: none; padding-left: 0; }}
|
16 |
+
li::before {{ content: "\2713 "; color: green; margin-right: 6px; }}
|
17 |
+
li.missing::before {{ content: "\2717 "; color: red; }}
|
18 |
+
</style>
|
19 |
+
</head>
|
20 |
+
<body>
|
21 |
+
<h2>AIBOM Completeness Score: <strong>{score_report['total_score']}%</strong></h2>
|
22 |
+
|
23 |
+
<h3>Section Scores</h3>
|
24 |
+
<table>
|
25 |
+
<tr><th>Section</th><th>Score</th></tr>
|
26 |
+
"""
|
27 |
+
for section, score in score_report.get("section_scores", {}).items():
|
28 |
+
html += f"<tr><td>{section}</td><td>{score}</td></tr>"
|
29 |
+
|
30 |
+
html += """
|
31 |
+
</table>
|
32 |
+
<h3>Field Checklist</h3>
|
33 |
+
<ul>
|
34 |
+
"""
|
35 |
+
for field, mark in score_report.get("field_checklist", {}).items():
|
36 |
+
css_class = "missing" if mark == "✘" else ""
|
37 |
+
html += f"<li class=\"{css_class}\">{field}</li>"
|
38 |
+
|
39 |
+
html += """
|
40 |
+
</ul>
|
41 |
+
<details>
|
42 |
+
<summary>Raw Score Report</summary>
|
43 |
+
<pre>{json.dumps(score_report, indent=2)}</pre>
|
44 |
+
</details>
|
45 |
+
</body>
|
46 |
+
</html>
|
47 |
+
"""
|
48 |
+
return html
|
49 |
+
|
50 |
+
|
51 |
+
def save_score_report_html(score_report: Dict[str, any], output_path: str):
|
52 |
+
html_content = render_score_html(score_report)
|
53 |
+
with open(output_path, 'w', encoding='utf-8') as f:
|
54 |
+
f.write(html_content)
|
55 |
+
print(f"Score report saved to {output_path}")
|