Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zachallaun/relative
Support for relative rating systems à la Elo
https://github.com/zachallaun/relative
Last synced: 11 days ago
JSON representation
Support for relative rating systems à la Elo
- Host: GitHub
- URL: https://github.com/zachallaun/relative
- Owner: zachallaun
- Created: 2012-08-02T19:09:33.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2013-11-10T15:10:25.000Z (almost 11 years ago)
- Last Synced: 2024-10-11T19:20:03.769Z (27 days ago)
- Language: Clojure
- Homepage:
- Size: 166 KB
- Stars: 12
- Watchers: 6
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Relative
*Relative is a Clojure library supporting relative rating systems such as Elo or TrueSkill.*
```clj
[relative "0.1.2"]
```### Use
Relative currently supports two rating engines: Elo (`relative.elo/elo-engine`) and TrueSkill (`relative.trueskill/trueskill-engine`).
Both engines implement the same protocol, `IRelativeRatingEngine`, and support the following functions:
#### `(player [engine map])`
Creates a player data structure that implements `IRelativelyRatedPlayer`. A call to `rating` should return that player's current rating.
#### `(match [engine winner loser])`
Represents a match played against two players, and returns a vector pair of updated players given the outcome of the match.
#### `(match-quality [engine p1 p2])`
This returns a match quality score given a hypothetical match between two players. A high quality match is considered to be a match where there is a high likelihood of a draw.
#### `(serialize [engine entities])`
Serializes a sequence of player entities into a string representation that could be stored.
#### `(resurrect [engine serialized])`
Returns a sequence of player entities based on the serialized form.
### Example
```clj
(ns elo-example
(:require [relative.elo :as elo])
(:use relative.rating));; We'll use the Elo engine
(def elo-engine (elo/elo-engine));; Create two players with default ratings of 1500.
(def player1 (player elo-engine {:id "Zach"}))
(def player2 (player elo-engine {:id "James"}))(rating player1) ;; => 1500
;; player1 wins the first match.
(match elo-engine player1 player2) ;; => [{:id "Zach" :rating 1516.0}
;; {:id "James" :rating 1484.0}](rating player1) ;; => 1516.0
;; player2 wins the second match.
(match elo-engine player2 player1) ;; => [{:id "James" :rating 1501.4695}
;; {:id "Zach" :rating 1498.5305}]
```