Class: Superbowl::BoxScoreHistory

Inherits:
Object
  • Object
show all
Defined in:
lib/superbowl/box_score_history.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(box_scores) ⇒ BoxScoreHistory

Returns a new instance of BoxScoreHistory.



10
11
12
13
14
15
16
17
18
19
# 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

Class Method Details

.parse(filename) ⇒ Object



6
7
8
# 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

Instance Method Details

#grid_color(row_index, col_index) ⇒ Object



30
31
32
33
# 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) ⇒ Object



26
27
28
# 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) ⇒ Object



21
22
23
24
# 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