public
anonymous / spark.py
Last active

  • Download Gist
spark.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
BARS = u'▁▂▃▅▆▇'
 
import sys
 
data = sys.argv[1:] or sys.stdin.read().split()
data = (x.strip() for x in data)
data = [float(x) for x in data if x]
incr = min(data)
width = max(data) / len(BARS)
 
bins = [i*width+incr for i in range(len(BARS))]
 
indexes = [i for n in data
for i, thres in enumerate(bins)
if thres <= n < thres+width]
 
print ''.join(BARS[i] for i in indexes)

What can I do if my terminal doesn't support unicode?

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.