Class: Olympic::Rating::Glicko

Inherits:
Base
  • Object
show all
Extended by:
Forwardable, Memoist
Defined in:
lib/olympic/rating/glicko.rb,
lib/olympic/rating/glicko/formula.rb

Overview

The Glicko rating system. This is Glicko, not Glicko2.

Defined Under Namespace

Classes: Formula

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(team) ⇒ Glicko

Returns a new instance of Glicko.



32
33
34
# File 'lib/olympic/rating/glicko.rb', line 32

def initialize(team)
  @team = team
end

Class Method Details

.required_fieldsHash{Symbol => Array<(Symbol, Hash)>}

Returns a hash of the fields that are required on a Team to make it compatible with the rating system. The base API requires no fields. However, if it were to require a ‘:rating` decimal field, it would have a value of something like this:

{ rating: [:decimal, { null: false, default: 100.2 }] }

The key is the name of the field, the value are options that are passed as options to the SQL column.

Returns:

  • (Hash{Symbol => Array<(Symbol, Hash)>})


23
24
25
26
27
28
29
30
# File 'lib/olympic/rating/glicko.rb', line 23

def self.required_fields
  {
    rating:     [:float, { null: false,
                           default: Formula::DEFAULT_RATING }],
    derivation: [:float, { null: false,
                           default: Formula::DEFAULT_RATING_DERIVATION }]
  }
end

Instance Method Details

#derivationObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/olympic/rating/glicko.rb', line 51

def derivation
  case
  when unrated?         then 350
  when time_passed == 0 then @team.derivation
  else
    [
      30,
      Math.sqrt(@team.derivation ** 2 +
        CERTAINTY_DECAY * time_passed),
      350
    ].sort[1]
  end
end

#ratingObject



47
48
49
# File 'lib/olympic/rating/glicko.rb', line 47

def rating
  @team.rating ||= 1500
end

#time_passedObject



66
67
68
69
# File 'lib/olympic/rating/glicko.rb', line 66

def time_passed
  # TODO
  0
end

#unrated?Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/olympic/rating/glicko.rb', line 71

def unrated?
  @team.rating == nil && @team.derivation == nil
end

#update(matches) ⇒ void

This method returns an undefined value.

Updates the rating with the given match information. Matches should be an array of hashes that contain information about those matches.

Parameters:



42
43
44
45
# File 'lib/olympic/rating/glicko.rb', line 42

def update(matches)
  standardized = standardize_matches(matches)
  Formula.new(self, standardized).call
end