Class: ApiBomb::Signaler
- Inherits:
-
Object
- Object
- ApiBomb::Signaler
- Defined in:
- lib/api_bomb/signaler.rb
Instance Attribute Summary collapse
-
#hold_times ⇒ Object
readonly
Returns the value of attribute hold_times.
-
#statuses ⇒ Object
readonly
Returns the value of attribute statuses.
Instance Method Summary collapse
- #fighters_lost ⇒ Object
-
#initialize ⇒ Signaler
constructor
A new instance of Signaler.
- #mean_hold_time ⇒ Object
- #percentile(value) ⇒ Object
- #report(fighter) ⇒ Object
- #sd_time ⇒ Object
- #server_errors ⇒ Object
- #server_status_stats ⇒ Object
Constructor Details
#initialize ⇒ Signaler
Returns a new instance of Signaler.
4 5 6 7 |
# File 'lib/api_bomb/signaler.rb', line 4 def initialize @statuses = [] @hold_times = [] end |
Instance Attribute Details
#hold_times ⇒ Object (readonly)
Returns the value of attribute hold_times.
2 3 4 |
# File 'lib/api_bomb/signaler.rb', line 2 def hold_times @hold_times end |
#statuses ⇒ Object (readonly)
Returns the value of attribute statuses.
2 3 4 |
# File 'lib/api_bomb/signaler.rb', line 2 def statuses @statuses end |
Instance Method Details
#fighters_lost ⇒ Object
14 15 16 |
# File 'lib/api_bomb/signaler.rb', line 14 def fighters_lost hold_times.count end |
#mean_hold_time ⇒ Object
18 19 20 |
# File 'lib/api_bomb/signaler.rb', line 18 def mean_hold_time hold_times.mean end |
#percentile(value) ⇒ Object
26 27 28 |
# File 'lib/api_bomb/signaler.rb', line 26 def percentile(value) hold_times.percentile(value) end |
#report(fighter) ⇒ Object
9 10 11 12 |
# File 'lib/api_bomb/signaler.rb', line 9 def report(fighter) @statuses << fighter.value.response.status @hold_times << fighter.value.hold_time end |
#sd_time ⇒ Object
22 23 24 |
# File 'lib/api_bomb/signaler.rb', line 22 def sd_time hold_times.standard_deviation end |
#server_errors ⇒ Object
30 31 32 |
# File 'lib/api_bomb/signaler.rb', line 30 def server_errors @statuses.select{|s| s >= 500}.count end |
#server_status_stats ⇒ Object
34 35 36 37 38 |
# File 'lib/api_bomb/signaler.rb', line 34 def server_status_stats @server_status_stats ||= @statuses.group_by{|status| status.to_i.to_s.chop.chop.insert(-1, 'xx') }.map{|s| {s.first => s.last.count}} end |