Mercurial > hg > soundsoftware-site
diff app/helpers/activities_helper.rb @ 1168:4d1a31b30987 cannam
Remove nil projects before sorting
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Mon, 21 Jan 2013 15:48:48 +0000 |
parents | b98f60a6d231 |
children | e19f375f9afa |
line wrap: on
line diff
--- a/app/helpers/activities_helper.rb Mon Jan 21 14:18:00 2013 +0000 +++ b/app/helpers/activities_helper.rb Mon Jan 21 15:48:48 2013 +0000 @@ -5,7 +5,9 @@ # 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 { |e| e.project unless !e.respond_to?(:project) }.sort.group_by { |p| p.id } + 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)