Class: ActiveGenie::Ranker::Entities::Players
- Inherits:
-
Object
- Object
- ActiveGenie::Ranker::Entities::Players
show all
- Defined in:
- lib/active_genie/entities/players.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(players) ⇒ Players
Returns a new instance of Players.
9
10
11
12
13
14
15
|
# File 'lib/active_genie/entities/players.rb', line 9
def initialize(players)
@players = if players.is_a?(Players)
players.players
else
build(players)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing ⇒ Object
70
71
72
|
# File 'lib/active_genie/entities/players.rb', line 70
def method_missing(...)
@players.send(...)
end
|
Instance Attribute Details
#players ⇒ Object
Returns the value of attribute players.
17
18
19
|
# File 'lib/active_genie/entities/players.rb', line 17
def players
@players
end
|
Instance Method Details
#all_scores ⇒ Object
30
31
32
|
# File 'lib/active_genie/entities/players.rb', line 30
def all_scores
eligible.map(&:score).compact
end
|
#calc_higher_tier ⇒ Object
Since eligible is sorted in descending order (best player first), lower_tier represents the worst performing players at the end of the array.
42
43
44
|
# File 'lib/active_genie/entities/players.rb', line 42
def calc_higher_tier
eligible[(tier_size * -2)...(tier_size * -1)]
end
|
#calc_lower_tier ⇒ Object
46
47
48
|
# File 'lib/active_genie/entities/players.rb', line 46
def calc_lower_tier
eligible[(tier_size * -1)..]
end
|
#coefficient_of_variation ⇒ Object
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/active_genie/entities/players.rb', line 19
def coefficient_of_variation
mean = score_mean
return 0 if mean.zero?
variance = all_scores.map { |num| (num - mean)**2 }.sum / all_scores.size
standard_deviation = Math.sqrt(variance)
(standard_deviation / mean) * 100
end
|
#eligible ⇒ Object
50
51
52
|
# File 'lib/active_genie/entities/players.rb', line 50
def eligible
sorted.reject(&:eliminated)
end
|
#eligible_size ⇒ Object
54
55
56
|
# File 'lib/active_genie/entities/players.rb', line 54
def eligible_size
@players.reject(&:eliminated).size
end
|
#elo_eligible? ⇒ Boolean
58
59
60
|
# File 'lib/active_genie/entities/players.rb', line 58
def elo_eligible?
eligible.size > 15
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
74
75
76
|
# File 'lib/active_genie/entities/players.rb', line 74
def respond_to_missing?(method_name, include_private = false)
@players.respond_to?(method_name, include_private)
end
|
#score_mean ⇒ Object
34
35
36
37
38
|
# File 'lib/active_genie/entities/players.rb', line 34
def score_mean
return 0 if all_scores.empty?
all_scores.sum.to_f / all_scores.size
end
|
#sorted ⇒ Object
62
63
64
|
# File 'lib/active_genie/entities/players.rb', line 62
def sorted
@players.sort_by { |p| -p.sort_value }
end
|
#to_json(*_args) ⇒ Object
66
67
68
|
# File 'lib/active_genie/entities/players.rb', line 66
def to_json(*_args)
@players.map(&:to_h).to_json
end
|