-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathload.py
261 lines (205 loc) · 8.48 KB
/
load.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/usr/bin/env python
#-*- coding:utf-8 -*-
##
## load.py
##
## Created on: Jun 05, 2015
## Author: Alexey S. Ignatiev
## E-mail: [email protected]
##
#
#==============================================================================
import csv
import json
import statutil
import six
import sys
#
#==============================================================================
def load_data(files, options):
"""
Loads data from the input files.
"""
try: # if JSON data
return load_json(statutil.StatArray(files), options)
except statutil.JSONException as e:
sys.stderr.write('\033[33;1mWarning:\033[m ' + str(e) + '\033[m\n')
sys.stderr.write('Probably not a JSON format. Trying to read as CSV.\n')
# reading CSV
# expecting exactly one input file
with open(files[0], 'r') as fp:
# try:
rows = csv.reader(fp, delimiter=' ', quotechar='|')
rows = [row for row in rows]
stats = []
names = [n.strip() for n in rows[0][1:] if n.strip()]
for row in rows[1:]:
stats.append([val.strip() for val in row[1:] if val.strip()])
return load_csv(names, stats, options)
# except:
# sys.stderr.write('\033[31;1mError:\033[m Unable to read input file(s).\n')
#
#==============================================================================
def load_json(stat_arr, options):
"""
Loads runtime data from STAT objects.
"""
# preparing data
if options['join_key']:
stat_arr.cluster(use_key=options['join_key'])
data = []
# choosing the minimal value
min_val = 0.000000001
if options['plot_type'] == 'scatter':
if options['x_min']:
min_val = max(options['x_min'], options['y_min'])
else:
min_val = options['y_min'] # options['y_min'] is always defined
# processing (normal) separate data
for stat_obj in stat_arr:
vals = []
num_solved = 0
last_val = -1
for inst in stat_obj.insts_own: # insts_own are sorted
if options['key'] in stat_obj.data[inst]:
val = stat_obj.data[inst][options['key']]
else:
val = float(options['timeout'])
if stat_obj.data[inst]['status'] == True:
if val > last_val:
last_val = val
if val >= float(options['timeout']):
val = float(options['timeout'])
elif val <= min_val:
val = min_val
num_solved += 1
else:
val = float(options['timeout'])
if options['plot_type'] == 'cactus':
val *= 10
vals.append(val)
if type(options['legend']) is list:
label = ' '.join([stat_obj.preamble[k] for k in options['legend']])
else:
label = stat_obj.preamble[options['legend']]
label = label.strip()
data.append((label, vals, num_solved, last_val))
# processing VBSes
if options['vbs']:
for vbs_name, tools in options['vbs'].items():
max_value = float(options['timeout']) if options['plot_type'] == 'scatter' else 10 * float(options['timeout'])
vals = { i: max_value for i in stat_arr.inst_full}
num_solved = 0
if tools != 'all':
for stat_obj in stat_arr:
if type(options['legend']) is list:
p = ' '.join([stat_obj.preamble[k] for k in options['legend']])
else:
p = stat_obj.preamble[options['legend']]
p = p.strip()
if p in tools:
for inst, d in six.iteritems(stat_obj.data):
if d['status'] == True:
if d[options['key']] >= float(options['timeout']):
d[options['key']] = max_value
elif vals[inst] >= max_value:
num_solved += 1
vals[inst] = max([min_val, min([d[options['key']], vals[inst]])])
else: # VBS among all the tools
for stat_obj in stat_arr:
for inst, d in six.iteritems(stat_obj.data):
if d['status'] == True:
if d[options['key']] >= float(options['timeout']):
d[options['key']] = max_value
elif vals[inst] >= max_value:
num_solved += 1
vals[inst] = max([min_val, min([d[options['key']], vals[inst]])])
last_val = -1
for v in six.itervalues(vals):
if v > last_val and v < max_value:
last_val = v
data.append((vbs_name, [vals[i] for i in stat_arr.inst_full], num_solved, last_val))
if options['only']:
data = [d for d in data if d[0] in options['only']]
if options['repls']:
data = [(options['repls'][n], v, s, l) if n in options['repls'] else (n, v, s, l) for n, v, s, l in data]
return sorted(data, key=lambda x: x[2] + len(x[1]) / sum(x[1]), reverse=not options['reverse'])
#
#==============================================================================
def load_csv(names, stats, options):
"""
Loads runtime CSV data.
"""
# choosing the minimal value
min_val = 0.000000001
if options['plot_type'] == 'scatter':
if options['x_min']:
min_val = max(options['x_min'], options['y_min'])
else:
min_val = options['y_min'] # options['y_min'] is always defined
names_orig = names[:]
if options['repls']:
names = [options['repls'][n] if n in options['repls'] else n for n in names]
# processing (normal) separate data
lens = [0 for n in names]
vals_all = [[] for n in names]
last_vals = [-1 for n in names]
for vlist in stats:
vlist = [float(val) for val in vlist]
for i, val in enumerate(vlist):
if val < float(options['timeout']):
if val > last_vals[i]:
last_vals[i] = val
if val < min_val:
val = min_val
lens[i] += 1
else:
val = float(options['timeout'])
if options['plot_type'] == 'cactus':
val *= 10
vals_all[i].append(val)
# processing VBSes
if options['vbs']:
for vbs_name, tools in options['vbs'].items():
vals = []
len_ = 0
last_val = -1
if tools != 'all':
tools = [n if n in tools else '' for n in names_orig]
for vlist in stats:
vlist = [float(val) for i, val in enumerate(vlist) if tools[i]]
val = min(vlist)
if val < float(options['timeout']):
if val > last_val:
last_val = val
if val < min_val:
val = min_val
len_ += 1
else:
val = options['timeout']
if options['plot_type'] == 'cactus':
val *= 10
vals.append(val)
else: # VBS among all the tools
for vlist in stats:
val = min([float(val) for val in vlist])
if val < float(options['timeout']):
if val > last_val:
last_val = val
if val < min_val:
val = min_val
len_ += 1
else:
val = options['timeout']
if options['plot_type'] == 'cactus':
val *= 10
vals.append(val)
names.append(vbs_name)
names_orig.append(vbs_name)
vals_all.append(vals)
lens.append(len_)
last_vals.append(last_val)
data = [[n, t, s, l] for n, t, s, l in zip(names, vals_all, lens, last_vals)]
if options['only']:
data = [d for i, d in enumerate(data) if names_orig[i] in options['only']]
return sorted(data, key=lambda x: x[2] + len(x[1]) / sum(x[1]), reverse=not options['reverse'])