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

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

Instance Method Summary collapse

Methods included from StageQueryHelpers

#duration, #duration_in_seconds, #in_progress?, #percentile_cont

Constructor Details

#initialize(stage:, query:, params:) ⇒ Median

Returns a new instance of Median.



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

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

Instance Method Details

#daysObject

rubocop: enable CodeReuse/ActiveRecord



25
26
27
# File 'lib/gitlab/analytics/cycle_analytics/aggregated/median.rb', line 25

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

#secondsObject

rubocop: disable CodeReuse/ActiveRecord



17
18
19
20
21
22
# File 'lib/gitlab/analytics/cycle_analytics/aggregated/median.rb', line 17

def seconds
  @query = @query.select(duration_in_seconds(percentile_cont).as('median')).reorder(nil)
  result = @query.take || {}

  result['median'] || nil
end