Class: PigCI::Metric::Current
- Inherits:
-
Object
- Object
- PigCI::Metric::Current
- Defined in:
- lib/pig_ci/metric/current.rb
Instance Method Summary collapse
-
#initialize(log_file:) ⇒ Current
constructor
A new instance of Current.
- #to_h ⇒ Object
Constructor Details
#initialize(log_file:) ⇒ Current
Returns a new instance of Current.
2 3 4 |
# File 'lib/pig_ci/metric/current.rb', line 2 def initialize(log_file:) @log_file = log_file end |
Instance Method Details
#to_h ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pig_ci/metric/current.rb', line 6 def to_h @to_h = {} File.foreach(@log_file) do |f| key, value = f.strip.split("|") value = value.to_i @to_h[key] ||= { key: key, max: value, min: value, mean: 0, total: 0, number_of_requests: 0 } @to_h[key][:max] = value if value > @to_h[key][:max] @to_h[key][:min] = value if value < @to_h[key][:min] @to_h[key][:total] += value @to_h[key][:number_of_requests] += 1 @to_h[key][:mean] = @to_h[key][:total] / @to_h[key][:number_of_requests] end @to_h.collect { |_k, d| d } end |