-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgenDist.py
More file actions
executable file
·54 lines (38 loc) · 1.26 KB
/
genDist.py
File metadata and controls
executable file
·54 lines (38 loc) · 1.26 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/python
"""
PDF Generator
Usage:
parser.py [-h] FILE COLUMN OUTPUT_FILE
Options:
-h --help Show this help messages
FILE File to use
COLUMN Column to generate pdf on
OUTPUT_FILE Output file to store results to
"""
from docopt import docopt
if __name__ == "__main__":
arguments = docopt(__doc__, version='PDF/CDF Generator v1')
filename = arguments['FILE']
column = int(arguments['COLUMN'])
outputFile = arguments['OUTPUT_FILE']
histogram = {}
with open(filename) as iFile, open(outputFile, 'w') as oFile:
for line in iFile.readlines():
if line[0] == '#':
continue
key = line.split()[column].strip()
if not histogram.get(key):
histogram[key] = 0
histogram[key] = histogram[key] + 1
oFile.write("# %-8s%-10s%-10s\r\n" % ("Key", "PDF", "CDF"))
totalCount = 0
totalBytes = 0
keys = histogram.keys()
keys.sort(key=int)
for key in keys:
value = histogram[key]
totalCount += int(value)
totalBytes += int(key)*int(value)
oFile.write("%-10s%-10s%-10d\r\n" % (key, value, totalCount))
print ""
print "%-30s: Average log length was %.2lf characters per message" % (filename, totalBytes*1.0/totalCount)