-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcollectData.py
More file actions
60 lines (54 loc) · 1.36 KB
/
collectData.py
File metadata and controls
60 lines (54 loc) · 1.36 KB
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
from Database import Connector
def load(filename):
data = []
with open(filename) as f:
for row in f:
data.append(row.split(','))
return data
def loadDB():
con = Connector()
table = 'filetable'
filelist = con.get(table, ['lang'])
cnt = {}
for d in filelist:
if d['lang'] in cnt:
cnt[d['lang']] += 1
else:
cnt[d['lang']] = 1
with open('lang.csv', 'w') as f:
for k, v in cnt.items():
f.write('%s,%s\n' % (k, v))
def count(dic, name, cnt):
if not name in dic:
dic[name] = cnt
else:
dic[name] += cnt
lang = [
'C++', 'Java', 'Python', 'PyPy', 'C#'
]
if __name__=='__main__':
loadDB()
data = load('lang.csv')
res = {}
sum_all = 0
for d in data:
name = d[0].replace('"', '')
cnt = int(d[1])
sum_all += cnt
for l in lang:
if l in name:
count(res, l, cnt)
break
else:
count(res, name, cnt)
res['Python'] += res['PyPy']
del res['PyPy']
stat = {}
for key, value in res.items():
par = value*100/sum_all
if par < 1:
count(stat, 'other', par)
else:
count(stat, key, par)
for d in sorted([(value, key) for (key, value) in stat.items()]):
print('"%s", %f' % (d[1], d[0]))