Revision 1011:f44860e089c5

View differences:

app/controllers/projects_controller.rb
43 43
  helper :repositories
44 44
  include RepositoriesHelper
45 45
  include ProjectsHelper
46
  include ActivitiesHelper
47
  helper :activities
46 48

  
47 49
  # Lists visible projects. Paginator is for top-level projects only
48 50
  # (subprojects belong to them)
app/helpers/activities_helper.rb
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
app/views/activities/_busy.html.erb
1 1
<% events = @events_by_day %>
2
<% max = 5 %>
3 2
<% if (events.nil?) 
4 3
     activity = Redmine::Activity::Fetcher.new(User.current)
5 4
     events = activity.events(Date.today - 14, Date.today + 1)
......
13 12
   <ul>
14 13

  
15 14
   <% 
16
      # Transform events list into hash from project id to number of
17
      # occurrences of project in list (there is surely a tidier way
18
      # to do this, e.g. chunk() in Ruby 1.9 but not in 1.8)
19
      phash = events.map { |e| e.project unless !e.respond_to?(:project) }.sort.group_by { |p| p.id }
20
      phash = phash.merge(phash) { |k,v| v.length }
21
      threshold = phash.values.sort.last(max).first
22
      busy = phash.keys.select { |k| phash[k] >= threshold }.sample(max)
23

  
24
      for id in busy
25
        project = Project.find(id)
15
      for project in busy_projects(events, 5)
26 16
   %>
27 17

  
28 18
   <li class="busy">
app/views/activities/_busy_institution.html.erb
1 1
<% events = @events_by_day %>
2
<% max = 5 %>
3 2
<% if (events.nil?) 
4 3
     activity = Redmine::Activity::Fetcher.new(User.current)
5 4
     events = activity.events(Date.today - 14, Date.today + 1)
......
13 12
   <ul>
14 13

  
15 14
   <% 
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(max).first
21
      busy = insthash.keys.select { |k| insthash[k] >= threshold }.sample(max)
22

  
23
      for institution in busy
15
      for institution in busy_institutions(events, 5)
24 16
   %>
25 17

  
26 18
   <li class="busy">

Also available in: Unified diff