Mercurial > hg > soundsoftware-site
comparison app/helpers/activities_helper.rb @ 1205:adb5f38f6ab7 cannam
Pick up activity date from various different methods
author | Chris Cannam <chris.cannam@soundsoftware.ac.uk> |
---|---|
date | Wed, 23 Jan 2013 12:00:09 +0000 |
parents | e19f375f9afa |
children | 875b5b4c574d |
comparison
equal
deleted
inserted
replaced
1203:74ad60b807ae | 1205:adb5f38f6ab7 |
---|---|
1 | 1 |
2 module ActivitiesHelper | 2 module ActivitiesHelper |
3 | |
4 def date_of_event(e) | |
5 if e.respond_to? :updated_at | |
6 e.updated_at | |
7 elsif e.respond_to? :updated_on | |
8 e.updated_on | |
9 elsif e.respond_to? :created_on | |
10 e.created_on | |
11 elsif e.respond_to? :committed_on | |
12 e.committed_on | |
13 else | |
14 nil | |
15 end | |
16 end | |
3 | 17 |
4 def busy_projects(events, count) | 18 def busy_projects(events, count) |
5 | 19 |
6 # Score each project for which there are any events, by giving | 20 # Score each project for which there are any events, by giving |
7 # 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 |
10 projhash = Hash.new | 24 projhash = Hash.new |
11 | 25 |
12 events.each do |e| | 26 events.each do |e| |
13 if e.respond_to?(:project) | 27 if e.respond_to?(:project) |
14 p = e.project | 28 p = e.project |
15 d = if e.respond_to? :updated_at then e.updated_at else e.updated_on end | 29 d = date_of_event e |
16 dd = Date.parse d.to_s | 30 if !d.nil? |
17 age = Date.today - dd | 31 dd = Date.parse d.to_s |
18 score = (age < 14 ? 15-age : 1) | 32 age = Date.today - dd |
19 if projhash.key? p | 33 score = (age < 14 ? 15-age : 1) |
20 projhash[p] += score | 34 if projhash.key? p |
21 else | 35 projhash[p] += score |
22 projhash[p] = score | 36 else |
37 projhash[p] = score | |
38 end | |
23 end | 39 end |
24 end | 40 end |
25 end | 41 end |
26 | 42 |
27 # pick N highest values and use cutoff value as selection threshold | 43 # pick N highest values and use cutoff value as selection threshold |