-
Notifications
You must be signed in to change notification settings - Fork 0
/
summarize.py
executable file
·166 lines (148 loc) · 5.32 KB
/
summarize.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
#!/usr/bin/python3
import argparse
import yaml
import enum
from compare import ComparisonResults, DiffType
CATEGORY_KEY = "category"
class SynResult(enum.StrEnum):
TRIVIAL = enum.auto()
NON_TRIVIAL = enum.auto()
WRONG = enum.auto()
class SemResult(enum.StrEnum):
UNKNOWN = enum.auto()
SIMPLE = enum.auto()
COMPLEX = enum.auto()
GENUINE = enum.auto()
def parse_args():
parser = argparse.ArgumentParser(
description="Summarize the complete results after manual review."
)
parser.add_argument(
"original_results",
help="path to the original results",
)
parser.add_argument(
"semantic_review",
help="path to the semantic manual review results",
)
parser.add_argument(
"syntactic_review",
help="path to the syntactic manual review results",
)
parser.add_argument(
"--output",
default="summary.yml",
help="path to the directory where the summary will be stored",
)
return parser.parse_args()
if __name__ == "__main__":
args = parse_args()
original_stats = ComparisonResults.load(args.original_results).get_stats()
with open(args.semantic_review, "r") as f:
semantic_review = yaml.safe_load(f)
with open(args.syntactic_review, "r") as f:
syntactic_review = yaml.safe_load(f)
summary = {
tag_key: {
DiffType.SEMANTIC.value: {},
DiffType.SYNTACTIC.value: {},
}
for tag_key in original_stats.keys()
}
for tag_key, tag_stats in original_stats.items():
summary[tag_key][DiffType.NO_DIFF.value] = original_stats[tag_key][
DiffType.NO_DIFF.value
]
summary[tag_key][DiffType.UNKNOWN.value] = original_stats[tag_key][
DiffType.UNKNOWN.value
]
semantic_results = [
semantic_review[tag_key][function][CATEGORY_KEY]
for function in semantic_review[tag_key].keys()
]
if not all(
[
x in [sem_result.value for sem_result in SemResult]
for x in semantic_results
]
):
print(f"WARNING: Unknown semantic review type in {tag_key}.")
for semantic_review_type in SemResult:
summary[tag_key][DiffType.SEMANTIC.value][semantic_review_type.value] = len(
[x for x in semantic_results if x == semantic_review_type.value]
)
if syntactic_review is None or tag_key not in syntactic_review:
summary[tag_key][DiffType.SYNTACTIC.value] = {
SynResult.TRIVIAL.value: 0,
SynResult.WRONG.value: 0,
SynResult.NON_TRIVIAL.value: original_stats[tag_key][
DiffType.SYNTACTIC.value
],
}
continue
syntactic_results = [
syntactic_review[tag_key][function][CATEGORY_KEY]
for function in syntactic_review[tag_key].keys()
]
if not all(
[
x in [syn_result.value for syn_result in SynResult]
for x in syntactic_results
]
):
print(f"WARNING: Unknown syntactic review type in {tag_key}.")
summary[tag_key][DiffType.SYNTACTIC.value][SynResult.TRIVIAL.value] = len(
[x for x in syntactic_results if x == SynResult.TRIVIAL.value]
)
summary[tag_key][DiffType.SYNTACTIC.value][SynResult.WRONG.value] = len(
[x for x in syntactic_results if x == SynResult.WRONG.value]
)
summary[tag_key][DiffType.SYNTACTIC.value][SynResult.NON_TRIVIAL.value] = (
original_stats[tag_key][DiffType.SYNTACTIC.value]
- summary[tag_key][DiffType.SYNTACTIC.value][SynResult.TRIVIAL.value]
- summary[tag_key][DiffType.SYNTACTIC.value][SynResult.WRONG.value]
)
summary["total"] = {
DiffType.SEMANTIC.value: {},
DiffType.SYNTACTIC.value: {},
DiffType.NO_DIFF.value: sum(
[
summary[tag_key][DiffType.NO_DIFF.value]
for tag_key in original_stats.keys()
]
),
DiffType.UNKNOWN.value: sum(
[
summary[tag_key][DiffType.UNKNOWN.value]
for tag_key in original_stats.keys()
]
),
}
for review_type in SemResult:
summary["total"][DiffType.SEMANTIC.value][review_type.value] = sum(
[
summary[tag_key][DiffType.SEMANTIC.value][review_type.value]
for tag_key in original_stats.keys()
]
)
summary["total"][DiffType.SEMANTIC.value]["total"] = sum(
[
summary["total"][DiffType.SEMANTIC.value][review_type.value]
for review_type in SemResult
]
)
for review_type in SynResult:
summary["total"][DiffType.SYNTACTIC.value][review_type.value] = sum(
[
summary[tag_key][DiffType.SYNTACTIC.value][review_type.value]
for tag_key in original_stats.keys()
]
)
summary["total"][DiffType.SYNTACTIC.value]["total"] = sum(
[
summary["total"][DiffType.SYNTACTIC.value][review_type.value]
for review_type in SynResult
]
)
with open(args.output, "w") as output:
yaml.safe_dump(summary, output)