Commit 34b7f173 authored by Małgorzata Ksionek's avatar Małgorzata Ksionek

Move cycle analytics model to separate namespace

parent 7301cd14
# frozen_string_literal: true
class CycleAnalytics
STAGES = %i[issue plan code test review staging production].freeze
def initialize(project, options)
@project = project
@options = options
end
def all_medians_per_stage
STAGES.each_with_object({}) do |stage_name, medians_per_stage|
medians_per_stage[stage_name] = self[stage_name].median
end
end
def summary
@summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project,
from: @options[:from],
current_user: @options[:current_user]).data
end
def stats
@stats ||= stats_per_stage
end
def no_stats?
stats.all? { |hash| hash[:value].nil? }
end
def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
end
def [](stage_name)
Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
end
private
def stats_per_stage
STAGES.map do |stage_name|
self[stage_name].as_json
end
end
end
# frozen_string_literal: true
module CycleAnalytics
class Base
STAGES = %i[issue plan code test review staging production].freeze
def all_medians_per_stage
STAGES.each_with_object({}) do |stage_name, medians_per_stage|
medians_per_stage[stage_name] = self[stage_name].median
end
end
def stats
@stats ||= stats_per_stage
end
def no_stats?
stats.all? { |hash| hash[:value].nil? }
end
def [](stage_name)
Gitlab::CycleAnalytics::Stage[stage_name].new(project: @project, options: @options)
end
private
def stats_per_stage
STAGES.map do |stage_name|
self[stage_name].as_json
end
end
end
end
# frozen_string_literal: true
module CycleAnalytics
class ProjectLevel < Base
def initialize(project:, options:)
@project = project
@options = options
end
def summary
@summary ||= ::Gitlab::CycleAnalytics::StageSummary.new(@project,
from: @options[:from],
current_user: @options[:current_user]).data
end
def permissions(user:)
Gitlab::CycleAnalytics::Permissions.get(user: user, project: @project)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment