-
Notifications
You must be signed in to change notification settings - Fork 2
/
_0_calc_score.py
76 lines (63 loc) · 2.17 KB
/
_0_calc_score.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
import datetime
hardcoded_issue_counts = {
# https://code.djangoproject.com/query
'django/django': 1424,
# Laravel has no ticketing system?
# Use core framework as proxy, assuming stars proportional to issues
# https://github.com/laravel/framework/issues
'laravel/laravel': 218,
}
# basically:
# stars * .01 + stars / days * 2 + stars / (non_self_issue_count) * 20
def calc_score(repo_dict, mean_stars_per_issue):
repo_dict['score'] = repo_dict['stargazers_count'] * .01
repo_dict['score'] += repo_dict['stargazers_count'] / (repo_dict['age'].days or 1) * 2
if repo_dict['has_issues']:
issue_count = (
repo_dict['open_issues_count'] - repo_dict['pull_count'] - repo_dict['self_issue_count']
)
# (can hardcode issue counts for projects which don't use github for issues)
elif repo_dict['full_name'] in hardcoded_issue_counts:
issue_count = hardcoded_issue_counts[repo_dict['full_name']]
else:
issue_count = repo_dict['stargazers_count'] / mean_stars_per_issue
repo_dict['issue_count'] = issue_count
repo_dict['score'] += repo_dict['stargazers_count'] / (issue_count or 1) * 20
return repo_dict['score']
fake_repo_dict = {
'full_name': 'fake_user/fake_repo',
'stargazers_count': 100,
'has_issues': True,
'open_issues_count': 10,
'age': datetime.timedelta(days=100),
'pull_count': 2,
'self_issue_count': 3
}
missing_pull_count = {
'full_name': 'fake_user/fake_repo',
'stargazers_count': 100,
'has_issues': True,
'open_issues_count': 10,
'age': datetime.timedelta(days=100),
}
if __name__ == '__main__':
# Test
print calc_score(fake_repo_dict, mean_stars_per_issue=30)
print 'django:', calc_score({
'full_name': 'django/django',
'stargazers_count': 30000,
'has_issues': False,
'age': datetime.timedelta(days=100)
}, mean_stars_per_issue=30)
print 'django:', calc_score({
'full_name': 'django/django',
'stargazers_count': 200,
'has_issues': False,
'age': datetime.timedelta(days=100)
}, mean_stars_per_issue=30)
print 'foo/bar:', calc_score({
'full_name': 'foo/bar',
'stargazers_count': 1,
'has_issues': False,
'age': datetime.timedelta(days=400),
}, mean_stars_per_issue=10)