-
Notifications
You must be signed in to change notification settings - Fork 4
/
script_typeAnnotation_analysis.py
102 lines (73 loc) · 3.4 KB
/
script_typeAnnotation_analysis.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
import pstats
import time
import multiprocessing
from Code.TypeAnnotations import gitUtils, Utils
from Code.TypeAnnotations.projectUtils import *
import cProfile
import tarfile
def typeAnnotation_analisis():
if config.EXTRACT:
tar = tarfile.open(config.ROOT_DIR + "/Resources/Output/typeAnnotationChanges.tar.xz", "r:xz")
tar.extractall(config.ROOT_DIR + "/Resources/Output/")
tar.close()
tar = tarfile.open(config.ROOT_DIR + "/Resources/Output/typeAnnotationCommitStatistics.tar.xz", "r:xz")
tar.extractall(config.ROOT_DIR + "/Resources/Output/")
tar.close()
if config.CLONING:
j = [0]
gitUtils.repo_cloning_oneplus(config.ROOT_DIR + "/Resources/Input/oneplus_list.json",
config.ROOT_DIR + "/GitHub", j)
if config.STATISTICS_COMPUTATION:
start = time.time()
# List of repositories
dirlist: list = [item for item in os.listdir(config.ROOT_DIR + "/GitHub") if
os.path.isdir(os.path.join(config.ROOT_DIR + "/GitHub", item))]
# List of statistics from processes to be merged
process_statistics = []
if config.TEST:
profile = cProfile.Profile()
profile.enable()
print("\nWorking on TEST CONFIGURATION")
process_statistics += gitUtils.query_repo_get_changes("mypy")
profile.disable()
ps = pstats.Stats(profile).sort_stats('cumulative')
ps.print_stats()
else:
with multiprocessing.Pool(multiprocessing.cpu_count()) as p:
process_statistics += p.imap_unordered(gitUtils.query_repo_get_changes, dirlist)
code_changes: list = []
commit_statistics: list = []
# The statistics are merged from the processes
statistics_final: CodeStatistics = CodeStatistics()
statistics_final.merge_results(process_statistics, code_changes, commit_statistics)
if statistics_final.total_typeAnnotation_codeChanges > 0:
# Statistics computation
try:
statistics_final.statistics_computation()
except Exception as e:
print("Error during statistics computation",str(e))
else:
print('No type annotation code changes found')
exit()
# Computational time
end = time.time()
hours, rem = divmod(end - start, 3600)
minutes, seconds = divmod(rem, 60)
statistics_final.execution_time = "{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), seconds)
# Write results in files
try:
# Remove old files
Utils.delete_all_files_in_folder(config.ROOT_DIR + '/Resources/Output/')
# Compute new files
write_results(statistics_final, code_changes, commit_statistics)
except Exception as e:
print('Error writing results in files:', str(e))
print("\nStatistics computed in " + "{:0>2}:{:0>2}:{:05.2f}".format(int(hours), int(minutes), seconds))
# Plots the results from the file Output/typeAnnotationAllStatisticsRAW.json
if config.PLOT:
statistics_final: CodeStatistics = load_final_statistics()
myplot(statistics_final)
print("\nProgram ends successfully")
if __name__ == "__main__":
# Script configuration file in Code/TypeAnnotations/config.py
typeAnnotation_analisis()