mirror of
https://github.com/TracksApp/tracks.git
synced 2025-09-21 21:40:48 +02:00
28 lines
601 B
Ruby
28 lines
601 B
Ruby
module Stats
|
|
class Projects
|
|
attr_reader :user
|
|
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
def runtime
|
|
@runtime ||= find_top10_longest_running_projects
|
|
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
|
|
|
|
private
|
|
|
|
def find_top10_longest_running_projects
|
|
projects = user.projects.order('created_at ASC')
|
|
projects.sort_by { |p| p.running_time }.reverse.take(10)
|
|
end
|
|
end
|
|
end
|