Created
February 9, 2012 03:17
-
-
Save rjurney/1776974 to your computer and use it in GitHub Desktop.
Ugly as hell Ruby
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
get '/sent_distributions/:email' do |@email| | |
raw_data = mongo['sentdist'].find_one({:email => @email})['sent_dist'] | |
puts JSON raw_data | |
@data = (0..23).map do |hour| | |
key = to_key(hour) | |
puts "Key: |#{key}|" | |
value = Integer | |
index = raw_data.find_index{ |record| record['sent_hour'] == key } | |
if index | |
value = raw_data[index]['total'] | |
else | |
value = 0 | |
end | |
puts "{'sent_hour': #{key}, 'total': #{value}}" | |
{'sent_hour' => key, 'total' => value} | |
end | |
@json = JSON @data | |
puts @json | |
erb :'partials/distribution' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment