class Superbowl::BoxScoreHistory

Public Class Methods

new(box_scores) click to toggle source
# File lib/superbowl/box_score_history.rb, line 10
def initialize(box_scores)
  @counts = Array.new(10) { Array.new(10) { 0 } }

  box_scores.each do |box_score|
    x, y = box_score.values_at('x', 'y').map(&:to_i)
    @counts[x][y] += 1
  end

  @num_box_scores = box_scores.count
end
parse(filename) click to toggle source
# File lib/superbowl/box_score_history.rb, line 6
def self.parse(filename)
  new(CSV.open(filename, headers: %w(quarter x y)).to_a)
end

Public Instance Methods

grid_color(row_index, col_index) click to toggle source
# File lib/superbowl/box_score_history.rb, line 30
def grid_color(row_index, col_index)
  hex_val = 15 - (ratio(row_index, col_index) * 100).to_i
  hex_val.to_s(16) * 6
end
probability(row_index, col_index) click to toggle source
# File lib/superbowl/box_score_history.rb, line 26
def probability(row_index, col_index)
  "%.2f%" % (ratio(row_index, col_index) * 100)
end
ratio(row_index, col_index) click to toggle source
# File lib/superbowl/box_score_history.rb, line 21
def ratio(row_index, col_index)
  # TODO: force symmetry?
  @counts[row_index][col_index].to_f / @num_box_scores
end