Skip to content

Instantly share code, notes, and snippets.

@rjurney
Created February 9, 2012 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjurney/1776974 to your computer and use it in GitHub Desktop.
Save rjurney/1776974 to your computer and use it in GitHub Desktop.
Ugly as hell Ruby
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