-
Notifications
You must be signed in to change notification settings - Fork 4
/
merge-results.py
86 lines (67 loc) · 2.78 KB
/
merge-results.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# This file will merge the results from different runs and test cases into a single file based only on the information
# on the folder structure.
import argparse
import os
import yaml
from bs4 import BeautifulSoup
import utils
import csv
def main():
parser = argparse.ArgumentParser(description='Benchmark script')
parser.add_argument('--first', type=str, help='Path to gather the results', default='merge5/')
parser.add_argument('--second', type=str, help='results', default='reports8/')
parser.add_argument('--output', type=str, help='Number of runs the program will process', default='merge6/')
# Parse command-line arguments
args = parser.parse_args()
first = args.first
second = args.second
output = args.output
# Get the list of files from both folders, and merge them into a single set without duplicates
first_files = set(os.listdir(first))
second_files = set(os.listdir(second))
files = first_files.union(second_files)
# Create the output folder if it doesn't exist
if not os.path.exists(output):
os.makedirs(output)
# Iterate over the files and merge them
for file in files:
first_file = os.path.join(first, file)
second_file = os.path.join(second, file)
output_file = os.path.join(output, file)
# If the file is not in the first folder, copy it from the second folder
if not os.path.exists(first_file):
os.system(f'cp {second_file} {output_file}')
continue
# If the file is not in the second folder, copy it from the first folder
if not os.path.exists(second_file):
os.system(f'cp {first_file} {output_file}')
continue
# If the file is in both folders, merge them
# Check if the file is a CSV file
if file.endswith('.csv'):
with open(first_file, 'r') as f:
first_data = list(csv.reader(f))
with open(second_file, 'r') as f:
second_data = list(csv.reader(f))
# Merge the data
result = utils.merge_csv(first_data, second_data)
# Save the result
with open(output_file, 'w') as f:
writer = csv.writer(f)
writer.writerows(result)
continue
elif file.endswith('index.html'):
with open(first_file, 'r') as f:
first_data = f.read()
with open(second_file, 'r') as f:
second_data = f.read()
# Merge the data
result = utils.merge_html(first_data, second_data)
# Save the result
with open(output_file, 'w') as f:
f.write(result)
else:
print(f'File type not supported: {file}')
print('Done!')
if __name__ == '__main__':
main()