gitlab-org--gitlab-foss/app/models/cycle_analytics.rb

41 lines
957 B
Ruby
Raw Normal View History

class CycleAnalytics
STAGES = %i[issue plan code test review staging production].freeze
2016-11-22 13:29:25 +00:00
def initialize(project, options:)
@project = project
@options = options
end
def summary
2016-11-23 10:28:28 +00:00
@summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project, from: @options[:from]).data
end
2016-11-22 13:29:25 +00:00
def stats
@stats ||= stats_per_stage
end
def no_stats?
2016-11-23 10:28:28 +00:00
stats.map { |hash| hash[:value] }.compact.empty?
2016-11-22 11:01:21 +00:00
end
def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
end
2016-11-23 10:28:28 +00:00
def events_for(stage)
classify_stage(stage).new(project: @project, options: @options, stage: stage).events
end
2016-11-22 13:29:25 +00:00
private
def stats_per_stage
STAGES.map do |stage_name|
2016-11-23 10:28:28 +00:00
classify_stage(stage_name).new(project: @project, options: @options, stage: stage_name).median_data
2016-11-22 13:29:25 +00:00
end
end
2016-11-22 13:29:25 +00:00
def classify_stage(stage_name)
"Gitlab::CycleAnalytics::#{stage_name.to_s.capitalize}Stage".constantize
end
end