Mercurial > hg > soundsoftware-site
comparison app/helpers/projects_helper.rb @ 1209:1b1138f6f55e
Merge from branch live
author | Chris Cannam |
---|---|
date | Wed, 23 Jan 2013 13:11:25 +0000 |
parents | 6676c0284df2 |
children | 16826c3afbba |
comparison
equal
deleted
inserted
replaced
1078:b9e34a051f82 | 1209:1b1138f6f55e |
---|---|
267 | 267 |
268 def format_version_sharing(sharing) | 268 def format_version_sharing(sharing) |
269 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) | 269 sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
270 l("label_version_sharing_#{sharing}") | 270 l("label_version_sharing_#{sharing}") |
271 end | 271 end |
272 | |
273 def score_maturity(project) | |
274 nr_changes = (project.repository.nil? ? 0 : project.repository.changesets.count) | |
275 downloadables = [project.attachments, | |
276 project.versions.collect { |v| v.attachments }, | |
277 project.documents.collect { |d| d.attachments }].flatten | |
278 nr_downloadables = downloadables.count | |
279 nr_downloads = downloadables.map do |d| d.downloads end.sum | |
280 nr_members = project.members.count | |
281 nr_publications = if project.respond_to? :publications | |
282 then project.publications.count else 0 end | |
283 Math.log(1 + nr_changes) + | |
284 Math.log(1 + nr_downloadables) + | |
285 Math.log(1 + nr_downloads) + | |
286 Math.sqrt(nr_members > 1 ? (nr_members - 1) : 0) + | |
287 Math.sqrt(nr_publications) | |
288 end | |
289 | |
290 def all_maturity_scores() | |
291 phash = Hash.new | |
292 pp = Project.visible(User.anonymous) | |
293 pp.each do |p| | |
294 phash[p] = score_maturity p | |
295 end | |
296 phash | |
297 end | |
298 | |
299 def mature_projects(count) | |
300 phash = all_maturity_scores | |
301 scores = phash.values.sort | |
302 threshold = scores[scores.length / 2] | |
303 if threshold == 0 then threshold = 1 end | |
304 phash.keys.select { |k| phash[k] > threshold }.sample(count) | |
305 end | |
272 end | 306 end |