Class: Gitlab::Analytics::CycleAnalytics::Median

Inherits:
Object
  • Object
show all
Includes:
StageQueryHelpers
Defined in:
lib/gitlab/analytics/cycle_analytics/median.rb

Instance Method Summary collapse

Methods included from StageQueryHelpers

#duration, #execute_query, #order_by_end_event, #requires_grouping?, #round_duration_to_seconds, #zero_interval

Constructor Details

#initialize(stage:, query:) ⇒ Median

Returns a new instance of Median.


9
10
11
12
# File 'lib/gitlab/analytics/cycle_analytics/median.rb', line 9

def initialize(stage:, query:)
  @stage = stage
  @query = query
end

Instance Method Details

#daysObject

rubocop: enable CodeReuse/ActiveRecord


23
24
25
# File 'lib/gitlab/analytics/cycle_analytics/median.rb', line 23

def days
  seconds ? seconds.fdiv(1.day) : nil
end

#secondsObject

rubocop: disable CodeReuse/ActiveRecord


15
16
17
18
19
20
# File 'lib/gitlab/analytics/cycle_analytics/median.rb', line 15

def seconds
  @query = @query.select(median_duration_in_seconds.as('median')).reorder(nil)
  result = execute_query(@query).first || {}

  result['median'] || nil
end