mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-16 20:28:09 +01:00
Statistics for longest running projects now includes completed and hidden projects. fixes #1725
This commit is contained in:
parent
ff9edcc309
commit
2883d1b7f4
6 changed files with 57 additions and 27 deletions
|
|
@ -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|
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue