Class: PSI::Metrics

Inherits:
Object
  • Object
show all
Defined in:
lib/psi/reading.rb

Overview

Pressure averages and the cumulative stall time for one PSI category.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(averages:, total:) ⇒ Metrics

Returns a new instance of Metrics.



8
9
10
11
# File 'lib/psi/reading.rb', line 8

def initialize(averages:, total:)
  @averages = averages.freeze
  @total = total
end

Instance Attribute Details

#totalObject (readonly)

Returns the value of attribute total.



6
7
8
# File 'lib/psi/reading.rb', line 6

def total
  @total
end

Instance Method Details

#avg(seconds) ⇒ Float?

Returns the rolling average for a window in seconds.

Parameters:

  • seconds (Integer)

Returns:

  • (Float, nil)


16
17
18
# File 'lib/psi/reading.rb', line 16

def avg(seconds)
  @averages[Integer(seconds)]
end

#avg10Float?

Returns ten-second average.

Returns:

  • (Float, nil)

    ten-second average



21
22
# File 'lib/psi/reading.rb', line 21

def avg10 = avg(10)
# @return [Float, nil] sixty-second average

#avg300Float?

Returns three-hundred-second average.

Returns:

  • (Float, nil)

    three-hundred-second average



25
# File 'lib/psi/reading.rb', line 25

def avg300 = avg(300)

#avg60Float?

Returns sixty-second average.

Returns:

  • (Float, nil)

    sixty-second average



23
24
# File 'lib/psi/reading.rb', line 23

def avg60 = avg(60)
# @return [Float, nil] three-hundred-second average

#to_hHash

Converts dynamic averages and total time to a hash.

Returns:

  • (Hash)


29
30
31
# File 'lib/psi/reading.rb', line 29

def to_h
  @averages.sort.to_h { |seconds, value| [:"avg#{seconds}", value] }.merge(total: total)
end