To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / helpers / activities_helper.rb @ 1078:b9e34a051f82
History | View | Annotate | Download (1.13 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 | 1013:b98f60a6d231 | Chris | authors = events.map do |e|
|
| 17 | e.event_author unless !e.respond_to?(:event_author) |
||
| 18 | end.compact
|
||
| 19 | institutions = authors.map do |a|
|
||
| 20 | if a.respond_to?(:ssamr_user_detail) and !a.ssamr_user_detail.nil? |
||
| 21 | a.ssamr_user_detail.institution_name |
||
| 22 | end
|
||
| 23 | end
|
||
| 24 | 1011:f44860e089c5 | chris | insthash = institutions.compact.sort.group_by { |i| i }
|
| 25 | insthash = insthash.merge(insthash) { |k,v| v.length }
|
||
| 26 | threshold = insthash.values.sort.last(count).first |
||
| 27 | insthash.keys.select { |k| insthash[k] >= threshold }.sample(count)
|
||
| 28 | end
|
||
| 29 | |||
| 30 | end |