luis@970: # this script will get stats from the repo and print them to stdout luis@970: luis@970: # USAGE: luis@970: luis@970: # ./script/runner -e production extra/soundsoftware/get-statistics.rb luis@970: # luis@970: luis@970: d1 = Date.parse("20101201") # => 1 Dec 2010 luis@970: d2 = Date.today luis@970: luis@970: def months_between(d1, d2) luis@970: months = [] luis@970: start_date = Date.civil(d1.year, d1.month, 1) luis@970: end_date = Date.civil(d2.year, d2.month, 1) luis@970: luis@970: raise ArgumentError unless d1 <= d2 luis@970: luis@970: while (start_date < end_date) luis@970: months << start_date luis@970: start_date = start_date >>1 luis@970: end luis@970: luis@970: months << end_date luis@970: end luis@970: luis@970: def weeks_between(d1, d2) luis@970: weeks = [] luis@976: start_date = Date.civil(d1.year, d1.month, d1.day) luis@976: end_date = Date.civil(d2.year, d2.month, d2.day) luis@970: luis@970: raise ArgumentError unless d1 <= d2 luis@970: luis@970: while (start_date < end_date) luis@970: weeks << start_date luis@970: start_date = start_date + 1.week luis@970: end luis@970: luis@970: weeks << end_date luis@970: end luis@970: luis@970: # dates = months_between(d1, d2) luis@970: dates = weeks_between(d1, d2) luis@970: luis@970: dates.each do |date| luis@973: users = User.find(:all, :conditions => {:created_on => d1..date}) luis@973: all_projects = Project.find(:all, :conditions => {:created_on => d1..date}) luis@973: private_projects = Project.find(:all, :conditions => {:created_on => d1..date, luis@970: :is_public => false}) luis@973: top_level_and_private_projects = Project.find(:all, :conditions => {:created_on => d1..date, luis@970: :is_public => false, luis@970: :parent_id => nil}) luis@970: luis@973: puts "#{date} #{users.count} #{all_projects.count} #{private_projects.count} #{top_level_and_private_projects.count}\n" luis@970: luis@970: end luis@970: luis@970: luis@970: luis@970: