Class: Olympic::Rating::Glicko
- 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
-
.required_fields ⇒ Hash{Symbol => Array<(Symbol, Hash)>}
Returns a hash of the fields that are required on a Team to make it compatible with the rating system.
Instance Method Summary collapse
- #derivation ⇒ Object
-
#initialize(team) ⇒ Glicko
constructor
A new instance of Glicko.
- #rating ⇒ Object
- #time_passed ⇒ Object
- #unrated? ⇒ Boolean
-
#update(matches) ⇒ void
Updates the rating with the given match information.
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_fields ⇒ Hash{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.
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
#derivation ⇒ Object
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 |
#rating ⇒ Object
47 48 49 |
# File 'lib/olympic/rating/glicko.rb', line 47 def @team. ||= 1500 end |
#time_passed ⇒ Object
66 67 68 69 |
# File 'lib/olympic/rating/glicko.rb', line 66 def time_passed # TODO 0 end |
#unrated? ⇒ Boolean
71 72 73 |
# File 'lib/olympic/rating/glicko.rb', line 71 def unrated? @team. == 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.
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 |