2013-03-02 17:11:19 -07:00
|
|
|
module Stats
|
|
|
|
class Projects
|
|
|
|
attr_reader :user
|
2020-10-10 02:27:42 +03:00
|
|
|
|
2013-03-02 17:11:19 -07:00
|
|
|
def initialize(user)
|
|
|
|
@user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
def runtime
|
2014-11-05 17:07:21 +01:00
|
|
|
@runtime ||= find_top10_longest_running_projects
|
2013-03-02 17:11:19 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def actions
|
|
|
|
@actions ||= Stats::TopProjectsQuery.new(user).result
|
|
|
|
end
|
|
|
|
|
|
|
|
def actions_last30days
|
|
|
|
@actions_last30days ||= Stats::TopProjectsQuery.new(user, 1.month.ago.beginning_of_day).result
|
|
|
|
end
|
|
|
|
|
2014-11-05 17:07:21 +01:00
|
|
|
private
|
|
|
|
|
|
|
|
def find_top10_longest_running_projects
|
|
|
|
projects = user.projects.order('created_at ASC')
|
2020-10-27 21:39:19 +02:00
|
|
|
projects.sort_by { |p| p.running_time }.reverse.take(10)
|
2014-11-05 17:07:21 +01:00
|
|
|
end
|
2013-03-02 17:11:19 -07:00
|
|
|
end
|
|
|
|
end
|