-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevalTestSet.py
More file actions
57 lines (41 loc) · 1.63 KB
/
evalTestSet.py
File metadata and controls
57 lines (41 loc) · 1.63 KB
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
import pickle
from pathlib import Path
from datetime import datetime
from tqdm import tqdm
from dfp_main import patch, PatchStats, setVerbose
TEST_SET_PATH = "testSet"
# How many test files should be examined [0,100]
LIMIT = None
def evaluateTestSet():
testFiles = list(Path(TEST_SET_PATH).iterdir())
testPairs = [(testFiles[i], testFiles[i + 1]) for i in range(0, len(testFiles), 2)]
all_stats = []
for dockerfile, violationFile in tqdm(testPairs[:LIMIT]):
stats = patch(str(dockerfile), str(violationFile), quiet=True)
all_stats.append(stats)
for s in all_stats:
print(s)
with open(f"evalStats_{datetime.now().strftime('%d%m%Y_%H%M')}.pkl", "wb") as f:
pickle.dump(all_stats, f, protocol=pickle.HIGHEST_PROTOCOL)
times = list(map(lambda it: it.time, all_stats))
avg_time = sum(times) / len(times)
total = sum(map(lambda it: it.total, all_stats))
fixed = sum(map(lambda it: it.fixed, all_stats))
unfixed = sum(map(lambda it: it.unfixed, all_stats))
verified_patches = [p for stat in all_stats for p in stat.patches]
position_dist = {}
rule_dist = {}
for p in verified_patches:
if p.position not in position_dist:
position_dist[p.position] = 0
position_dist[p.position] += 1
if p.rule not in rule_dist:
rule_dist[p.rule] = 0
rule_dist[p.rule] += 1
setVerbose(True)
PatchStats(total, fixed, unfixed).print()
print(f"Average time: {avg_time}s")
print(f"Position distribution: {position_dist}")
print(f"Rule distribution: {rule_dist}")
if __name__ == "__main__":
evaluateTestSet()