Created
March 9, 2015 17:55
-
-
Save pop/b6472d96a0036a1d6bf7 to your computer and use it in GitHub Desktop.
huRandom Tools
This file contains 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/python | |
# This compensates for troll data in which a user decides to enter the same value a few, possibly one hundred, | |
# times to hurandom.elijahciane.me | |
import pygal | |
from pygal.style import CleanStyle | |
data = [-100000, -100, -100, 0, 0.4919173444481295, 1, 1, 1, 2, 3, 4, 4, 5, 5, 6, 7, 8, 8, 9, 9, 10, 12, 13, 13, 13, 14, 18, 20, 20, 22, 22, 22, 22, 23, 25, 29, 32, 32, 37, 37, 37, 37, 40, 42, 42, 42, 42, 42, 42, 43, 55, 64, 65, 67, 67, 71, 76, 79, 82, 97.00027461847252, 123, 137, 164, 337, 337.2346435765485, 365, 437, 456, 558, 632, 658, 666, 789, 1764, 3466, 3788, 3857, 4550, 5672, 5761, 9586, 10021, 12334, 12789, 12789, 12921, 35614, 44307, 86372, 98776, 114413, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135484, 135485, 135486, 135489, 135490, 135490, 135490, 135490, 135490, 135490, 141928, 233500, 259152, 325756, 345235, 422749, 684613, 696969, 764509] | |
print('\nData: ' + str(data)) | |
new_data = list() | |
for i in range(1, len(data)-1): | |
if data[i-1] != data[i+1]: | |
new_data.append(data[i]) | |
print('\nNew Data: ' + str(new_data)) | |
def graph_data(data): | |
""" | |
Generates histogram of data for user | |
""" | |
graph_data, axis , n= compile_data(data) | |
chart = pygal.Bar(fill=True, | |
interpolate='cubic', | |
style=CleanStyle, | |
no_data_text=str(n) + ' more entries needed for graphing.', | |
title_font_size=30, | |
show_legend=False, | |
x_title='Range', | |
y_title='Frequency', | |
label_font_size=12.5, | |
x_label_rotation=30, | |
title="'Random' Numbers", | |
x_labels=axis, | |
no_data_font_size=30) | |
chart.add('Data', graph_data) | |
chart.render_to_file('bar_chart.svg') | |
def compile_data(data): | |
""" | |
Compiles data for graphing | |
Splits the data evenly into #bin_num of 'bins' which store the frequency of | |
number occurences within each range. | |
Breaks if you enter a number that is magnitudes larger than the rest of | |
the data. | |
""" | |
bin_num = 20 | |
bin_range = int((max(data) - min(data)) / bin_num)+1 | |
output = [0 for i in range(bin_num)] | |
axis = ['-' for i in range(bin_num)] | |
n = bin_num - len(data) | |
# Purely debigging information | |
#print('Number of Bins: ' + str(bin_num) +\ | |
# ' | range for each bin: ' + str(bin_range) +\ | |
# ' | min value: ' + str(min(data)) +\ | |
# ' | max value: ' + str(max(data)) +\ | |
# ' | number of values: ' + str(len(data)) +\ | |
# ' | list of data: ' + str(data)) | |
if len(data) >= bin_num: | |
for i in range(bin_num): | |
axis[i] = str(bin_range*i+min(data)) | |
for j in range(len(data)): | |
if bin_range*i+min(data) <= data[j] and data[j] < bin_range*(i+1)+min(data): | |
output[i] += 1 | |
axis[i] += " to " + str(bin_range*(i+1)+min(data)) | |
return(output, axis, n) | |
graph_data(new_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment