Class: FactValue
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- FactValue
- Defined in:
- app/models/fact_value.rb
Class Method Summary collapse
- .build_facts_hash(facts) ⇒ Object
-
.count_each(fact) ⇒ Object
returns the sum of each value, e.g.
-
.mem_average(fact) ⇒ Object
returns the average of all facts required only on facts that return a unit (e.g. MB, GB etc) normal facts could be used via the sum and AR average.
-
.mem_sum(fact) ⇒ Object
returns the rounded total of memory fact values (e.g. MB, GB etc).
Class Method Details
.build_facts_hash(facts) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'app/models/fact_value.rb', line 64 def self.build_facts_hash facts hash = {} facts.each do |fact| hash[fact.host.to_s] ||= {} hash[fact.host.to_s].update({fact.name.to_s => fact.value}) end return hash end |
.count_each(fact) ⇒ Object
returns the sum of each value, e.g. how many machines with 2,4…n cpu's
56 57 58 59 60 61 62 |
# File 'app/models/fact_value.rb', line 56 def self.count_each(fact) output = [] where({:fact_names => {:name => fact}}).joins(:fact_name).count(:group=>'value').each do |k,v| output << {:label => k, :data => v } unless v == 0 end output end |
.mem_average(fact) ⇒ Object
returns the average of all facts required only on facts that return a unit (e.g. MB, GB etc) normal facts could be used via the sum and AR average
42 43 44 45 46 |
# File 'app/models/fact_value.rb', line 42 def self.mem_average(fact) total, count = to_gb(fact) return 0 if count == 0 (total / count).round(1) end |
.mem_sum(fact) ⇒ Object
returns the rounded total of memory fact values (e.g. MB, GB etc)
49 50 51 52 53 |
# File 'app/models/fact_value.rb', line 49 def self.mem_sum(fact) to_gb(fact).first.to_f.round(1) rescue 0 end |