added analytics stage serializer and moved some info to the stage classes from the controller

This commit is contained in:
James Lopez 2016-11-21 17:15:25 +01:00
parent 3268e37791
commit a998276223
10 changed files with 59 additions and 0 deletions

View file

@ -0,0 +1,12 @@
class AnalyticsStageEntity < Grape::Entity
include EntityDateHelper
expose :stage, as: :title do |object|
object[:stage].to_s.capitalize
end
expose :description
expose :median, as: :value do |stage|
stage[:median] && !stage[:median].zero? ? distance_of_time_in_words(stage[:median]) : nil
end
end

View file

@ -0,0 +1,3 @@
class AnalyticsStageSerializer < BaseSerializer
entity AnalyticsStageEntity
end

View file

@ -1,6 +1,8 @@
module Gitlab
module CycleAnalytics
class BaseStage
attr_reader :stage, :description
def initialize(project:, options:, stage: stage)
@project = project
@options = options

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class CodeStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time until first merge request"
end
def median
@fetcher.calculate_metric(:code,
Issue::Metrics.arel_table[:first_mentioned_in_commit_at],

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class IssueStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time before an issue gets scheduled"
end
def median
@fetcher.calculate_metric(:issue,
Issue.arel_table[:created_at],

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class PlanStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time before an issue starts implementation"
end
def median
@fetcher.calculate_metric(:plan,
[Issue::Metrics.arel_table[:first_associated_with_milestone_at],

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class ProductionStage < BaseStage
def initialize(*args)
super(*args)
@description = "From issue creation until deploy to production"
end
def median
@fetcher.calculate_metric(:production,
Issue.arel_table[:created_at],

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class ReviewStage < BaseStage
def initialize(*args)
super(*args)
@description = "Time between merge request creation and merge/close"
end
def median
@fetcher.calculate_metric(:review,
MergeRequest.arel_table[:created_at],

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class StagingStage < BaseStage
def initialize(*args)
super(*args)
@description = "From merge request merge until deploy to production"
end
def median
@fetcher.calculate_metric(:staging,
MergeRequest::Metrics.arel_table[:merged_at],

View file

@ -1,6 +1,12 @@
module Gitlab
module CycleAnalytics
class TestStage < BaseStage
def initialize(*args)
super(*args)
@description = "Total test time for all commits/merges"
end
def median
@fetcher.calculate_metric(:test,
MergeRequest::Metrics.arel_table[:latest_build_started_at],