-
Notifications
You must be signed in to change notification settings - Fork 10
/
stats.py
71 lines (56 loc) · 2.13 KB
/
stats.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
from typing import List
from ghcl.contributions import Contributions
from ghcl.github_stats import GithubStats
from ghcl.models.user_experience import UserPRExperience, ExperienceSummary
from ghcl.models.user_stats import UserStats
from utils.args import parse_args
def _stats_with_exp(e: UserPRExperience) -> (UserPRExperience, List[int]):
return (e, [stat.pr_count() for stat in stats])
def _stats_to_prs(t: (UserPRExperience, List[int])) -> (UserPRExperience, int):
return (t[0], sum(t[1]))
def _experience_data(stats: List[UserStats]) -> str:
experiences = [stat.user_past_pr_experience() for stat in stats]
sorted_experience = sorted(experiences, key=lambda exp: exp.value[0])
def _to_summary_experience(t: (UserPRExperience, int)) -> str:
return ExperienceSummary(
user_experience=t[0],
people_count=sorted_experience.count(t[0]),
pr_count=t[1]
).summary()
past_summaries = map(
_to_summary_experience,
map(
_stats_to_prs,
map(_stats_with_exp, sorted_experience)
)
)
return '\n'.join(past_summaries)
args = parse_args()
contribs = Contributions(
stats_client=GithubStats(access_token=args['access_token']),
http_pool_size=args['http_pool_size']
)
stats = contribs.leaderboard(
args['users'], args['start_date'], args['end_date'])
print("===========================")
print("Leaderboard")
print("===========================")
for stat in stats:
print(getattr(stat, f"{args['mode']}_data")())
print("===========================")
if args['with_summary']:
print()
print("===========================")
print("Summary")
print("===========================")
print(f"Users:")
user_count = len(args['users'])
print(f" count: {user_count}")
print("PRs overall:")
in_period_pr_count = sum([stat.pr_count() for stat in stats])
print(f" during period: {in_period_pr_count}")
total_pr_count = sum([stat.total_count for stat in stats])
print(f" overall: {total_pr_count}")
print("User experience:")
print(_experience_data(stats))
print("===========================")