-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloc_stat.py
69 lines (57 loc) · 1.74 KB
/
cloc_stat.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
__author__ = 'GVlab'
import csv
languages = ['C#','C++','Python','Javascript','Others']
langout = ['C\#','C++','Python','Javascript (JS)','Others']
langpie = ['C\#','C++','Python','JS','Others']
counts = [0,0,0,0,0]
others = 0
def check_exist(csvLang):
for lang in languages:
if lang in csvLang:
return lang
return ''
def csv_reader(file_obj):
reader = csv.reader(file_obj)
i=0
for row in reader:
#print(" ".join(row))
#if i>2:
# break
if i>0:
#print row[1]
lang = check_exist(row[1])
if lang is not '':
#print row[1]
index = languages.index(lang)
counts[index] = counts[index] + int(row[4])
continue
else:
index = languages.index('Others')
counts[index] = counts[index] + int(row[4])
continue
i=i+1
if __name__ == "__main__":
csv_path = "cloc_code_statistics.csv"
with open(csv_path, "rb") as f_obj:
csv_reader(f_obj)
print languages
print counts
total = sum(counts)
percentage = ''
code_table = 'Language & Lines of code \\\ \hline \n'
comma = 0
for lang in languages:
if comma is 1:
percentage = percentage + ','
index = languages.index(lang)
code_table = code_table + langout[index] + ' & ' + str(counts[index]) + '\\\ \n'
p = float(counts[index])/total
percentage = percentage + str(round(p*100,2)) + '/' + langpie[index]
comma = 1
code_table = code_table + '\hline \n Total' + ' & ' + str(total) + '\\\ \hline \n'
print code_table
print percentage
f = open('cloc_latex.txt', 'w')
f.write(code_table)
f.write(percentage)
f.close()