-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsum_percent.py
More file actions
executable file
·51 lines (43 loc) · 1.47 KB
/
sum_percent.py
File metadata and controls
executable file
·51 lines (43 loc) · 1.47 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
#!/usr/bin/env python3
'''
@file: sum_percent.py
@auth: sprax
@date: 2019-10-06 01:02:13 Sun 06 Oct
Convert size/name pairs, such as from uniq -c, into a table with percentages
Written for Python 3.7.4
'''
# from __future__ import print_function
# import pdb
# from pdb import set_trace
import fileinput
def sum_percent(beg=0, end=1):
''' add percentage column after number & name columns '''
total_tags, total_debt = 0, 0
auths, debts = [], []
for line in fileinput.input():
tokens = line.split()
if len(tokens) > end:
try:
size = int(tokens[beg])
name = tokens[end]
if name[0] == '@':
total_tags += size
auths.append([size, name])
elif name in ['FIXME', 'TODO']:
total_debt += size
debts.append([size, name])
except ValueError:
pass
print("%12s %7s % 7s" % ("AUTHOR", "Count", "Percent"))
for tokens in auths:
size, name = tokens[0:2]
percent = size * 100 / total_debt
print("%12s %7d % 7.1f" % (name, size, percent))
print("%12s %7s % 7s" % ("MARKER", "-----", "-----"))
for tokens in debts:
size, name = tokens[0:2]
percent = size * 100 / total_debt
print("%12s %7d % 7.1f" % (name, size, percent))
print("%12s %7d % 7.1f" % ("TOTALS", total_debt, 100.0))
if __name__ == '__main__':
sum_percent()