Skip to content

Instantly share code, notes, and snippets.

@samanthamjohn
Last active August 29, 2015 14:13
Show Gist options
  • Save samanthamjohn/cbf48438a65022058760 to your computer and use it in GitHub Desktop.
Save samanthamjohn/cbf48438a65022058760 to your computer and use it in GitHub Desktop.
A script for finding what percentage of projects are liked/starred/etc
Category.all.each do |c|
has_been_played = c.projects.where("has_been_removed IS NOT TRUE AND play_count > 0").count
all_projects = c.projects.where("has_been_removed IS NOT TRUE").count
ratio = has_been_played.to_f/all_projects.to_f
puts "#{c.label} has #{ratio*100} percent played"
has_been_starred = c.projects.where("has_been_removed IS NOT TRUE AND stars_count > 0").count
ratio = has_been_starred.to_f/all_projects.to_f
puts "#{c.label} has #{ratio*100} percent starred"
has_been_remixed = c.projects.where("has_been_removed IS NOT TRUE AND project_remixes_count > 0").count
ratio = has_been_remixed.to_f/all_projects.to_f
puts "#{c.label} has #{ratio*100} percent remixed"
puts "=============================================================="
puts ""
end
def percent_projects_interacted_with_between(start_date_string, end_date_string)
query = "updated_at > ? AND updated_at < ? AND PUBLISHED IS TRUE AND has_been_removed IS NOT TRUE AND title NOT ILIKE '%level%'"
end_date = Date.parse("dec 17, 2014")
start_date = Date.parse("dec 8, 2014")
all_projects = Project.where(query, start_date, end_date).count
has_been_played = Project.where("#{query} AND play_count > 0", start_date, end_date).count
ratio = has_been_played.to_f/all_projects.to_f
puts "#{ratio * 100} percent of projects have been played"
has_been_remixed = Project.where("#{query} AND project_remixes_count > 0", start_date, end_date).count
ratio = has_been_remixed.to_f/all_projects.to_f
puts "#{ratio * 100} percent of projects have been remixed"
has_been_starred = Project.where("#{query} AND stars_count > 0", start_date, end_date).count
ratio = has_been_starred.to_f/all_projects.to_f
puts "#{ratio * 100} percent of projects have been starred"
end
percent_projects_interacted_with_between("dec 8, 2014", "dec 17, 2014")
@ashaegupta
Copy link

beautiful! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment