Mercurial > hg > soundsoftware-site
comparison app/helpers/activities_helper.rb @ 1217:875b5b4c574d cannam
Add "People I'm working with" as My Page box -- currently off by default
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Tue, 12 Mar 2013 13:01:36 +0000 |
parents | adb5f38f6ab7 |
children | 3286032e15cf |
comparison
equal
deleted
inserted
replaced
1216:05ce7de07fef | 1217:875b5b4c574d |
---|---|
13 else | 13 else |
14 nil | 14 nil |
15 end | 15 end |
16 end | 16 end |
17 | 17 |
18 def busy_projects(events, count) | 18 def project_activity_on_events(events) |
19 | 19 |
20 # Score each project for which there are any events, by giving | 20 # Score each project for which there are any events, by giving |
21 # each event a score based on how long ago it was (the more recent | 21 # each event a score based on how long ago it was (the more recent |
22 # the better). | 22 # the better). Return a hash mapping project id to score. |
23 | 23 |
24 projhash = Hash.new | 24 projhash = Hash.new |
25 | 25 |
26 events.each do |e| | 26 events.each do |e| |
27 if e.respond_to?(:project) | 27 if e.respond_to?(:project) |
37 projhash[p] = score | 37 projhash[p] = score |
38 end | 38 end |
39 end | 39 end |
40 end | 40 end |
41 end | 41 end |
42 | |
43 projhash | |
44 end | |
45 | |
46 def projects_by_activity(user, count) | |
47 | |
48 # Return up to count of the user's projects ordered by that user's | |
49 # recent activity, omitting any projects for which no activity | |
50 # occurred in the recent past | |
51 | |
52 activity = Redmine::Activity::Fetcher.new(user, :author => user) | |
53 days = Setting.activity_days_default.to_i | |
54 events = activity.events(Date.today - days, Date.today + 1) | |
55 projhash = project_activity_on_events(events) | |
56 projhash.keys.sort_by { |k| -projhash[k] }.first(count) | |
57 end | |
58 | |
59 def render_active_colleagues(colleagues) | |
60 | |
61 s = "" | |
62 | |
63 for c in colleagues | |
64 u = User.find_by_id(c) | |
65 active_projects = projects_by_activity(u, 3) | |
66 if !active_projects.empty? | |
67 s << "<div class='user'>" | |
68 s << link_to_user(u) | |
69 s << "<span class='institution'>" | |
70 s << h(u.ssamr_user_detail.institution_name) | |
71 s << "</span>" | |
72 s << "</div>" | |
73 s << "<div class='active'>" | |
74 s << l(:label_working_in) << " " | |
75 s << (active_projects.map { |p| link_to_project(p) }.join ", ") | |
76 s << "</div>" | |
77 end | |
78 end | |
79 | |
80 if s != "" | |
81 s | |
82 else | |
83 l(:label_no_active_colleagues) | |
84 end | |
85 end | |
86 | |
87 def busy_projects(events, count) | |
88 | |
89 # Return a list of count projects randomly selected from amongst | |
90 # the busiest projects represented by the given activity events | |
91 | |
92 projhash = project_activity_on_events(events) | |
42 | 93 |
43 # pick N highest values and use cutoff value as selection threshold | 94 # pick N highest values and use cutoff value as selection threshold |
44 threshold = projhash.values.sort.last(count).first | 95 threshold = projhash.values.sort.last(count).first |
45 | 96 |
46 # select projects above threshold and pick N from them randomly | 97 # select projects above threshold and pick N from them randomly |