@@ -56,86 +56,88 @@ def add_problem_id_row_attributes(table_html, problem_ids):
5656html_footer = f"{ html_dir } footer.html"
5757html_index = f"{ html_dir } index.html"
5858html_table_template = f"{ html_dir } table_template.html"
59-
60- # Load data
61- with open (yaml_file ) as yaml_input :
62- raw_data = pd .json_normalize (yaml .safe_load (yaml_input ))
63-
64- if "problem_id" in raw_data .columns :
65- problem_ids = raw_data ["problem_id" ].fillna ("" ).map (str )
66- else :
67- problem_ids = raw_data ["name" ].fillna ("" ).map (str ).map (to_problem_id )
68-
69- problem_ids = problem_ids .where (problem_ids .str .len () > 0 , raw_data ["name" ].fillna ("" ).map (str ).map (to_problem_id ))
70- data = raw_data .copy ()
71-
72- # Choose desired columns
73- all_columns = False
7459default_columns = ["name" ,
75- "textual description" ,
76- "suite/generator/single" ,
77- "objectives" ,
78- "dimensionality" ,
79- "variable type" ,
80- "constraints" ,
81- "dynamic" ,
82- "noise" ,
83- "multi-fidelity" ,
84- "source (real-world/artificial)" ,
85- "reference" ,
86- "implementation" ]
87-
88- if all_columns is False :
89- columns = default_columns
90- data = data [columns ]
91-
92- data = data .map (linkify_cell )
93-
94- # Generate plain table
95- table = data .to_html (render_links = False ,
96- escape = False , # Don't escape HTML in cells (to allow links)
97- index = False ,
98- table_id = "problems" ,
99- classes = ["display compact" , "display" , "styled-table" ], # Set display style
100- border = 0 ,
101- na_rep = "" ) # Leave NaN cells empty
102-
103- table = add_problem_id_row_attributes (table , problem_ids .tolist ())
104-
105- # Add footer to facilitate individual column search
106- idx = table .index ('</table>' )
107- final_table = table [:idx ] + "<tfoot><tr>" + " " .join (["<th>" + i + "</th>" for i in data .columns ])+ "</tr> </tfoot>" + table [idx :]
108-
109- default_hidden_columns = {"textual description" , "reference" , "implementation" }
110-
111- column_toggles = "" .join (
112- [
113- (
114- f'<label class="column-chip">'
115- f'<input class="col-toggle" type="checkbox" data-column="{ i } "'
116- f'{ " checked" if col not in default_hidden_columns else "" } >'
117- f'<span>{ escape (col )} </span>'
118- f'</label>'
119- )
120- for i , col in enumerate (data .columns )
121- ]
122- )
123-
124- with open (html_table_template , encoding = "utf-8" ) as template_file :
125- table_template = template_file .read ()
126-
127- table_markup = (
128- table_template
129- .replace ("__COLUMN_TOGGLES__" , column_toggles )
130- .replace ("__TABLE__" , final_table )
131- )
132-
133- # Write table to file
134- with open (html_table , "w" , encoding = "utf-8" ) as table_file :
135- table_file .write (table_markup )
136-
137- # Merge table and scripts into HTML page
138- with open (html_index , "wb" ) as output_file :
139- for part_path in [html_header , html_table , html_scripts , html_footer ]:
140- with open (part_path , "rb" ) as part_file :
141- shutil .copyfileobj (part_file , output_file )
60+ "textual description" ,
61+ "suite/generator/single" ,
62+ "objectives" ,
63+ "dimensionality" ,
64+ "variable type" ,
65+ "constraints" ,
66+ "dynamic" ,
67+ "noise" ,
68+ "multi-fidelity" ,
69+ "source (real-world/artificial)" ,
70+ "reference" ,
71+ "implementation" ]
72+
73+ if __name__ == "__main__" :
74+
75+ # Load data
76+ with open (yaml_file ) as yaml_input :
77+ raw_data = pd .json_normalize (yaml .safe_load (yaml_input ))
78+
79+ if "problem_id" in raw_data .columns :
80+ problem_ids = raw_data ["problem_id" ].fillna ("" ).map (str )
81+ else :
82+ problem_ids = raw_data ["name" ].fillna ("" ).map (str ).map (to_problem_id )
83+
84+ problem_ids = problem_ids .where (problem_ids .str .len () > 0 , raw_data ["name" ].fillna ("" ).map (str ).map (to_problem_id ))
85+ data = raw_data .copy ()
86+
87+ # Choose desired columns
88+ all_columns = False
89+
90+ if all_columns is False :
91+ columns = default_columns
92+ data = data [columns ]
93+
94+ data = data .map (linkify_cell )
95+
96+ # Generate plain table
97+ table = data .to_html (render_links = False ,
98+ escape = False , # Don't escape HTML in cells (to allow links)
99+ index = False ,
100+ table_id = "problems" ,
101+ classes = ["display compact" , "display" , "styled-table" ], # Set display style
102+ border = 0 ,
103+ na_rep = "" ) # Leave NaN cells empty
104+
105+ table = add_problem_id_row_attributes (table , problem_ids .tolist ())
106+
107+ # Add footer to facilitate individual column search
108+ idx = table .index ('</table>' )
109+ final_table = table [:idx ] + "<tfoot><tr>" + " " .join (["<th>" + i + "</th>" for i in data .columns ])+ "</tr> </tfoot>" + table [idx :]
110+
111+ default_hidden_columns = {"textual description" , "reference" , "implementation" }
112+
113+ column_toggles = "" .join (
114+ [
115+ (
116+ f'<label class="column-chip">'
117+ f'<input class="col-toggle" type="checkbox" data-column="{ i } "'
118+ f'{ " checked" if col not in default_hidden_columns else "" } >'
119+ f'<span>{ escape (col )} </span>'
120+ f'</label>'
121+ )
122+ for i , col in enumerate (data .columns )
123+ ]
124+ )
125+
126+ with open (html_table_template , encoding = "utf-8" ) as template_file :
127+ table_template = template_file .read ()
128+
129+ table_markup = (
130+ table_template
131+ .replace ("__COLUMN_TOGGLES__" , column_toggles )
132+ .replace ("__TABLE__" , final_table )
133+ )
134+
135+ # Write table to file
136+ with open (html_table , "w" , encoding = "utf-8" ) as table_file :
137+ table_file .write (table_markup )
138+
139+ # Merge table and scripts into HTML page
140+ with open (html_index , "wb" ) as output_file :
141+ for part_path in [html_header , html_table , html_scripts , html_footer ]:
142+ with open (part_path , "rb" ) as part_file :
143+ shutil .copyfileobj (part_file , output_file )
0 commit comments