Skip to content

Instantly share code, notes, and snippets.

@cyyself
Created November 16, 2024 06:07
Show Gist options
  • Save cyyself/3a108ee642f1d654b4ffa68f25c0b29a to your computer and use it in GitHub Desktop.
Save cyyself/3a108ee642f1d654b4ffa68f25c0b29a to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import sys
from pathlib import Path
def read_csv(file_path: Path):
filename = file_path.name
with open(file_path, 'r') as file:
lines = file.readlines()
result_line_idx = lines.index('"Selected Results Table"\n')
keys = lines[result_line_idx + 2].strip().split(',')
keys = [key.replace('"','') for key in keys]
keys.extend(["config", "filename"])
config_name = 'default'
for i in range(result_line_idx + 3, len(lines)):
line_str = lines[i].strip()
if line_str.startswith('"runcpu command:","'):
args = line_str.split(' ')
if args.index('--configfile') != -1:
config_name = args[args.index('--configfile') + 1]
result = []
for i in range(result_line_idx + 3, len(lines)):
line_str = lines[i].strip()
if len(line_str) == 0:
break
values = line_str.split(',')
values = [value.replace('"','') for value in values]
values = [value.replace('"','') for value in values]
values.extend([config_name, filename])
cur_value = dict(zip(keys, values))
if cur_value['Est. Base Run Time'] == '' and cur_value['Est. Peak Run Time'] == '':
continue
result.append(cur_value)
return result
if __name__ == '__main__':
csv_files = []
for p in Path("result").iterdir():
if p.is_file() and p.suffix == '.csv':
csv_files.append(p)
keys = []
for csv_file in sorted(csv_files):
result = read_csv(csv_file)
if len(keys) == 0:
keys = result[0].keys()
print(','.join(keys))
print('\n'.join([','.join([row[key] for key in keys]) for row in result]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment