Mercurial > hg > soundsoftware-site
comparison app/helpers/activities_helper.rb @ 1011:f44860e089c5 browsing
Refactor into activities helper
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Mon, 12 Nov 2012 14:38:17 +0000 |
parents | |
children | b98f60a6d231 |
comparison
equal
deleted
inserted
replaced
1010:76a677c96bce | 1011:f44860e089c5 |
---|---|
1 | |
2 module ActivitiesHelper | |
3 | |
4 def busy_projects(events, count) | |
5 # Transform events list into hash from project id to number of | |
6 # occurrences of project in list (there is surely a tidier way | |
7 # to do this, e.g. chunk() in Ruby 1.9 but not in 1.8) | |
8 phash = events.map { |e| e.project unless !e.respond_to?(:project) }.sort.group_by { |p| p.id } | |
9 phash = phash.merge(phash) { |k,v| v.length } | |
10 threshold = phash.values.sort.last(count).first | |
11 busy = phash.keys.select { |k| phash[k] >= threshold }.sample(count) | |
12 busy.map { |pid| Project.find(pid) } | |
13 end | |
14 | |
15 def busy_institutions(events, count) | |
16 authors = events.map { |e| e.event_author unless !e.respond_to?(:event_author) }.compact | |
17 institutions = authors.map { |a| a.ssamr_user_detail.institution_name } | |
18 insthash = institutions.compact.sort.group_by { |i| i } | |
19 insthash = insthash.merge(insthash) { |k,v| v.length } | |
20 threshold = insthash.values.sort.last(count).first | |
21 insthash.keys.select { |k| insthash[k] >= threshold }.sample(count) | |
22 end | |
23 | |
24 end |