module CrashingTheDance::RpiCalculator

Constants

VERSION

Public Class Methods

calculate(teams, games) click to toggle source

teams should be valid hash keys (hash and eql?) don’t put any other requirements (e.g., name) also use fixtures to test them. simple, lightweight.

# File lib/crashing_the_dance/rpi_calculator.rb, line 10
def self.calculate(teams, games)
  by_team = games_by_team(teams, games)
  teams = build_rpi teams, by_team
  calculate_owp teams, by_team
  calculate_oowp teams
  calculate_conference_owp teams, by_team
  calculate_conference_oowp teams
  calculate_nonconference_owp teams, by_team
  calculate_nonconference_oowp teams
  teams
end

Private Class Methods

add_team_game(all, game, team) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 75
def self.add_team_game(all, game, team)
  all[team] << OpponentGame.new(game, team) if all.has_key?(team)
end
build_rpi(teams, games_by_team) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 60
def self.build_rpi(teams, games_by_team)
  teams.map { |team| RPI.new team, games_by_team[team] }
end
calculate_conference_oowp(teams) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 36
def self.calculate_conference_oowp(teams)
  teams.each do |team|
    team.calculate_conference_oowp teams
  end
end
calculate_conference_owp(teams, games_by_team) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 42
def self.calculate_conference_owp(teams, games_by_team)
  teams.each do |team|
    team.calculate_conference_owp(games_by_team)
  end
end
calculate_nonconference_oowp(teams) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 48
def self.calculate_nonconference_oowp(teams)
  teams.each do |team|
    team.calculate_nonconference_oowp teams
  end
end
calculate_nonconference_owp(teams, games_by_team) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 54
def self.calculate_nonconference_owp(teams, games_by_team)
  teams.each do |team|
    team.calculate_nonconference_owp(games_by_team)
  end
end
calculate_oowp(teams) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 24
def self.calculate_oowp(teams)
  teams.each do |team|
    team.calculate_oowp teams
  end
end
calculate_owp(teams, games_by_team) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 30
def self.calculate_owp(teams, games_by_team)
  teams.each do |team|
    team.calculate_owp(games_by_team)
  end
end
games_by_team(teams, games) click to toggle source
# File lib/crashing_the_dance/rpi_calculator.rb, line 64
def self.games_by_team(teams, games)
  all = teams.inject({}) { |a, team| a[team] = [ ]; a }
  games.each do |game|
    # has to be a cleaner way than this
    # exception if neither matches?
    add_team_game all, game, game.vis_team
    add_team_game all, game, game.home_team
  end
  all
end