Commit 150a4485 authored by James Lopez's avatar James Lopez

refactored a bunch of stuff based on feedback

parent 34875ce6
...@@ -17,7 +17,7 @@ class CycleAnalytics ...@@ -17,7 +17,7 @@ class CycleAnalytics
end end
def no_stats? def no_stats?
stats.map { |hash| hash[:value] }.compact.empty? stats.all? { hash[:value].nil? }
end end
def permissions(user:) def permissions(user:)
...@@ -32,7 +32,7 @@ class CycleAnalytics ...@@ -32,7 +32,7 @@ class CycleAnalytics
def stats_per_stage def stats_per_stage
STAGES.map do |stage_name| STAGES.map do |stage_name|
self[stage_name].median_data self[stage_name].as_json
end end
end end
end end
...@@ -42,7 +42,7 @@ module Gitlab ...@@ -42,7 +42,7 @@ module Gitlab
end end
def default_order def default_order
@options[:start_time_attrs].is_a?(Array) ? @options[:start_time_attrs].first : @options[:start_time_attrs] [@options[:start_time_attrs]].flatten.first
end end
def serialize(_event) def serialize(_event)
......
...@@ -8,17 +8,11 @@ module Gitlab ...@@ -8,17 +8,11 @@ module Gitlab
@options = options @options = options
end end
def event
@event ||= Gitlab::CycleAnalytics::Event[name].new(project: @project,
stage: name,
options: event_options)
end
def events def events
event.fetch event_fetcher.fetch
end end
def median_data def as_json
AnalyticsStageSerializer.new.represent(self).as_json AnalyticsStageSerializer.new.represent(self).as_json
end end
...@@ -35,7 +29,7 @@ module Gitlab ...@@ -35,7 +29,7 @@ module Gitlab
# cycle analytics stage. # cycle analytics stage.
interval_query = Arel::Nodes::As.new( interval_query = Arel::Nodes::As.new(
cte_table, cte_table,
subtract_datetimes(base_query.dup, @start_time_attrs, @end_time_attrs, name.to_s)) subtract_datetimes(base_query.dup, start_time_attrs, end_time_attrs, name.to_s))
median_datetime(cte_table, interval_query, name) median_datetime(cte_table, interval_query, name)
end end
...@@ -46,8 +40,14 @@ module Gitlab ...@@ -46,8 +40,14 @@ module Gitlab
private private
def event_fetcher
@event_fetcher ||= Gitlab::CycleAnalytics::EventFetcher[name].new(project: @project,
stage: name,
options: event_options)
end
def event_options def event_options
@options.merge(start_time_attrs: @start_time_attrs, end_time_attrs: @end_time_attrs) @options.merge(start_time_attrs: start_time_attrs, end_time_attrs: end_time_attrs)
end end
end end
end end
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class CodeStage < BaseStage class CodeStage < BaseStage
def initialize(*args) def start_time_attrs
@start_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at] @start_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at]
@end_time_attrs = mr_table[:created_at] end
super(*args) def end_time_attrs
@end_time_attrs ||= mr_table[:created_at]
end end
def name def name
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
module Event module EventFetcher
def self.[](stage_name) def self.[](stage_name)
CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher") CycleAnalytics.const_get("#{stage_name.to_s.camelize}EventFetcher")
end end
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class IssueStage < BaseStage class IssueStage < BaseStage
def initialize(*args) def start_time_attrs
@start_time_attrs = issue_table[:created_at] @start_time_attrs ||= issue_table[:created_at]
@end_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at], end
issue_metrics_table[:first_added_to_board_at]]
super(*args) def end_time_attrs
@end_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]]
end end
def name def name
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class PlanStage < BaseStage class PlanStage < BaseStage
def initialize(*args) def start_time_attrs
@start_time_attrs = [issue_metrics_table[:first_associated_with_milestone_at], @start_time_attrs ||= [issue_metrics_table[:first_associated_with_milestone_at],
issue_metrics_table[:first_added_to_board_at]] issue_metrics_table[:first_added_to_board_at]]
@end_time_attrs = issue_metrics_table[:first_mentioned_in_commit_at] end
super(*args) def end_time_attrs
@end_time_attrs ||= issue_metrics_table[:first_mentioned_in_commit_at]
end end
def name def name
......
...@@ -3,11 +3,12 @@ module Gitlab ...@@ -3,11 +3,12 @@ module Gitlab
class ProductionStage < BaseStage class ProductionStage < BaseStage
include ProductionHelper include ProductionHelper
def initialize(*args) def start_time_attrs
@start_time_attrs = issue_table[:created_at] @start_time_attrs ||= issue_table[:created_at]
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at] end
super(*args) def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:first_deployed_to_production_at]
end end
def name def name
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class ReviewStage < BaseStage class ReviewStage < BaseStage
def initialize(*args) def start_time_attrs
@start_time_attrs = mr_table[:created_at] @start_time_attrs ||= mr_table[:created_at]
@end_time_attrs = mr_metrics_table[:merged_at] end
super(*args) def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:merged_at]
end end
def name def name
......
...@@ -2,12 +2,12 @@ module Gitlab ...@@ -2,12 +2,12 @@ module Gitlab
module CycleAnalytics module CycleAnalytics
class StagingStage < BaseStage class StagingStage < BaseStage
include ProductionHelper include ProductionHelper
def start_time_attrs
@start_time_attrs ||= mr_metrics_table[:merged_at]
end
def initialize(*args) def end_time_attrs
@start_time_attrs = mr_metrics_table[:merged_at] @end_time_attrs ||= mr_metrics_table[:first_deployed_to_production_at]
@end_time_attrs = mr_metrics_table[:first_deployed_to_production_at]
super(*args)
end end
def name def name
......
module Gitlab module Gitlab
module CycleAnalytics module CycleAnalytics
class TestStage < BaseStage class TestStage < BaseStage
def initialize(*args) def start_time_attrs
@start_time_attrs = mr_metrics_table[:latest_build_started_at] @start_time_attrs ||= mr_metrics_table[:latest_build_started_at]
@end_time_attrs = mr_metrics_table[:latest_build_finished_at] end
super(*args) def end_time_attrs
@end_time_attrs ||= mr_metrics_table[:latest_build_finished_at]
end end
def name def name
......
...@@ -9,15 +9,15 @@ shared_examples 'base stage' do ...@@ -9,15 +9,15 @@ shared_examples 'base stage' do
end end
it 'has the median data value' do it 'has the median data value' do
expect(stage.median_data[:value]).not_to be_nil expect(stage.as_json[:value]).not_to be_nil
end end
it 'has the median data stage' do it 'has the median data stage' do
expect(stage.median_data[:title]).not_to be_nil expect(stage.as_json[:title]).not_to be_nil
end end
it 'has the median data description' do it 'has the median data description' do
expect(stage.median_data[:description]).not_to be_nil expect(stage.as_json[:description]).not_to be_nil
end end
it 'has the title' do it 'has the title' do
......
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