-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacro_stats.py
More file actions
36 lines (30 loc) · 955 Bytes
/
Copy pathmacro_stats.py
File metadata and controls
36 lines (30 loc) · 955 Bytes
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
import difflib
def read_file(filename):
with open(filename, 'r') as filename:
l = filename.read().splitlines()
return l
def similar(a, b):
ratio = difflib.SequenceMatcher(None, a, b).ratio() * 100
#print (str(a) + " ratio " + str(b) + " = " + str(ratio))
return ratio
macros = read_file('result/all_macros.txt')
attrs = read_file('result/all_attrs.txt')
stats = {}
row = set()
for macro in macros:
stats[macro.split()[0]] = 0
for macro in macros:
defn = macro.split()
max_similarity = 0
for attr in attrs:
similarity = similar(defn[1], attr)
if (similarity > max_similarity):
max_similarity = similarity
row.add((defn[1], attr, max_similarity))
if (max_similarity >= 80):
stats[defn[0]] += 1
else:
stats[defn[0]] -= 1
for k, v in sorted(stats.items(), key=lambda x:x[1], reverse=True):
if not 'module' in k.lower():
print (k, v)