Class: Gitlab::CycleAnalytics::UsageData
- Inherits:
-
Object
- Object
- Gitlab::CycleAnalytics::UsageData
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/cycle_analytics/usage_data.rb
Constant Summary collapse
- PROJECTS_LIMIT =
10
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ UsageData
constructor
A new instance of UsageData.
- #projects ⇒ Object
- #to_json ⇒ Object
Methods included from Utils::StrongMemoize
#clear_memoization, #strong_memoize, #strong_memoized?
Constructor Details
#initialize ⇒ UsageData
Returns a new instance of UsageData.
11 12 13 |
# File 'lib/gitlab/cycle_analytics/usage_data.rb', line 11 def initialize @options = { from: 7.days.ago } end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options
9 10 11 |
# File 'lib/gitlab/cycle_analytics/usage_data.rb', line 9 def @options end |
Instance Method Details
#projects ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gitlab/cycle_analytics/usage_data.rb', line 15 def projects strong_memoize(:projects) do projects = Project.where.not(last_activity_at: nil).order(last_activity_at: :desc).limit(10) + Project.where.not(last_repository_updated_at: nil).order(last_repository_updated_at: :desc).limit(10) projects = projects.uniq.sort_by do |project| [project.last_activity_at, project.last_repository_updated_at].min end if projects.size < 10 projects.concat(Project.where(last_activity_at: nil, last_repository_updated_at: nil).limit(10)) end projects.uniq.first(10) end end |
#to_json ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gitlab/cycle_analytics/usage_data.rb', line 32 def to_json(*) total = 0 values = medians_per_stage.each_with_object({}) do |(stage_name, medians), hsh| calculations = stage_values(medians) total += calculations.values.compact.sum hsh[stage_name] = calculations end values[:total] = total { avg_cycle_analytics: values } end |