-
Notifications
You must be signed in to change notification settings - Fork 2
/
eval2csv.py
54 lines (40 loc) · 1.56 KB
/
eval2csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import pandas as pd
import argparse
import json
import os
import sys
def main(args):
output_data = []
if args.output_file is None:
print("No output file specified, exiting.")
sys.exit(1)
for file in args.file_list:
print("Reading in {}".format(file))
with open(file) as raw_data:
results = json.load(raw_data)
filename = os.path.basename(file)
data_row = {}
data_row.update({'name': '.'.join(filename.split('.')[:-1])})
data_row.update(results)
output_data.append(data_row)
columns = output_data[0].keys()
df = pd.DataFrame(output_data, columns=columns)
if args.verbose:
print(df)
output_dir = args.output_dir
output_file = os.path.join(output_dir, args.output_file)
print("Writing combined results to {}".format(output_file))
df.to_csv(output_file, index=False)
if __name__ == '__main__':
parser = argparse.ArgumentParser(
description="Combine evaluation results into a single CSV file")
parser.add_argument('file_list', type=str, nargs='*',
help='list of files to be evaluated')
parser.add_argument('--output_dir', type=str, default='results/',
help='Directory where to output the CSV file')
parser.add_argument('--output_file', type=str, default=None,
help='Name of output CSV file')
parser.add_argument('--verbose', action='store_true',
help='Output parsed results to stdout')
args = parser.parse_args()
main(args=args)