Created
December 21, 2011 01:11
-
-
Save jraines/1504084 to your computer and use it in GitHub Desktop.
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
# Hash for each brand. | |
# Each key is an item of that brand, in a format like 'id:type:name'. | |
# Each value is a json string representing an array of user ids. | |
# For this query we would: | |
# iterate over each brand | |
# pull the the keys that match our type ('*jeans*') and | |
# get the user ids array for each brand of jeans. | |
# Then something like this, where "brand" in this case is a constructed object | |
# from the above operation, with name and user_id_array_for_jeans: | |
results = {} | |
brands.each do |b| | |
jean_wearers = b.user_id_array_for_jeans | |
results[brand.name] = User.where(:id => jean_wearers).where(demographic_conditions).count | |
end | |
results.sort_by {|brand, count| count} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment