Skip to content

Commit 23125e6

Browse files
analysis: add functionality for patcher comparison
1 parent bed7f19 commit 23125e6

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

src/main/python/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ run-eval = "result_analysis.__main__:main"
2121
power-simulation = "result_analysis.simulation:main"
2222
find-example = "result_analysis.__main__:example"
2323
find-outliers = "result_analysis.__main__:outliers"
24+
compare-patchers = "result_analysis.__main__:compare"
2425

2526
[build-system]
2627
requires = ["poetry-core>=1.0.0"]

src/main/python/result_analysis/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from result_analysis.tables import (
22
find_example,
33
metrics_table_generation,
4+
venn_diagram,
45
)
56
from result_analysis.analyze_results import find_outliers
67

@@ -28,5 +29,9 @@ def outliers():
2829
find_outliers(results_dir + "rep-1/", repo_sample, False)
2930

3031

32+
def compare():
33+
venn_diagram(results_dir + "rep-1/", repo_sample, False)
34+
35+
3136
if __name__ == "__main__":
3237
main()

src/main/python/result_analysis/tables.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,107 @@ def find_example(path_to_results, path_to_repo_list, only_non_trivial):
229229
print(f"Target: {url}{res_mpatch.pick_id}")
230230
print()
231231
print()
232+
233+
234+
def venn_diagram(path_to_results, path_to_repo_list, only_non_trivial):
235+
global languages
236+
repos = load_repositories(path_to_repo_list)
237+
238+
results_per_patcher = {}
239+
for patcher in Patcher: # Patcher is an enum
240+
results = load_all_results(path_to_results, patcher)
241+
# Filter trivial results
242+
if only_non_trivial:
243+
results = non_trivial_results(results)
244+
# Group results by repo
245+
results_per_patcher[patcher] = results_per_repo(results, repos)
246+
247+
results = results_per_patcher[Patcher.MPatch]
248+
249+
rm_best = 0
250+
rm_equal = 0
251+
rm_worse = 0
252+
num_total = 0
253+
rc_better = 0
254+
ru_better = 0
255+
ra_better = 0
256+
rc_worse = 0
257+
ru_worse = 0
258+
ra_worse = 0
259+
260+
for repo in results.keys():
261+
repo_results_mpatch = results[repo]
262+
repo_results_upatch = results_per_patcher[Patcher.UnixPatch][repo]
263+
repo_results_apply = results_per_patcher[Patcher.GitApply][repo]
264+
repo_results_cherry = results_per_patcher[Patcher.GitCherry][repo]
265+
266+
sorted(repo_results_mpatch, key=lambda x: x.pick_id)
267+
sorted(repo_results_upatch, key=lambda x: x.pick_id)
268+
sorted(repo_results_apply, key=lambda x: x.pick_id)
269+
sorted(repo_results_cherry, key=lambda x: x.pick_id)
270+
271+
repo_results_mpatch = {r.run_id: r for r in repo_results_mpatch}
272+
repo_results_upatch = {r.run_id: r for r in repo_results_upatch}
273+
repo_results_apply = {r.run_id: r for r in repo_results_apply}
274+
repo_results_cherry = {r.run_id: r for r in repo_results_cherry}
275+
276+
for i in repo_results_mpatch.keys():
277+
res_mpatch = repo_results_mpatch.get(i, None)
278+
if res_mpatch is None:
279+
continue
280+
281+
res_upatch = repo_results_upatch.get(i, None)
282+
res_cherry = repo_results_cherry.get(i, None)
283+
res_apply = repo_results_apply.get(i, None)
284+
285+
rm = res_mpatch.outcome_classification.num_incorrect()
286+
rc = (
287+
res_cherry.outcome_classification.num_incorrect()
288+
if res_cherry is not None
289+
else float("inf")
290+
)
291+
ru = (
292+
res_upatch.outcome_classification.num_incorrect()
293+
if res_upatch is not None
294+
else float("inf")
295+
)
296+
ra = (
297+
res_apply.outcome_classification.num_incorrect()
298+
if res_apply is not None
299+
else float("inf")
300+
)
301+
lang, user = res_mpatch.dataset.split("_")[:2]
302+
repo = "_".join(res_mpatch.dataset.split("_")[2:])
303+
304+
if rm < rc:
305+
rc_worse += 1
306+
if rm < ru:
307+
ru_worse += 1
308+
if rm < ra:
309+
ra_worse += 1
310+
311+
if rm < rc and rm < ru and rm < ra:
312+
rm_best += 1
313+
elif rm <= rc and rm <= ru and rm <= ra:
314+
rm_equal += 1
315+
else:
316+
rm_worse += 1
317+
if rm > rc:
318+
rc_better += 1
319+
if rm > ru:
320+
ru_better += 1
321+
if rm > ra:
322+
ra_better += 1
323+
num_total += 1
324+
325+
print("mpatch is best: " + str(rm_best / num_total))
326+
print("mpatch at least as good: " + str(rm_equal / num_total))
327+
print("mpatch worse: " + str(rm_worse / num_total))
328+
print("cp better: " + str(rc_better / num_total))
329+
print("patch better: " + str(ru_better / num_total))
330+
print("apply better: " + str(ra_better / num_total))
331+
332+
print("cp worse: " + str(rc_worse / num_total))
333+
print("patch worse: " + str(ru_worse / num_total))
334+
print("apply worse: " + str(ra_worse / num_total))
335+
print()

0 commit comments

Comments
 (0)