Mercurial > hg > soundsoftware-site
comparison app/helpers/projects_helper.rb @ 1501:467282ce64a4 cannam
Add varied-mature-projects Featured box
author | Chris Cannam |
---|---|
date | Fri, 21 Mar 2014 13:03:27 +0000 |
parents | 16826c3afbba |
children | 523f55b47b98 |
comparison
equal
deleted
inserted
replaced
1491:cb53cb6eeaef | 1501:467282ce64a4 |
---|---|
276 then project.publications.count else 0 end | 276 then project.publications.count else 0 end |
277 Math.log(1 + nr_changes) + | 277 Math.log(1 + nr_changes) + |
278 Math.log(1 + nr_downloadables) + | 278 Math.log(1 + nr_downloadables) + |
279 Math.log(1 + nr_downloads) + | 279 Math.log(1 + nr_downloads) + |
280 Math.sqrt(nr_members > 1 ? (nr_members - 1) : 0) + | 280 Math.sqrt(nr_members > 1 ? (nr_members - 1) : 0) + |
281 Math.sqrt(nr_publications) | 281 Math.sqrt(nr_publications * 2) |
282 end | 282 end |
283 | 283 |
284 def all_maturity_scores() | 284 def all_maturity_scores() |
285 phash = Hash.new | 285 phash = Hash.new |
286 pp = Project.visible(User.anonymous) | 286 pp = Project.visible(User.anonymous) |
287 pp.each do |p| | |
288 phash[p] = score_maturity p | |
289 end | |
290 phash | |
291 end | |
292 | |
293 def top_level_maturity_scores() | |
294 phash = Hash.new | |
295 pp = Project.root_visible_by(User.anonymous) | |
287 pp.each do |p| | 296 pp.each do |p| |
288 phash[p] = score_maturity p | 297 phash[p] = score_maturity p |
289 end | 298 end |
290 phash | 299 phash |
291 end | 300 end |
295 scores = phash.values.sort | 304 scores = phash.values.sort |
296 threshold = scores[scores.length / 2] | 305 threshold = scores[scores.length / 2] |
297 if threshold == 0 then threshold = 1 end | 306 if threshold == 0 then threshold = 1 end |
298 phash.keys.select { |k| phash[k] > threshold }.sample(count) | 307 phash.keys.select { |k| phash[k] > threshold }.sample(count) |
299 end | 308 end |
309 | |
310 def varied_mature_projects(count) | |
311 phash = top_level_maturity_scores | |
312 scores = phash.values.sort | |
313 threshold = scores[scores.length / 2] | |
314 if threshold == 0 then threshold = 1 end | |
315 uhash = Hash.new | |
316 phash.keys.select do |k| | |
317 if phash[k] < threshold or k.description == "" then | |
318 false | |
319 else | |
320 uu = k.users | |
321 novel = (uhash.keys & uu).empty? | |
322 uu.each { |u| uhash[u] = 1 } | |
323 novel | |
324 end | |
325 end.sample(count) | |
326 end | |
327 | |
300 end | 328 end |