Class: CrashingTheDance::RpiCalculator::RPI
- Inherits:
-
Object
- Object
- CrashingTheDance::RpiCalculator::RPI
- Defined in:
- lib/crashing_the_dance/rpi_calculator/rpi.rb
Instance Attribute Summary collapse
-
#games ⇒ Object
readonly
Returns the value of attribute games.
-
#losses ⇒ Object
readonly
Returns the value of attribute losses.
-
#rpi_losses ⇒ Object
readonly
Returns the value of attribute rpi_losses.
-
#rpi_wins ⇒ Object
readonly
Returns the value of attribute rpi_wins.
-
#team ⇒ Object
readonly
Returns the value of attribute team.
-
#wins ⇒ Object
readonly
Returns the value of attribute wins.
Instance Method Summary collapse
-
#calculate_oowp(all_teams) ⇒ Object
Now to calculate the opponents’ opponents winning percentage (OOWP), you simply average the OWPs for each of their opponents.
-
#calculate_owp(games_by_team) ⇒ Object
To calculate opponent’s winning percentage (OWP), you remove games against the team in question.
-
#initialize(team, games) ⇒ RPI
constructor
A new instance of RPI.
- #oowp ⇒ Object
- #owp ⇒ Object
- #rpi ⇒ Object
- #rpi_win_percentage ⇒ Object
- #win_percentage ⇒ Object
Constructor Details
#initialize(team, games) ⇒ RPI
Returns a new instance of RPI.
6 7 8 9 10 11 12 13 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 6 def initialize(team, games) @team = team @games = games @owp = 0.0 @oowp = 0.0 @rpi = nil calculate_record end |
Instance Attribute Details
#games ⇒ Object (readonly)
Returns the value of attribute games.
4 5 6 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 4 def games @games end |
#losses ⇒ Object (readonly)
Returns the value of attribute losses.
4 5 6 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 4 def losses @losses end |
#rpi_losses ⇒ Object (readonly)
Returns the value of attribute rpi_losses.
4 5 6 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 4 def rpi_losses @rpi_losses end |
#rpi_wins ⇒ Object (readonly)
Returns the value of attribute rpi_wins.
4 5 6 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 4 def rpi_wins @rpi_wins end |
#team ⇒ Object (readonly)
Returns the value of attribute team.
4 5 6 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 4 def team @team end |
#wins ⇒ Object (readonly)
Returns the value of attribute wins.
4 5 6 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 4 def wins @wins end |
Instance Method Details
#calculate_oowp(all_teams) ⇒ Object
Now to calculate the opponents’ opponents winning percentage (OOWP), you simply average the OWPs for each of their opponents.
59 60 61 62 63 64 65 66 67 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 59 def calculate_oowp(all_teams) if games.count > 0 sum_oowp = games.inject(0.0) do |sum, game| opponent = all_teams.find { |t| game.opponent.eql? t.team } sum + opponent.owp end @oowp = sum_oowp / games.count.to_f end end |
#calculate_owp(games_by_team) ⇒ Object
To calculate opponent’s winning percentage (OWP), you remove games against the team in question. However, for the purpose of calculating OWP and OOWP, use standard WP.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 46 def calculate_owp(games_by_team) if games.count > 0 sum_owp = games.inject(0.0) do |sum, game| sked = opponent_schedule game.opponent, games_by_team ow = sked.inject(0) { |wins, og| wins + og.wins } sum + (sked.empty? ? 0.0 : (ow.to_f / sked.count.to_f)) end @owp = sum_owp / games.count.to_f end end |
#oowp ⇒ Object
35 36 37 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 35 def oowp @oowp end |
#owp ⇒ Object
31 32 33 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 31 def owp @owp end |
#rpi ⇒ Object
39 40 41 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 39 def rpi @rpi ||= calculate_rpi end |
#rpi_win_percentage ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 23 def rpi_win_percentage if games.count > 0 rpi_wins / (rpi_wins + rpi_losses) else 0.0 end end |
#win_percentage ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/crashing_the_dance/rpi_calculator/rpi.rb', line 15 def win_percentage if games.count > 0 wins.to_f / (wins.to_f + losses.to_f) else 0.0 end end |