Forked from ashaegupta/gist:3417edaf4e72d255affb
Last active
August 29, 2015 14:09
-
-
Save samanthamjohn/2d854331eb8cec70d82d to your computer and use it in GitHub Desktop.
Finding number of projects that are levels
This file contains hidden or 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
def query_for_terms(terms) | |
query = "" | |
terms.each do |term| | |
query += "lower(substring(title from 0 for 30)) LIKE '%#{term}%' OR " | |
end | |
query.chomp("OR ") | |
end | |
def projects_arel(weeks_ago) | |
start_date = Time.now.beginning_of_week - 1.day - weeks_ago.weeks | |
end_date = start_date + 7.days | |
Project.where("updated_at > ? AND updated_at < ? AND PUBLISHED IS TRUE", start_date, end_date) | |
end | |
query = query_for_terms(["level", "done"]) | |
10.times.each do |time| | |
puts "#{time} weeks ago" | |
projects_count = projects_arel(time).count | |
levels_count = projects_arel(time).where(query).count | |
puts "projects count: #{projects_count} levels count: #{levels_count}" | |
puts "----------------------" | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment