Class: ApiBomb::Signaler

Inherits:
Object
  • Object
show all
Defined in:
lib/api_bomb/signaler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSignaler

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_timesObject (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

#statusesObject (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_lostObject



14
15
16
# File 'lib/api_bomb/signaler.rb', line 14

def fighters_lost
  hold_times.count
end

#mean_hold_timeObject



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_timeObject



22
23
24
# File 'lib/api_bomb/signaler.rb', line 22

def sd_time
  hold_times.standard_deviation
end

#server_errorsObject



30
31
32
# File 'lib/api_bomb/signaler.rb', line 30

def server_errors
  @statuses.select{|s| s >= 500}.count
end

#server_status_statsObject



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