-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_getlangstats.py
48 lines (41 loc) · 1.61 KB
/
stats_getlangstats.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
from api_getrepositories import get_all_repositories
from api_getrepolang import get_language_from_repo
import logging as lg
def get_languages_stats():
languages_stats = {}
lg.info("attempting getallrepos!")
repos = get_all_repositories()
alllangsize = 0
for repo in repos:
reponame = repo['name']
repolangs = get_language_from_repo(reponame=reponame)
lg.info("getlanguagefromrepo {reponame}".format(reponame=reponame))
for repolang in repolangs:
if repolang == None:
continue
lg.info("repo found language: {lang}".format(lang=repolang))
if repolang in languages_stats:
languages_stats[repolang] += repolangs[repolang]
else:
languages_stats[repolang] = repolangs[repolang]
alllangsize += repolangs[repolang]
langnames = list(languages_stats.keys())
langsizes = list(languages_stats.values())
lg.info("ordering by size")
for _ in range(0, len(langnames)):
for j in range(0, len(langnames)-1):
if langsizes[j] < langsizes[j+1]:
temp = langsizes[j+1]
langsizes[j+1] = langsizes[j]
langsizes[j] = temp
tempname = langnames[j+1]
langnames[j+1] = langnames[j]
langnames[j] = tempname
result = {}
remaininglangsize = alllangsize
for i in range(0, 5):
result[langnames[i]] = langsizes[i]
remaininglangsize -= langsizes[i]
result['Other'] = remaininglangsize
lg.info(result['Other'])
return result