Statistics for longest running projects now includes completed and hidden projects. fixes #1725

This commit is contained in:
Reinier Balt 2014-11-05 17:07:21 +01:00
parent ff9edcc309
commit 2883d1b7f4
6 changed files with 57 additions and 27 deletions

View file

@ -138,6 +138,14 @@ class Project < ActiveRecord::Base
@age_in_days ||= (Time.current.to_date - created_at.to_date).to_i + 1
end
def running_time
if completed_at.nil?
return age_in_days
else
return (completed_at.to_date - created_at.to_date).to_i + 1
end
end
def self.import(filename, params, user)
count = 0
CSV.foreach(filename, headers: true) do |row|

View file

@ -7,7 +7,7 @@ module Stats
end
def runtime
@runtime ||= user.projects.active.order('created_at ASC').limit(10)
@runtime ||= find_top10_longest_running_projects
end
def actions
@ -18,5 +18,12 @@ module Stats
@actions_last30days ||= Stats::TopProjectsQuery.new(user, 1.month.ago.beginning_of_day).result
end
private
def find_top10_longest_running_projects
projects = user.projects.order('created_at ASC')
projects.sort{|a,b| b.running_time <=> a.running_time}.take(10)
end
end
end