mirror of
https://github.com/open-compass/opencompass.git
synced 2025-05-30 16:03:24 +08:00
[Feature] Support results saving as md format table (#1638)
This commit is contained in:
parent
22fdea4bf2
commit
2542bc6907
@ -299,16 +299,34 @@ class DefaultSummarizer:
|
|||||||
raw_txts = '\n'.join(raw_txts)
|
raw_txts = '\n'.join(raw_txts)
|
||||||
return raw_txts
|
return raw_txts
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _format_md_table(table):
|
||||||
|
table_head_str = '| ' + ' | '.join(table[0]) + ' |\n'
|
||||||
|
table_mid_list = ['-----' for _ in range(len(table[0]))]
|
||||||
|
table_mid_str = '|' + ' | '.join(table_mid_list) + '|\n'
|
||||||
|
|
||||||
|
md_table_str = table_head_str + table_mid_str
|
||||||
|
for row in table[1:]:
|
||||||
|
curr_str = '| ' + ' | '.join(row) + ' |\n'
|
||||||
|
md_table_str += curr_str
|
||||||
|
return md_table_str
|
||||||
|
|
||||||
def _output_to_file(self, output_path, time_str, table, raw_txts):
|
def _output_to_file(self, output_path, time_str, table, raw_txts):
|
||||||
# output to file
|
# output to file
|
||||||
if output_path is None:
|
if output_path is None:
|
||||||
output_path = osp.join(self.work_dir, 'summary', f'summary_{time_str}.txt')
|
output_path = osp.join(self.work_dir, 'summary', f'summary_{time_str}.txt')
|
||||||
output_csv_path = osp.join(self.work_dir, 'summary', f'summary_{time_str}.csv')
|
output_csv_path = osp.join(self.work_dir, 'summary', f'summary_{time_str}.csv')
|
||||||
|
output_md_path = osp.join(self.work_dir, 'summary', f'summary_{time_str}.md')
|
||||||
else:
|
else:
|
||||||
output_csv_path = output_path.replace('.txt', '.csv')
|
output_csv_path = output_path.replace('.txt', '.csv')
|
||||||
|
output_md_path = output_path.replace('.txt', '.md')
|
||||||
|
|
||||||
output_dir = osp.split(output_path)[0]
|
output_dir = osp.split(output_path)[0]
|
||||||
mmengine.mkdir_or_exist(output_dir)
|
mmengine.mkdir_or_exist(output_dir)
|
||||||
|
|
||||||
|
# process md table
|
||||||
|
md_table = self._format_md_table(table)
|
||||||
|
|
||||||
with open(output_path, 'w', encoding='utf-8') as f:
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
text = f'{time_str}\n' + \
|
text = f'{time_str}\n' + \
|
||||||
'tabulate format\n' + \
|
'tabulate format\n' + \
|
||||||
@ -320,6 +338,10 @@ class DefaultSummarizer:
|
|||||||
'^' * 128 + '\n' + \
|
'^' * 128 + '\n' + \
|
||||||
'\n'.join([','.join(row) for row in table]) + '\n' + \
|
'\n'.join([','.join(row) for row in table]) + '\n' + \
|
||||||
'$' * 128 + '\n\n' + \
|
'$' * 128 + '\n\n' + \
|
||||||
|
'markdown format\n' + \
|
||||||
|
'^' * 128 + '\n' + \
|
||||||
|
md_table + '\n' + \
|
||||||
|
'$' * 128 + '\n' + \
|
||||||
'-' * 128 + ' THIS IS A DIVIDER ' + '-' * 128 + '\n\n' + \
|
'-' * 128 + ' THIS IS A DIVIDER ' + '-' * 128 + '\n\n' + \
|
||||||
'raw format\n' + \
|
'raw format\n' + \
|
||||||
'^' * 128 + '\n' + \
|
'^' * 128 + '\n' + \
|
||||||
@ -332,6 +354,11 @@ class DefaultSummarizer:
|
|||||||
f.write('\n'.join([','.join(row) for row in table]) + '\n')
|
f.write('\n'.join([','.join(row) for row in table]) + '\n')
|
||||||
self.logger.info(f'write csv to {osp.abspath(output_csv_path)}')
|
self.logger.info(f'write csv to {osp.abspath(output_csv_path)}')
|
||||||
|
|
||||||
|
with open(output_md_path, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(md_table)
|
||||||
|
print(f'\n\nThe markdown format results is as below:\n\n{md_table}')
|
||||||
|
self.logger.info(f'write markdown summary to {osp.abspath(output_md_path)}')
|
||||||
|
|
||||||
def summarize(
|
def summarize(
|
||||||
self,
|
self,
|
||||||
output_path: str = None,
|
output_path: str = None,
|
||||||
|
Loading…
Reference in New Issue
Block a user