Created
November 15, 2011 21:41
-
-
Save rogerallen/1368454 to your computer and use it in GitHub Desktop.
spark in python inspired by http://news.ycombinator.com/item?id=3237478 and https://gist.github.com/1366875
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env 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) - min(data)) / (len(BARS) - 1) | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment