22NUM_OUTLIERS_TO_REMOVE = 2
27 with open(csv_file,
'rb')
as f:
28 csv_reader = csv.reader(f, delimiter=
',')
30 header_row = csv_reader.next()
31 if header_row[0] !=
'id':
32 raise Exception(
'%s in unexpected format' % csv_file)
33 p = re.compile(
'^.*,test=(.*),$')
36 result = p.search(v[0])
37 test_name = result.group(1)
39 vals = [
float(i)
for i
in v[1:]]
42 vals = vals[NUM_OUTLIERS_TO_REMOVE:-NUM_OUTLIERS_TO_REMOVE]
44 avg_val = reduce(
lambda x, y: x+y, vals) /
float(
len(vals))
45 test_to_avg[test_name] = avg_val
51 for test1, v1
in d1.items():
52 v2 = d2.get(test1, MISSING_STR)
53 perc_diff = MISSING_STR
57 perc_diff = 0
if avg == 0
else diff/avg * 100
62 'perc_diff': perc_diff,
64 test_to_result[test1] = result
67 for test2, v2
in d2.items():
68 if test2
in test_to_result:
70 test_to_result[test2] = {
74 'perc_diff': MISSING_STR,
81 with open(output_csv,
'w')
as f:
82 fieldnames = [
'test_name',
'csv1',
'csv2',
'perc_diff']
83 writer = csv.DictWriter(f, fieldnames=fieldnames)
85 tests = output_dict.keys()
88 writer.writerow(output_dict[test])
99 option_parser = optparse.OptionParser()
100 option_parser.add_option(
101 '',
'--csv1', type=str,
102 help=
'The first CSV to parse.')
103 option_parser.add_option(
104 '',
'--csv2', type=str,
105 help=
'The second CSV to parse.')
106 option_parser.add_option(
107 '',
'--output_csv', type=str,
108 help=
'The file to write the output CSV to.')
109 options, _ = option_parser.parse_args()
113if __name__ ==
'__main__':
def combine_results(d1, d2)
def read_from_csv(csv_file)
def write_to_csv(output_dict, output_csv)
def parse_and_output(csv1, csv2, output_csv)