a1c00l commited on
Commit
78bf0aa
·
verified ·
1 Parent(s): 0900fea

Update src/aibom_generator/aibom_score_report.py

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