2017 © Pedro Peláez
 

library elo

A PHP implementation of Elo rating system

image

zelenin/elo

A PHP implementation of Elo rating system

  • Tuesday, June 17, 2014
  • by zelenin
  • Repository
  • 1 Watchers
  • 14 Stars
  • 1,555 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 2 Versions
  • 1 % Grown

The README.md

Elo

A PHP implementation of Elo rating system, (*1)

Installation

Composer

The preferred way to install this extension is through Composer., (*2)

Either run, (*3)

php composer.phar require zelenin/elo "dev-master"

or add, (*4)

"zelenin/elo": "dev-master"

to the require section of your composer.json, (*5)

Usage

Create two players with current ratings:, (*6)

use Zelenin\Elo\Player;

$player1 = new Player(1200);
$player2 = new Player(800);

Create match:, (*7)

use Zelenin\Elo\Match;

$match = new Match($player1, $player2);
$match->setScore(1, 0)
    ->setK(32)
    ->count();

Get players:, (*8)

$player1 = $match->getPlayer1();
$player2 = $match->getPlayer2();

Get new ratings:, (*9)

$newRating1 = $player1->getRating();
$newRating2 = $player2->getRating();

Advanced usage

If you want use this library for not-traditional for Elo sports like football, ice hockey, basketball, you may set additional handlers for setting goal index and home correction., (*10)

use Zelenin\Elo\Match;
use Zelenin\Elo\Player;

$player1 = new Player(1200);
$player2 = new Player(800);

$goalIndexHandler = function ($score1, $score2) {
    $diff = abs($score1 - $score2);
    if ($diff > 0) {
        return sqrt($diff);
    }
    return 1;
};

$homeCorrectionHandler = function ($home, $diff) {
    $coefficient = 100;
    if ($home == 1) {
        return $diff - $coefficient;
    }
    if ($home == 2) {
        return $diff + $coefficient;
    }
    return $diff;
};

$match = new Match($player1, $player2);
$match->setScore(1, 0)
    ->setK(32)
    ->setGoalIndexHandler($goalIndexHandler)
    ->setHome(2)
    ->setHomeCorrectionHandler($homeCorrectionHandler)
    ->count();

$newRating1 = $player1->getRating();
$newRating2 = $player2->getRating();

Info

See Wiki about Elo rating system, (*11)

Author

Aleksandr Zelenin, e-mail: aleksandr@zelenin.me, (*12)

The Versions

17/06 2014

dev-master

9999999-dev https://github.com/zelenin/elo

A PHP implementation of Elo rating system

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

rating elo ranking

17/06 2014

0.0.1

0.0.1.0 https://github.com/zelenin/elo

A PHP implementation of Elo rating system

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

rating elo ranking