To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / activities_helper.rb @ 1012:bbca6f4eebc7

History | View | Annotate | Download (1.02 KB)

1 1011:f44860e089c5 chris
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