-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathplot_benchmarks.py
82 lines (70 loc) · 2.32 KB
/
plot_benchmarks.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
from matplotlib import pyplot as plt
from os import listdir
from os.path import isfile, abspath, join
from glob import glob
import sys
import csv
def listFiles(path):
files = sorted(glob(join(path, '*.csv')))
return files
# Format:
# {
# benchmark1: {
# scene1: {
# 'time': [],
# 'primary': [],
# 'extension': [],
# 'shadow': [],
# 'total': [],
# 'samples': [],
# },
# scene2: {...},
# scene3: {...}
# },
# benchmark2: {
# scene2: {...},
# scene3: {...}
# }
# }
data = {}
scene_names = set()
if __name__ == '__main__':
files = listFiles(abspath('.'))
if len(sys.argv) > 1:
files = sys.argv[1:]
for benchmark in files:
with open(benchmark, 'r') as csvfile:
print("Processing file: " + benchmark)
data[benchmark] = {}
plots = csv.reader(csvfile, delimiter=';')
current_scene = ''
for i, row in enumerate(plots):
if i == 0:
header = row[1:] # indices offset by one
continue
scene = row[0].replace('\\', '/').split('/')[-1]
if current_scene != scene:
scene_names.add(scene)
data[benchmark][scene] = {}
for h in header:
data[benchmark][scene][h] = []
current_scene = scene
for idx, value in enumerate(row[1:]):
data[benchmark][scene][header[idx]].append(float(value))
wanted_datas = ['total'] #, 'primary', 'extension', 'shadow']
for scene in scene_names:
print("Creating plot for " + scene)
fig = plt.figure()
plt.title(scene)
axes = fig.add_subplot(111)
for benchmark_name in sorted(data.keys()):
benchmark = data[benchmark_name]
if scene not in benchmark:
continue
scene_data = benchmark[scene]
for colname in wanted_datas:
if colname not in scene_data:
continue
axes.plot(scene_data['time'][1:], scene_data[colname][1:], label="{}: {}".format(benchmark_name, colname))
plt.legend(loc='upper left');
plt.show()