luis@970
|
1 # this script will get stats from the repo and print them to stdout
|
luis@970
|
2
|
luis@970
|
3 # USAGE:
|
luis@970
|
4
|
luis@970
|
5 # ./script/runner -e production extra/soundsoftware/get-statistics.rb
|
luis@970
|
6 #
|
luis@970
|
7
|
luis@970
|
8 d1 = Date.parse("20101201") # => 1 Dec 2010
|
luis@970
|
9 d2 = Date.today
|
luis@970
|
10
|
luis@970
|
11 def months_between(d1, d2)
|
luis@970
|
12 months = []
|
luis@970
|
13 start_date = Date.civil(d1.year, d1.month, 1)
|
luis@970
|
14 end_date = Date.civil(d2.year, d2.month, 1)
|
luis@970
|
15
|
luis@970
|
16 raise ArgumentError unless d1 <= d2
|
luis@970
|
17
|
luis@970
|
18 while (start_date < end_date)
|
luis@970
|
19 months << start_date
|
luis@970
|
20 start_date = start_date >>1
|
luis@970
|
21 end
|
luis@970
|
22
|
luis@970
|
23 months << end_date
|
luis@970
|
24 end
|
luis@970
|
25
|
luis@970
|
26 def weeks_between(d1, d2)
|
luis@970
|
27 weeks = []
|
luis@976
|
28 start_date = Date.civil(d1.year, d1.month, d1.day)
|
luis@976
|
29 end_date = Date.civil(d2.year, d2.month, d2.day)
|
luis@970
|
30
|
luis@970
|
31 raise ArgumentError unless d1 <= d2
|
luis@970
|
32
|
luis@970
|
33 while (start_date < end_date)
|
luis@970
|
34 weeks << start_date
|
luis@970
|
35 start_date = start_date + 1.week
|
luis@970
|
36 end
|
luis@970
|
37
|
luis@970
|
38 weeks << end_date
|
luis@970
|
39 end
|
luis@970
|
40
|
luis@970
|
41 # dates = months_between(d1, d2)
|
luis@970
|
42 dates = weeks_between(d1, d2)
|
luis@970
|
43
|
luis@970
|
44 dates.each do |date|
|
luis@973
|
45 users = User.find(:all, :conditions => {:created_on => d1..date})
|
luis@973
|
46 all_projects = Project.find(:all, :conditions => {:created_on => d1..date})
|
luis@973
|
47 private_projects = Project.find(:all, :conditions => {:created_on => d1..date,
|
luis@970
|
48 :is_public => false})
|
luis@973
|
49 top_level_and_private_projects = Project.find(:all, :conditions => {:created_on => d1..date,
|
luis@970
|
50 :is_public => false,
|
luis@970
|
51 :parent_id => nil})
|
luis@970
|
52
|
luis@973
|
53 puts "#{date} #{users.count} #{all_projects.count} #{private_projects.count} #{top_level_and_private_projects.count}\n"
|
luis@970
|
54
|
luis@970
|
55 end
|
luis@970
|
56
|
luis@970
|
57
|
luis@970
|
58
|
luis@970
|
59
|