2018-07-25 09:30:33 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 05:02:27 +00:00
|
|
|
class CycleAnalytics
|
2016-11-21 09:48:07 +00:00
|
|
|
STAGES = %i[issue plan code test review staging production].freeze
|
|
|
|
|
2016-12-01 10:21:24 +00:00
|
|
|
def initialize(project, options)
|
2016-09-16 06:04:49 +00:00
|
|
|
@project = project
|
2016-11-18 15:38:02 +00:00
|
|
|
@options = options
|
2016-09-19 09:30:55 +00:00
|
|
|
end
|
|
|
|
|
2018-02-12 12:24:42 +00:00
|
|
|
def all_medians_per_stage
|
2018-02-15 13:23:39 +00:00
|
|
|
STAGES.each_with_object({}) do |stage_name, medians_per_stage|
|
|
|
|
medians_per_stage[stage_name] = self[stage_name].median
|
2018-01-30 11:28:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-19 09:30:55 +00:00
|
|
|
def summary
|
2016-12-01 12:28:24 +00:00
|
|
|
@summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project,
|
|
|
|
from: @options[:from],
|
|
|
|
current_user: @options[:current_user]).data
|
2016-08-26 10:15:00 +00:00
|
|
|
end
|
|
|
|
|
2016-11-22 13:29:25 +00:00
|
|
|
def stats
|
|
|
|
@stats ||= stats_per_stage
|
|
|
|
end
|
|
|
|
|
|
|
|
def no_stats?
|
2017-01-12 13:32:30 +00:00
|
|
|
stats.all? { |hash| hash[:value].nil? }
|
2016-11-22 11:01:21 +00:00
|
|
|
end
|
|
|
|
|
2016-11-21 13:09:26 +00:00
|
|
|
def permissions(user:)
|
|
|
|
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
|
2016-11-21 09:48:07 +00:00
|
|
|
end
|
|
|
|
|
2016-12-01 10:21:24 +00:00
|
|
|
def [](stage_name)
|
2018-02-12 12:24:42 +00:00
|
|
|
Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
|
2016-11-23 10:28:28 +00:00
|
|
|
end
|
|
|
|
|
2016-11-22 13:29:25 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def stats_per_stage
|
|
|
|
STAGES.map do |stage_name|
|
2017-01-12 11:48:01 +00:00
|
|
|
self[stage_name].as_json
|
2016-11-22 13:29:25 +00:00
|
|
|
end
|
2016-08-25 05:02:27 +00:00
|
|
|
end
|
|
|
|
end
|