11import json
2+ import html
23
34START_REPORT_PATH = 'reports/start/results.json'
45END_REPORT_PATH = 'reports/end/results.json'
56START_FOLDER = 'start'
67END_FOLDER = 'end'
78OUTPUT_FILE = 'reports/index.html'
89NUM_ITERATIONS = 10
10+ ACCELERATORS_PATH = 'reports/accelerators.json'
911
1012def calculate_end_accuracy (data ):
1113 total_end = 0
@@ -17,17 +19,55 @@ def calculate_end_accuracy(data):
1719 return 0.0
1820 return 100 - (100 * (total_end / max_accuracy ))
1921
22+ def load_report (path ):
23+ with open (path , 'r' ) as f :
24+ return json .load (f )
25+
2026def get_accuracy_str (path ):
21- try :
22- with open (path , 'r' ) as f :
23- data = json .load (f )
24- percent = calculate_end_accuracy (data )
25- return f"{ percent :.1f} %"
26- except (FileNotFoundError , json .JSONDecodeError ):
27- return "N/A"
27+ report = load_report (path )
28+ percent = calculate_end_accuracy (report )
29+ return f"{ percent :.1f} %"
30+
31+ def load_accelerators (path ):
32+ with open (path , 'r' ) as f :
33+ data = json .load (f )
34+ if isinstance (data , dict ):
35+ return [data ]
36+ if isinstance (data , (list , tuple , set )):
37+ return list (data )
38+ return []
39+
40+
41+ def format_accelerator_rows (accelerators , counts ):
42+ if not accelerators :
43+ return '<tr><td colspan="3">No accelerators recorded.</td></tr>'
44+ rows = []
45+ for acc in accelerators :
46+ name = html .escape (str (acc .get ("name" , "" )))
47+ spec = html .escape (str (acc .get ("spec" , "" )))
48+ count = counts .get (acc .get ("name" ), 0 )
49+ rows .append (f'<tr><td>{ name } </td><td><code>{ spec } </code></td><td>{ count } </td></tr>' )
50+ return "" .join (rows )
51+
52+ end_report = load_report (END_REPORT_PATH )
2853
2954start_accuracy_str = get_accuracy_str (START_REPORT_PATH )
3055end_accuracy_str = get_accuracy_str (END_REPORT_PATH )
56+ accelerators = load_accelerators (ACCELERATORS_PATH )
57+
58+ def read_text (path ):
59+ with open (path , 'r' ) as f :
60+ return f .read ()
61+
62+ report_paths = [END_REPORT_PATH ] + [f"reports/iter{ i } /results.json" for i in range (NUM_ITERATIONS )]
63+ report_texts = [read_text (p ) for p in report_paths ]
64+ counts = {
65+ acc_name : sum (text .count (acc_name ) for text in report_texts )
66+ for acc_name in [str (acc .get ("name" , "" )) for acc in accelerators ]
67+ if acc_name
68+ }
69+
70+ accelerator_rows = format_accelerator_rows (accelerators , counts )
3171
3272table_rows = "" .join ([
3373 f'<tr><td><a href="iter{ i } /">iter{ i } </a></td><td>{ get_accuracy_str (f"reports/iter{ i } /results.json" )} </td></tr>'
@@ -45,12 +85,21 @@ def get_accuracy_str(path):
4585 <h1>GrowLibm Report</h1>
4686 <p><a href="grow_platform.txt">Grow Platform</a></p>
4787 <p><a href="candidates.txt">Candidates</a></p>
48- <p><a href="report_info.txt">More Info</a></p>
4988
5089 <h2>Overall Summary</h2>
5190 <p><strong>Start:</strong> { start_accuracy_str } - <a href="{ START_FOLDER } /">Folder</a></p>
5291 <p><strong>End:</strong> { end_accuracy_str } - <a href="{ END_FOLDER } /">Folder</a></p>
5392
93+ <h2>Accelerators</h2>
94+ <table border="1" style="border-collapse:collapse; width:100%; max-width:900px;">
95+ <tr>
96+ <th>Name</th>
97+ <th>Spec</th>
98+ <th>Uses</th>
99+ </tr>
100+ { accelerator_rows }
101+ </table>
102+
54103 <h2>Grow Platform Iterations</h2>
55104 <table border="1" style="border-collapse:collapse; width:300px;">
56105 <tr>
@@ -65,4 +114,3 @@ def get_accuracy_str(path):
65114
66115with open (OUTPUT_FILE , 'w' ) as f :
67116 f .write (html_content )
68-
0 commit comments