diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /lib/gitlab/cycle_analytics | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'lib/gitlab/cycle_analytics')
-rw-r--r-- | lib/gitlab/cycle_analytics/builds_event_helper.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/code_event_fetcher.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/issue_event_fetcher.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/permissions.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/plan_event_fetcher.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/production_event_fetcher.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/review_event_fetcher.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/updater.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/cycle_analytics/usage_data.rb | 91 |
9 files changed, 16 insertions, 107 deletions
diff --git a/lib/gitlab/cycle_analytics/builds_event_helper.rb b/lib/gitlab/cycle_analytics/builds_event_helper.rb index 0d6f32fdc6f..c39d41578e9 100644 --- a/lib/gitlab/cycle_analytics/builds_event_helper.rb +++ b/lib/gitlab/cycle_analytics/builds_event_helper.rb @@ -3,11 +3,11 @@ module Gitlab module CycleAnalytics module BuildsEventHelper - def initialize(*args) + def initialize(...) @projections = [build_table[:id]] @order = build_table[:created_at] - super(*args) + super(...) end def fetch diff --git a/lib/gitlab/cycle_analytics/code_event_fetcher.rb b/lib/gitlab/cycle_analytics/code_event_fetcher.rb index d75da76415a..790bf32c6c7 100644 --- a/lib/gitlab/cycle_analytics/code_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/code_event_fetcher.rb @@ -5,7 +5,7 @@ module Gitlab class CodeEventFetcher < BaseEventFetcher include CodeHelper - def initialize(*args) + def initialize(...) @projections = [mr_table[:title], mr_table[:iid], mr_table[:id], @@ -14,7 +14,7 @@ module Gitlab mr_table[:author_id]] @order = mr_table[:created_at] - super(*args) + super(...) end private diff --git a/lib/gitlab/cycle_analytics/issue_event_fetcher.rb b/lib/gitlab/cycle_analytics/issue_event_fetcher.rb index 6914cf24c19..fd04ec090b3 100644 --- a/lib/gitlab/cycle_analytics/issue_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/issue_event_fetcher.rb @@ -5,14 +5,14 @@ module Gitlab class IssueEventFetcher < BaseEventFetcher include IssueHelper - def initialize(*args) + def initialize(...) @projections = [issue_table[:title], issue_table[:iid], issue_table[:id], issue_table[:created_at], issue_table[:author_id]] - super(*args) + super(...) end private diff --git a/lib/gitlab/cycle_analytics/permissions.rb b/lib/gitlab/cycle_analytics/permissions.rb index 55214e6b896..0e094fabb01 100644 --- a/lib/gitlab/cycle_analytics/permissions.rb +++ b/lib/gitlab/cycle_analytics/permissions.rb @@ -12,8 +12,8 @@ module Gitlab production: :read_issue }.freeze - def self.get(*args) - new(*args).get + def self.get(...) + new(...).get end def initialize(user:, project:) diff --git a/lib/gitlab/cycle_analytics/plan_event_fetcher.rb b/lib/gitlab/cycle_analytics/plan_event_fetcher.rb index bad02e00a13..4d98d589e46 100644 --- a/lib/gitlab/cycle_analytics/plan_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/plan_event_fetcher.rb @@ -5,14 +5,14 @@ module Gitlab class PlanEventFetcher < BaseEventFetcher include PlanHelper - def initialize(*args) + def initialize(...) @projections = [issue_table[:title], issue_table[:iid], issue_table[:id], issue_table[:created_at], issue_table[:author_id]] - super(*args) + super(...) end private diff --git a/lib/gitlab/cycle_analytics/production_event_fetcher.rb b/lib/gitlab/cycle_analytics/production_event_fetcher.rb index 8843ab2bcb9..5fa286bd3df 100644 --- a/lib/gitlab/cycle_analytics/production_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/production_event_fetcher.rb @@ -5,7 +5,7 @@ module Gitlab class ProductionEventFetcher < BaseEventFetcher include ProductionHelper - def initialize(*args) + def initialize(...) @projections = [issue_table[:title], issue_table[:iid], issue_table[:id], @@ -13,7 +13,7 @@ module Gitlab issue_table[:author_id], routes_table[:path]] - super(*args) + super(...) end private diff --git a/lib/gitlab/cycle_analytics/review_event_fetcher.rb b/lib/gitlab/cycle_analytics/review_event_fetcher.rb index f5f8c19683d..0b7d160c7de 100644 --- a/lib/gitlab/cycle_analytics/review_event_fetcher.rb +++ b/lib/gitlab/cycle_analytics/review_event_fetcher.rb @@ -5,7 +5,7 @@ module Gitlab class ReviewEventFetcher < BaseEventFetcher include ReviewHelper - def initialize(*args) + def initialize(...) @projections = [mr_table[:title], mr_table[:iid], mr_table[:id], @@ -13,7 +13,7 @@ module Gitlab mr_table[:state_id], mr_table[:author_id]] - super(*args) + super(...) end private diff --git a/lib/gitlab/cycle_analytics/updater.rb b/lib/gitlab/cycle_analytics/updater.rb index c642809a792..5be351989e0 100644 --- a/lib/gitlab/cycle_analytics/updater.rb +++ b/lib/gitlab/cycle_analytics/updater.rb @@ -3,8 +3,8 @@ module Gitlab module CycleAnalytics class Updater - def self.update!(*args) - new(*args).update! + def self.update!(...) + new(...).update! end def initialize(event_result, from:, to:, klass:) diff --git a/lib/gitlab/cycle_analytics/usage_data.rb b/lib/gitlab/cycle_analytics/usage_data.rb deleted file mode 100644 index e58def57e69..00000000000 --- a/lib/gitlab/cycle_analytics/usage_data.rb +++ /dev/null @@ -1,91 +0,0 @@ -# frozen_string_literal: true - -module Gitlab - module CycleAnalytics - class UsageData - include Gitlab::Utils::StrongMemoize - PROJECTS_LIMIT = 10 - - attr_reader :options - - def initialize - @options = { from: 7.days.ago } - end - - 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 - - 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 - - private - - def medians_per_stage - projects.each_with_object({}) do |project, hsh| - ::CycleAnalytics::ProjectLevel.new(project, options: options).all_medians_by_stage.each do |stage_name, median| - hsh[stage_name] ||= [] - hsh[stage_name] << median - end - end - end - - def stage_values(medians) - medians = medians.map(&:presence).compact - average = calc_average(medians) - - { - average: average, - sd: standard_deviation(medians, average), - missing: projects.length - medians.length - } - end - - def calc_average(values) - return if values.empty? - - (values.sum / values.length).to_i - end - - def standard_deviation(values, average) - Math.sqrt(sample_variance(values, average)).to_i - end - - def sample_variance(values, average) - return 0 if values.length <= 1 - - sum = values.inject(0) do |acc, val| - acc + (val - average)**2 - end - - sum / (values.length - 1) - end - end - end -end |