# HG changeset patch # User Chris Cannam # Date 1358866164 0 # Node ID e19f375f9afa18c700a7c6e035bb24d126341166 # Parent f37237021a460d5586d30a4d12a19ff1000683e6 Score activity to favour more recent events diff -r f37237021a46 -r e19f375f9afa app/helpers/activities_helper.rb --- a/app/helpers/activities_helper.rb Tue Jan 22 14:14:56 2013 +0000 +++ b/app/helpers/activities_helper.rb Tue Jan 22 14:49:24 2013 +0000 @@ -2,15 +2,35 @@ module ActivitiesHelper def busy_projects(events, count) - # Transform events list into hash from project id to number of - # occurrences of project in list (there is surely a tidier way - # to do this, e.g. chunk() in Ruby 1.9 but not in 1.8) - phash = events.map do |e| - e.project unless !e.respond_to?(:project) - end.select { |p| !p.nil? }.sort.group_by { |p| p.id } - phash = phash.merge(phash) { |k,v| v.length } - threshold = phash.values.sort.last(count).first - busy = phash.keys.select { |k| phash[k] >= threshold }.sample(count) + + # Score each project for which there are any events, by giving + # each event a score based on how long ago it was (the more recent + # the better). + + projhash = Hash.new + + events.each do |e| + if e.respond_to?(:project) + p = e.project + d = if e.respond_to? :updated_at then e.updated_at else e.updated_on end + dd = Date.parse d.to_s + age = Date.today - dd + score = (age < 14 ? 15-age : 1) + if projhash.key? p + projhash[p] += score + else + projhash[p] = score + end + end + end + + # pick N highest values and use cutoff value as selection threshold + threshold = projhash.values.sort.last(count).first + + # select projects above threshold and pick N from them randomly + busy = projhash.keys.select { |k| projhash[k] >= threshold }.sample(count) + + # return projects rather than just ids busy.map { |pid| Project.find(pid) } end diff -r f37237021a46 -r e19f375f9afa app/views/activities/_busy.html.erb --- a/app/views/activities/_busy.html.erb Tue Jan 22 14:14:56 2013 +0000 +++ b/app/views/activities/_busy.html.erb Tue Jan 22 14:49:24 2013 +0000 @@ -1,7 +1,8 @@ <% events = @events_by_day %> <% if (events.nil?) activity = Redmine::Activity::Fetcher.new(User.anonymous) - events = activity.events(Date.today - 140, Date.today + 1) + days = Setting.activity_days_default.to_i + events = activity.events(Date.today - days, Date.today + 1) end %> @@ -31,7 +32,7 @@ <% u = project.users_by_role if ! u.empty? %> - <%= + <%= mgmt_roles = u.keys.select{ |r| r.allowed_to?(:edit_project) } managers = mgmt_roles.map{ |r| u[r] }.flatten.sort.uniq managers.map{ |m| m.name }.join(', ')