63
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 """
|
|
5
|
|
6 Unicode is awesome; see http://www.alanwood.net/unicode/block_elements.html
|
|
7 """
|
|
8
|
|
9 blocks = """
|
|
10 █
|
|
11 ▉
|
|
12 ▊
|
|
13 ▋
|
|
14 ▌
|
|
15 ▍
|
|
16 ▎
|
|
17 ▏
|
|
18 """
|
|
19
|
|
20 # imports
|
|
21 import argparse
|
|
22 import os
|
|
23 import sys
|
|
24 import time
|
|
25 from .read import CSVParser
|
64
|
26 from collections import OrderedDict
|
63
|
27
|
|
28 # module globals
|
64
|
29 __all__ = ['Histogram', 'HistogramParser', 'main']
|
|
30
|
|
31 class Histogram(object):
|
|
32 """historgram"""
|
63
|
33
|
64
|
34 def __init__(self, bins):
|
|
35 bins = sorted(bin)
|
|
36 assert len(bins) > 1
|
|
37 self.histogram = self.OrderedDict(zip(bins[:-1],
|
|
38 bins[1:]))
|
|
39
|
65
|
40 def __iadd__(self, value):
|
|
41 return self
|
|
42
|
64
|
43 class HistogramParser(CSVParser):
|
63
|
44 """histogram CLI option parser"""
|
|
45
|
|
46 def __init__(self, **kwargs):
|
|
47 kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter)
|
|
48 kwargs.setdefault('description', __doc__)
|
64
|
49 CSVParser..__init__(self, **kwargs)
|
63
|
50 self.add_argument('-n', '--bins', dest='n_bins', type=int,
|
|
51 help="number of bins")
|
|
52 self.options = None
|
|
53
|
|
54
|
|
55 def main(args=sys.argv[1:]):
|
|
56 """CLI"""
|
|
57
|
|
58 # parse command line options
|
|
59 parser = HistogramParser()
|
|
60 options = parser.parse_args(args)
|
|
61
|
|
62
|
|
63 if __name__ == '__main__':
|
|
64 main()
|
|
65
|
|
66
|