Mercurial > hg > soundsoftware-site
diff app/helpers/projects_helper.rb @ 1519:afce8026aaeb redmine-2.4-integration
Merge from branch "live"
author | Chris Cannam |
---|---|
date | Tue, 09 Sep 2014 09:34:53 +0100 |
parents | c86dacc2ef0a 9f37f7e39d3c |
children | a1bdbf8a87d5 |
line wrap: on
line diff
--- a/app/helpers/projects_helper.rb Tue Sep 09 09:32:11 2014 +0100 +++ b/app/helpers/projects_helper.rb Tue Sep 09 09:34:53 2014 +0100 @@ -279,7 +279,7 @@ Math.log(1 + nr_downloadables) + Math.log(1 + nr_downloads) + Math.sqrt(nr_members > 1 ? (nr_members - 1) : 0) + - Math.sqrt(nr_publications) + Math.sqrt(nr_publications * 2) end def all_maturity_scores() @@ -291,6 +291,15 @@ phash end + def top_level_maturity_scores() + phash = Hash.new + pp = Project.visible_roots(User.anonymous) + pp.each do |p| + phash[p] = score_maturity p + end + phash + end + def mature_projects(count) phash = all_maturity_scores scores = phash.values.sort @@ -298,4 +307,29 @@ if threshold == 0 then threshold = 1 end phash.keys.select { |k| phash[k] > threshold }.sample(count) end + + def varied_mature_projects(count) + phash = top_level_maturity_scores + scores = phash.values.sort + threshold = scores[scores.length / 2] + if threshold == 0 then threshold = 1 end + mhash = Hash.new + phash.keys.shuffle.select do |k| + if phash[k] < threshold or k.description == "" then + false + else + u = k.users_by_role + mgrs = [] + u.keys.each do |r| + if r.allowed_to?(:edit_project) + u[r].each { |m| mgrs << m } + end + end + novel = (mhash.keys & mgrs).empty? + mgrs.each { |m| mhash[m] = 1 } + novel and not mgrs.empty? + end + end.sample(count) + end + end