To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / extra / soundsoftware / get-statistics.rb @ 1450:020bc7fe7a2a
History | View | Annotate | Download (4.16 KB)
| 1 |
# this script will get stats from the repo and print them to stdout
|
|---|---|
| 2 |
|
| 3 |
# USAGE:
|
| 4 |
|
| 5 |
# ./script/runner -e production extra/soundsoftware/get-statistics.rb
|
| 6 |
#
|
| 7 |
|
| 8 |
d1 = Date.parse("20100701") # => 1 Jul 2010 |
| 9 |
d2 = Date.today
|
| 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 |
|
| 21 |
def months_between(d1, d2) |
| 22 |
months = [] |
| 23 |
start_date = Date.civil(d1.year, d1.month, 1) |
| 24 |
end_date = Date.civil(d2.year, d2.month, 1) |
| 25 |
|
| 26 |
raise ArgumentError unless d1 <= d2 |
| 27 |
|
| 28 |
while (start_date < end_date)
|
| 29 |
months << start_date |
| 30 |
start_date = start_date >>1
|
| 31 |
end
|
| 32 |
|
| 33 |
months << end_date |
| 34 |
end
|
| 35 |
|
| 36 |
def weeks_between(d1, d2) |
| 37 |
weeks = [] |
| 38 |
start_date = Date.civil(d1.year, d1.month, d1.day)
|
| 39 |
end_date = Date.civil(d2.year, d2.month, d2.day)
|
| 40 |
|
| 41 |
raise ArgumentError unless d1 <= d2 |
| 42 |
|
| 43 |
while (start_date < end_date)
|
| 44 |
weeks << start_date |
| 45 |
start_date = start_date + 2.week
|
| 46 |
end
|
| 47 |
|
| 48 |
weeks << end_date |
| 49 |
end
|
| 50 |
|
| 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
|
| 84 |
|
| 85 |
|
| 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
|
| 132 |
|
| 133 |
end
|
| 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
|
| 142 |
|
| 143 |
|
| 144 |
# get_user_projects_ratios()
|
| 145 |
# get_user_project_evol_stats()
|
| 146 |
|
| 147 |
get_project_status() |