forked from Qi247/SimSPI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat_system.py
More file actions
85 lines (74 loc) · 2.35 KB
/
Copy pathstat_system.py
File metadata and controls
85 lines (74 loc) · 2.35 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
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
import os
import matplotlib.pyplot as plt
suffix_names = [
'c', 'cpp', 'h', 'hpp', 'cc', 'java', 'php', 'go', 'js', 'py', 'pl',
'json', 'rb', 'rs'
]
def main():
patch_path = "./raw_patch"
files = os.listdir(patch_path)
line_count_list = []
segment_count_list = []
suffix_dict = {name: 0 for name in suffix_names}
for file in files:
line_count = 0
segment_count = 0
file_path = os.path.join(patch_path, file)
with open(file_path, "rb") as f:
lines = f.readlines()
for line in lines:
if line.startswith(b"+") or line.startswith(b"-"):
line_count += 1
if line.startswith(b"@@"):
segment_count += 1
if line.startswith(b"---"):
suffix = line.split(b".")[-1].decode().strip()
if suffix in suffix_names:
suffix_dict[suffix] += 1
line_count_list.append(line_count)
segment_count_list.append(segment_count)
# print(line_count_list, segment_count_list)
line_count_array = [0] * 50
for count in line_count_list:
if count >= len(line_count_array):
continue
line_count_array[count] += 1
print(line_count_array)
s = ""
for i in range(1, len(line_count_array) + 1):
s += '{:d},'.format(i)
print(s)
segment_count_array = [0] * 20
for count in segment_count_list:
if count >= len(segment_count_array):
continue
segment_count_array[count] += 1
print(segment_count_array)
s = ""
for i in range(1, len(segment_count_array) + 1):
s += '{:d},'.format(i)
print(s)
# print(suffix_dict)
ks = [
'c', 'cpp', 'h', 'hpp', 'cc', 'java', 'php', 'go', 'js', 'py', 'pl',
'json', 'rb', 'others'
]
vs = [
5602, 1033, 3746, 201, 124, 1096, 233, 12, 498, 262, 44, 363, 24, 2300
]
new_vs = []
for v in vs:
new_vs.append(round(v / sum(vs), 2))
print(ks)
print(new_vs)
new_ks = [
'c', 'cpp', 'h', 'hpp', 'cc', 'java', 'php', 'go', 'js', 'py', 'others'
]
vs = [5602, 1033, 3746, 201, 124, 1096, 233, 12, 498, 262, 123]
new_vs = []
for v in vs:
new_vs.append(round(v / sum(vs), 2))
print(new_ks)
print(new_vs)
if __name__ == "__main__":
main()