Mercurial > hg > soundsoftware-site
annotate app/helpers/activities_helper.rb @ 1469:c77ab1edff6b bug_563
Close obsolete branch bug_563
author | Chris Cannam |
---|---|
date | Wed, 23 Jan 2013 14:12:47 +0000 |
parents | 4d1a31b30987 |
children | e19f375f9afa |
rev | line source |
---|---|
chris@1011 | 1 |
chris@1011 | 2 module ActivitiesHelper |
chris@1011 | 3 |
chris@1011 | 4 def busy_projects(events, count) |
chris@1011 | 5 # Transform events list into hash from project id to number of |
chris@1011 | 6 # occurrences of project in list (there is surely a tidier way |
chris@1011 | 7 # to do this, e.g. chunk() in Ruby 1.9 but not in 1.8) |
chris@1168 | 8 phash = events.map do |e| |
chris@1168 | 9 e.project unless !e.respond_to?(:project) |
chris@1168 | 10 end.select { |p| !p.nil? }.sort.group_by { |p| p.id } |
chris@1011 | 11 phash = phash.merge(phash) { |k,v| v.length } |
chris@1011 | 12 threshold = phash.values.sort.last(count).first |
chris@1011 | 13 busy = phash.keys.select { |k| phash[k] >= threshold }.sample(count) |
chris@1011 | 14 busy.map { |pid| Project.find(pid) } |
chris@1011 | 15 end |
chris@1011 | 16 |
chris@1011 | 17 def busy_institutions(events, count) |
Chris@1013 | 18 authors = events.map do |e| |
Chris@1013 | 19 e.event_author unless !e.respond_to?(:event_author) |
Chris@1013 | 20 end.compact |
Chris@1013 | 21 institutions = authors.map do |a| |
Chris@1013 | 22 if a.respond_to?(:ssamr_user_detail) and !a.ssamr_user_detail.nil? |
Chris@1013 | 23 a.ssamr_user_detail.institution_name |
Chris@1013 | 24 end |
Chris@1013 | 25 end |
chris@1011 | 26 insthash = institutions.compact.sort.group_by { |i| i } |
chris@1011 | 27 insthash = insthash.merge(insthash) { |k,v| v.length } |
chris@1011 | 28 threshold = insthash.values.sort.last(count).first |
chris@1011 | 29 insthash.keys.select { |k| insthash[k] >= threshold }.sample(count) |
chris@1011 | 30 end |
chris@1011 | 31 |
chris@1011 | 32 end |