| 5 |
5 |
# ./script/runner -e production extra/soundsoftware/get-statistics.rb
|
| 6 |
6 |
#
|
| 7 |
7 |
|
| 8 |
|
d1 = Date.parse("20101201") # => 1 Dec 2010
|
|
8 |
d1 = Date.parse("20100701") # => 1 Jul 2010
|
| 9 |
9 |
d2 = Date.today
|
| 10 |
10 |
|
|
11 |
def delta_array (iarray)
|
|
12 |
# returns an array with the deltas
|
|
13 |
## prepends a zero and drops the last element
|
|
14 |
deltas = [0] + iarray
|
|
15 |
deltas = deltas.first(deltas.size - 1)
|
|
16 |
|
|
17 |
return iarray.zip(deltas).map { |x, y| x - y }
|
|
18 |
|
|
19 |
end
|
|
20 |
|
| 11 |
21 |
def months_between(d1, d2)
|
| 12 |
22 |
months = []
|
| 13 |
23 |
start_date = Date.civil(d1.year, d1.month, 1)
|
| ... | ... | |
| 32 |
42 |
|
| 33 |
43 |
while (start_date < end_date)
|
| 34 |
44 |
weeks << start_date
|
| 35 |
|
start_date = start_date + 1.week
|
|
45 |
start_date = start_date + 2.week
|
| 36 |
46 |
end
|
| 37 |
47 |
|
| 38 |
48 |
weeks << end_date
|
| 39 |
49 |
end
|
| 40 |
50 |
|
| 41 |
|
# dates = months_between(d1, d2)
|
| 42 |
|
dates = weeks_between(d1, d2)
|
|
51 |
def get_user_project_evol_stats()
|
|
52 |
# dates = months_between(d1, d2)
|
|
53 |
dates = months_between(d1, d2)
|
|
54 |
|
|
55 |
# number of users
|
|
56 |
n_users = []
|
|
57 |
n_projects = []
|
|
58 |
qm_users = []
|
|
59 |
|
|
60 |
dates.each do |date|
|
|
61 |
users = User.find_by_sql ["SELECT * FROM users WHERE users.status = '1' AND users.created_on <= ?;", date]
|
|
62 |
projects = Project.find_by_sql ["SELECT * FROM projects WHERE projects.created_on <= ?;", date]
|
|
63 |
|
|
64 |
qm_users_list = User.find_by_sql ["SELECT * FROM users,ssamr_user_details WHERE users.status = '1' AND ssamr_user_details.user_id = users.id AND (users.mail like '%qmul%' OR ssamr_user_details.institution_id = '99') AND users.created_on <= ?;", date ]
|
|
65 |
|
|
66 |
qm_users << qm_users_list.count
|
|
67 |
n_users << users.count
|
|
68 |
n_projects << projects.count
|
|
69 |
|
|
70 |
# private_projects = Project.find(:all, :conditions => {:created_on => d1..date, is_public => false})
|
|
71 |
end
|
|
72 |
|
|
73 |
user_deltas = delta_array(n_users)
|
|
74 |
proj_deltas = delta_array(n_projects)
|
|
75 |
qm_user_deltas = delta_array(qm_users)
|
|
76 |
|
|
77 |
puts "Date Users D_Users QM_Users D_QM_users Projects D_Projects"
|
|
78 |
|
|
79 |
dates.zip(n_users, user_deltas, qm_users, qm_user_deltas, n_projects, proj_deltas).each do |a, b, c, d, e, f, g|
|
|
80 |
puts "#{a} #{b} #{c} #{d} #{e} #{f} #{g}"
|
|
81 |
end
|
|
82 |
|
|
83 |
end
|
| 43 |
84 |
|
| 44 |
|
dates.each do |date|
|
| 45 |
|
users = User.find(:all, :conditions => {:created_on => d1..date})
|
| 46 |
|
all_projects = Project.find(:all, :conditions => {:created_on => d1..date})
|
| 47 |
|
private_projects = Project.find(:all, :conditions => {:created_on => d1..date,
|
| 48 |
|
:is_public => false})
|
| 49 |
|
top_level_and_private_projects = Project.find(:all, :conditions => {:created_on => d1..date,
|
| 50 |
|
:is_public => false,
|
| 51 |
|
:parent_id => nil})
|
| 52 |
85 |
|
| 53 |
|
puts "#{date} #{users.count} #{all_projects.count} #{private_projects.count} #{top_level_and_private_projects.count}\n"
|
|
86 |
def get_project_status()
|
|
87 |
date = "20121101"
|
|
88 |
|
|
89 |
all_projects = Project.find(:all, :conditions => ["created_on < ?", date])
|
|
90 |
# all_projects = Project.find(:all, :conditions => ["is_public = ? AND created_on < ?", true, date])
|
|
91 |
# all_projects = Project.find(:all, :conditions => ["is_public = ? AND created_on < ?", false, date])
|
|
92 |
|
|
93 |
collab = []
|
|
94 |
users_per_proj = []
|
|
95 |
|
|
96 |
# puts "Public Users Institutions"
|
|
97 |
|
|
98 |
all_projects.each do |proj|
|
|
99 |
insts = []
|
|
100 |
|
|
101 |
proj.users.each do |u|
|
|
102 |
if u.institution == "" || u.institution == "No Institution Set"
|
|
103 |
if u.mail.include?("qmul.ac.uk") || u.mail.include?("andrewrobertson77")
|
|
104 |
insts << "Queen Mary, University of London"
|
|
105 |
else
|
|
106 |
insts << u.mail
|
|
107 |
end
|
|
108 |
else
|
|
109 |
insts << u.institution
|
|
110 |
end
|
|
111 |
end
|
|
112 |
|
|
113 |
users_per_proj << proj.users.count
|
|
114 |
collab << insts.uniq.count
|
|
115 |
end
|
|
116 |
|
|
117 |
|
|
118 |
# freq = collab.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
|
|
119 |
# freq = freq.sort_by {|key, value| value}
|
|
120 |
# puts freq.inspect.sort
|
|
121 |
|
|
122 |
puts "Projects: #{all_projects.count} UpP: #{users_per_proj.sum / users_per_proj.size.to_f} Users1+: #{users_per_proj.count{|x| x> 1}} Users2+: #{users_per_proj.count{|x| x> 2}} Collab1+: #{collab.count{|x| x > 1}} Collab2+: #{collab.count{|x| x > 2}} IpP: #{collab.sum / collab.size.to_f}"
|
|
123 |
end
|
|
124 |
|
|
125 |
def get_user_projects_ratios()
|
|
126 |
user_projects = User.find(:all, :conditions=> {:status => 1})
|
|
127 |
pub_proj_user = user_projects.map{|u| u.projects.find(:all, :conditions=>{:is_public => true}).count}
|
|
128 |
|
|
129 |
user_projects.zip(pub_proj_user).each do |u, pub|
|
|
130 |
puts "#{u.projects.count} #{pub}"
|
|
131 |
end
|
| 54 |
132 |
|
| 55 |
133 |
end
|
| 56 |
134 |
|
|
135 |
def get_inst_list()
|
|
136 |
users = User.find(:all, :conditions => {:status => 1})
|
|
137 |
inst_list = users.map{|user| user.institution}
|
|
138 |
|
|
139 |
freq = inst_list.inject(Hash.new(0)) { |h,v| h[v] += 1; h }
|
|
140 |
|
|
141 |
end
|
| 57 |
142 |
|
| 58 |
143 |
|
|
144 |
# get_user_projects_ratios()
|
|
145 |
# get_user_project_evol_stats()
|
| 59 |
146 |
|
|
147 |
get_project_status()
|