-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.py
94 lines (47 loc) · 1.61 KB
/
helpers.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
import math
def __split_package_name(package_name):
result = []
end = package_name.find('.')
while end > 0:
result.append(package_name[0:end])
end = package_name.find('.', end + 1)
result.append(package_name)
return result
def __resolve_packages(line, keyword):
start = line.find(keyword) + len(keyword)
end = line.find(';', start)
if start < end:
package_name = line[start:end].strip()
return __split_package_name(package_name)
return []
def resolve_package_usage(record, keyword):
if record is not None:
lines = record.split('\n')
for line in lines:
if line.startswith(keyword):
packages = __resolve_packages(line, keyword)
for each in packages:
yield (each, 1)
def compare_by_value(kv1, kv2):
_, value1 = kv1
_, value2 = kv2
return value1 < value2
def resolve_package_help_score(record, keyword):
count = 0
package_name = ''
if record is not None:
lines = record.split('\n')
for each in lines:
if each.startswith(keyword):
package_name = each
if each in ['FIXME', 'TODO']:
count += 1
packages = (__resolve_packages(package_name, keyword))
for package in packages:
yield (package, count)
def calculate_composite_score(popular, help):
for element in popular:
if help.get(element[0]):
composite = math.log(help.get(element[0])) * math.log(element[1])
if composite > 0:
yield (element[0], composite)