Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch some bugs in histogram.py #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions data_hacks/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ def load_stream(input_stream, agg_value_key, agg_key_value):
yield DataPoint(Decimal(clean_line), 1)
except:
logging.exception('failed %r', line)
print >>sys.stderr, "invalid line %r" % line
print(sys.stderr, "invalid line %r" % line)


def median(values, key=None):
if not key:
key = None # map and sort accept None as identity
length = len(values)
if length % 2:
median_indeces = [length/2]
if length % 2 == 0:
median_indeces = [length//2]
else:
median_indeces = [length/2-1, length/2]
median_indeces = [length//2-1, length//2]

values = sorted(values, key=key)
return sum(map(key,
Expand Down Expand Up @@ -241,7 +241,7 @@ def log_steps(k, n):
print("# Mean = %f; Variance = %f; SD = %f; Median %f" %
(mvsd.mean(), mvsd.var(), mvsd.sd(),
median(accepted_data, key=lambda x: x.value)))
print "# each " + options.dot + " represents a count of %d" % bucket_scale
print("# each " + options.dot + " represents a count of %d" % bucket_scale)
bucket_min = min_v
bucket_max = min_v
percentage = ""
Expand All @@ -252,12 +252,12 @@ def log_steps(k, n):
bucket_count = bucket_counts[bucket]
star_count = 0
if bucket_count:
star_count = bucket_count / bucket_scale
star_count = bucket_count // bucket_scale
if options.percentage:
percentage = " (%0.2f%%)" % (100 * Decimal(bucket_count) /
Decimal(samples))
print format_string % (bucket_min, bucket_max, bucket_count, options.dot *
star_count, percentage)
print(format_string % (bucket_min, bucket_max, bucket_count, options.dot *
star_count, percentage))


if __name__ == "__main__":
Expand Down Expand Up @@ -294,7 +294,7 @@ def log_steps(k, n):
if sys.stdin.isatty():
# if isatty() that means it's run without anything piped into it
parser.print_usage()
print "for more help use --help"
print("for more help use --help")
sys.exit(1)
histogram(load_stream(sys.stdin, options.agg_value_key,
options.agg_key_value), options)