Class: FullReview

Inherits:
Object
  • Object
show all
Defined in:
lib/ogs_katacheck/full_review.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ FullReview

Returns a new instance of FullReview.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ogs_katacheck/full_review.rb', line 7

def initialize(attributes)
  attributes.each {|key, value| self.send(("#{key}="), value)}
  @black_tier_1 = [0, 0]
  @black_tier_2 = [0, 0]
  @black_tier_3 = [0, 0]
  @black_tier_4 = [0, 0]
  @black_total = [0, 0]
  @white_total = [0, 0]
  @white_tier_1 = [0, 0]
  @white_tier_2 = [0, 0]
  @white_tier_3 = [0, 0]
  @white_tier_4 = [0, 0]

  @@all << self
end

Instance Attribute Details

#black_tier_1Object

Returns the value of attribute black_tier_1.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def black_tier_1
  @black_tier_1
end

#black_tier_2Object

Returns the value of attribute black_tier_2.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def black_tier_2
  @black_tier_2
end

#black_tier_3Object

Returns the value of attribute black_tier_3.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def black_tier_3
  @black_tier_3
end

#black_tier_4Object

Returns the value of attribute black_tier_4.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def black_tier_4
  @black_tier_4
end

#black_totalObject

Returns the value of attribute black_total.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def black_total
  @black_total
end

#dateObject

Returns the value of attribute date.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def date
  @date
end

#engineObject

Returns the value of attribute engine.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def engine
  @engine
end

#engine_versionObject

Returns the value of attribute engine_version.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def engine_version
  @engine_version
end

#game_idObject

Returns the value of attribute game_id.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def game_id
  @game_id
end

#idObject

Returns the value of attribute id.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def id
  @id
end

#movesObject

Returns the value of attribute moves.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def moves
  @moves
end

#networkObject

Returns the value of attribute network.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def network
  @network
end

#network_sizeObject

Returns the value of attribute network_size.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def network_size
  @network_size
end

#scoresObject

Returns the value of attribute scores.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def scores
  @scores
end

#strengthObject

Returns the value of attribute strength.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def strength
  @strength
end

#total_movesObject

Returns the value of attribute total_moves.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def total_moves
  @total_moves
end

#typeObject

Returns the value of attribute type.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def type
  @type
end

#uuidObject

Returns the value of attribute uuid.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def uuid
  @uuid
end

#white_tier_1Object

Returns the value of attribute white_tier_1.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def white_tier_1
  @white_tier_1
end

#white_tier_2Object

Returns the value of attribute white_tier_2.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def white_tier_2
  @white_tier_2
end

#white_tier_3Object

Returns the value of attribute white_tier_3.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def white_tier_3
  @white_tier_3
end

#white_tier_4Object

Returns the value of attribute white_tier_4.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def white_tier_4
  @white_tier_4
end

#white_totalObject

Returns the value of attribute white_total.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def white_total
  @white_total
end

#win_rateObject

Returns the value of attribute win_rate.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def win_rate
  @win_rate
end

#win_ratesObject

Returns the value of attribute win_rates.



2
3
4
# File 'lib/ogs_katacheck/full_review.rb', line 2

def win_rates
  @win_rates
end

Class Method Details

.allObject



23
24
25
# File 'lib/ogs_katacheck/full_review.rb', line 23

def self.all
  @@all
end

.destroy_allObject



27
28
29
# File 'lib/ogs_katacheck/full_review.rb', line 27

def self.destroy_all
  self.all.clear
end

Instance Method Details

#calculate_percentagesObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ogs_katacheck/full_review.rb', line 31

def calculate_percentages
  white_moves = (@total_moves / 2.0).floor
  black_moves = (@total_moves / 2.0).ceil

  @black_tier_1[1] = @black_tier_1[0].to_f / black_moves * 100
  @black_tier_2[1] = @black_tier_2[0].to_f / black_moves * 100
  @black_tier_3[1] = @black_tier_3[0].to_f / black_moves * 100
  @black_tier_4[1] = @black_tier_4[0].to_f / black_moves * 100
  @white_tier_1[1] = @white_tier_1[0].to_f / white_moves * 100
  @white_tier_2[1] = @white_tier_2[0].to_f / white_moves * 100
  @white_tier_3[1] = @white_tier_3[0].to_f / white_moves * 100
  @white_tier_4[1] = @white_tier_4[0].to_f / white_moves * 100

  @black_total[0] = @black_tier_1[0] + @black_tier_2[0] + @black_tier_3[0] + @black_tier_4[0]
  @white_total[0] = @white_tier_1[0] + @white_tier_2[0] + @white_tier_3[0] + @white_tier_4[0]

  @white_total[1] = @white_tier_1[1] + @white_tier_2[1] + @white_tier_3[1] + @white_tier_4[1]
  @black_total[1] = @black_tier_1[1] + @black_tier_2[1] + @black_tier_3[1] + @black_tier_4[1]
end

#processObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/ogs_katacheck/full_review.rb', line 52

def process
  @total_moves = @moves.count;

  @moves.each do |move|
    current_move = move[1]["move_number"]
    previous_move = @moves[(current_move.to_i - 1).to_s]
    move_made = move[1]["move"]
    if current_move.to_i >= 2
      if previous_move["branches"][0]["moves"][0] == move_made
        current_move % 2 == 0 ? @white_tier_1[0] += 1 : @black_tier_1[0] += 1
      elsif previous_move["branches"].count >= 2 && previous_move["branches"][1]["moves"][0] == move_made
        current_move % 2 == 0 ? @white_tier_2[0] += 1 : @black_tier_2[0] += 1
      elsif previous_move["branches"].count >= 3 && previous_move["branches"][2]["moves"][0] == move_made
        current_move % 2 == 0 ? @white_tier_3[0] += 1 : @black_tier_3[0] += 1
      elsif previous_move["branches"].count >= 4 && previous_move["branches"][3]["moves"][0] == move_made
        current_move % 2 == 0 ? @white_tier_4[0] += 1 : @black_tier_4[0] += 1
      end
    end
  end
  calculate_percentages
end