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, #end_event_timestamp_projection, #execute_query, #in_progress?, #order_by, #requires_grouping?, #round_duration_to_seconds, #zero_interval

Constructor Details

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

Returns a new instance of Median.



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

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

Instance Method Details

#daysObject

rubocop: enable CodeReuse/ActiveRecord



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

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

#secondsObject

rubocop: disable CodeReuse/ActiveRecord



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

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

  result['median'] || nil
end