Class: ForemanStatistics::Statistics::CountNumericalFactPair

Inherits:
Base
  • Object
show all
Defined in:
app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#count_by, #title, #url

Instance Method Summary collapse

Methods inherited from Base

#id, #metadata, #search

Constructor Details

#initialize(options = {}) ⇒ CountNumericalFactPair

Returns a new instance of CountNumericalFactPair.



6
7
8
9
10
11
12
13
14
# File 'app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb', line 6

def initialize(options = {})
  super(options)
  if @count_by.empty?
    raise(ArgumentError, 'Must provide :count_by option')
  end
  @count_by = @count_by.to_s
  @total    = options[:total] || 'size'
  @used     = options[:used]  || 'free'
end

Instance Attribute Details

#totalObject (readonly)

Returns the value of attribute total.



4
5
6
# File 'app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb', line 4

def total
  @total
end

#usedObject (readonly)

Returns the value of attribute used.



4
5
6
# File 'app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb', line 4

def used
  @used
end

Instance Method Details

#calculateObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/foreman_statistics/statistics/count_numerical_fact_pair.rb', line 16

def calculate
  mem_size = FactValue.authorized(:view_facts).my_facts.mem_average(total_name)
  mem_free = FactValue.authorized(:view_facts).my_facts.mem_average(used_name)

  [
    {
      :label => _('free memory'),
      :data => mem_free
    },
    {
      :label => _('used memory'),
      :data => (mem_size - mem_free).round(2)
    }
  ]
end