Plugin Directory

Changeset 526301


Ignore:
Timestamp:
04/02/2012 03:52:11 PM (14 years ago)
Author:
davidn.de
Message:

Remove creative common licenced code and implemented own elo rating algorithm.

Location:
elo-rating
Files:
3 edited
8 copied

Legend:

Unmodified
Added
Removed
  • elo-rating/tags/0.6/README.txt

    r526262 r526301  
    55Requires at least: 3.0
    66Tested up to: 3.3.1
    7 Stable tag: 0.5
     7Stable tag: 0.6
    88
    99With this plugin you can let users rate posts agains each other just like it worked with pictures on the famous facemash by Mark Zuckerberg.
     
    5252== Changelog ==
    5353
     54= 0.6 =
     55- Implemented own elo algorithm.
     56
    5457= 0.5 =
    5558- Fixed version number.
  • elo-rating/tags/0.6/elo-rating-algorithm.php

    r526245 r526301  
    11<?php
     2
    23/**
    3 * This class calculates ratings based on the Elo system used in chess.
    4 *
    5 * @author Priyesh Patel <priyesh@pexat.com> & Michal Chovanec <michalchovaneceu@gmail.com>
    6 * @copyright Copyright (c) 2011 onwards, Priyesh Patel
    7 * @license Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
    8 */
    9 class EloRatingAlgorithm
    10 {
    11 
    12     /**
    13 * @var int The K Factor used.
    14 */
    15     const KFACTOR = 16;
    16 
    17     /**
    18 * Protected & private variables.
    19 */
    20     protected $_ratingA;
    21     protected $_ratingB;
    22    
    23     protected $_scoreA;
    24     protected $_scoreB;
    25 
    26     protected $_expectedA;
    27     protected $_expectedB;
    28 
    29     protected $_newRatingA;
    30     protected $_newRatingB;
    31 
    32     /**
    33 * Costructor function which does all the maths and stores the results ready
    34 * for retrieval.
    35 *
    36 * @param int Current rating of A
    37 * @param int Current rating of B
    38 * @param int Score of A
    39 * @param int Score of B
    40 */
    41     public function __construct($ratingA,$ratingB,$scoreA,$scoreB)
    42     {
    43         $this->_ratingA = $ratingA;
    44         $this->_ratingB = $ratingB;
    45         $this->_scoreA = $scoreA;
    46         $this->_scoreB = $scoreB;
    47 
    48         $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
    49         $this->_expectedA = $expectedScores['a'];
    50         $this->_expectedB = $expectedScores['b'];
    51 
    52         $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
    53         $this->_newRatingA = $newRatings['a'];
    54         $this->_newRatingB = $newRatings['b'];
    55     }
    56 
    57     /**
    58 * Set new input data.
    59 *
    60 * @param int Current rating of A
    61 * @param int Current rating of B
    62 * @param int Score of A
    63 * @param int Score of B
    64 */
    65     public function setNewSettings($ratingA,$ratingB,$scoreA,$scoreB)
    66     {
    67         $this -> _ratingA = $ratingA;
    68         $this -> _ratingB = $ratingB;
    69         $this -> _scoreA = $scoreA;
    70         $this -> _scoreB = $scoreB;
    71 
    72         $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
    73         $this -> _expectedA = $expectedScores['a'];
    74         $this -> _expectedB = $expectedScores['b'];
    75 
    76         $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
    77         $this -> _newRatingA = $newRatings['a'];
    78         $this -> _newRatingB = $newRatings['b'];
    79     }
    80 
    81     /**
    82 * Retrieve the calculated data.
    83 *
    84 * @return Array An array containing the new ratings for A and B.
    85 */
    86     public function getNewRatings()
    87     {
    88         return array (
    89             'a' => $this -> _newRatingA,
    90             'b' => $this -> _newRatingB
    91         );
    92     }
    93 
    94     /**
    95 * Protected & private functions begin here
    96 */
    97 
    98     protected function _getExpectedScores($ratingA,$ratingB)
    99     {
    100         $expectedScoreA = 1 / ( 1 + ( pow( 10 , ( $ratingB - $ratingA ) / 400 ) ) );
    101         $expectedScoreB = 1 / ( 1 + ( pow( 10 , ( $ratingA - $ratingB ) / 400 ) ) );
    102 
    103         return array (
    104             'a' => $expectedScoreA,
    105             'b' => $expectedScoreB
    106         );
    107     }
    108 
    109     protected function _getNewRatings($ratingA,$ratingB,$expectedA,$expectedB,$scoreA,$scoreB)
    110     {
    111         $newRatingA = $ratingA + ( self::KFACTOR * ( $scoreA - $expectedA ) );
    112         $newRatingB = $ratingB + ( self::KFACTOR * ( $scoreB - $expectedB ) );
    113 
    114         return array (
    115             'a' => $newRatingA,
    116             'b' => $newRatingB
    117         );
    118     }
    119 
     4 * Function to calculate ratings based on the Elo system used in chess.
     5 *
     6 * We use a K-Factor of 16.
     7 *
     8 * @param unknown_type $rating_a
     9 * @param unknown_type $rating_b
     10 * @param unknown_type $score_a
     11 * @param unknown_type $score_b
     12 */
     13function elo_rating__calculate_ratings($rating_a,$rating_b,$score_a,$score_b) {
     14  $expected_a = 1 / ( 1 + ( pow( 10 , ( $rating_b - $rating_a ) / 400 ) ) );
     15  $expected_b = 1 / ( 1 + ( pow( 10 , ( $rating_a - $rating_b ) / 400 ) ) );
     16 
     17  $new_rating_a = $rating_a + ( 16 * ( $score_a - $expected_a ) );
     18  $new_rating_b = $rating_b + ( 16 * ( $score_b - $expected_b ) );
     19 
     20  return array(
     21    'a' => $new_rating_a,
     22    'b' => $new_rating_b,
     23  );
    12024}
  • elo-rating/tags/0.6/elo-rating.php

    r526262 r526301  
    44Plugin URI: http://davidn.de
    55Description: With this plugin you can let users <strong>rate posts agains each other</strong> just like it worked with pictures on the famous facemash by Mark Zuckerberg. The likes are triggered by a <strong>facebook like button</strong>.
    6 Version: 0.5
     6Version: 0.6
    77Author: David Nellessen
    88Author URI: http://davidn.de
     
    2727
    2828// Define environement vars.
    29 define('ELO_RATING_VERSION', '0.5');
     29define('ELO_RATING_VERSION', '0.6');
    3030
    3131/**
     
    259259 
    260260  // Calculate new ratings
    261   $handler = new EloRatingAlgorithm($current_rating_win, $current_rating_lost, $score_win, $score_lost );
    262  
     261  $new_ratings = elo_rating__calculate_ratings($current_rating_win, $current_rating_lost, $score_win, $score_lost );
    263262  //Save new ratings.
    264   $new_ratings = $handler->getNewRatings();
    265   update_post_meta($post_win, 'elo_rating__rating', $new_ratings[a], $current_rating_win);
    266   update_post_meta($post_lost, 'elo_rating__rating', $new_ratings[b], $current_rating_lost);
    267 }
     263  update_post_meta($post_win, 'elo_rating__rating', $new_ratings['a'], $current_rating_win);
     264  update_post_meta($post_lost, 'elo_rating__rating', $new_ratings['b'], $current_rating_lost);
     265}
  • elo-rating/trunk/README.txt

    r526262 r526301  
    55Requires at least: 3.0
    66Tested up to: 3.3.1
    7 Stable tag: 0.5
     7Stable tag: 0.6
    88
    99With this plugin you can let users rate posts agains each other just like it worked with pictures on the famous facemash by Mark Zuckerberg.
     
    5252== Changelog ==
    5353
     54= 0.6 =
     55- Implemented own elo algorithm.
     56
    5457= 0.5 =
    5558- Fixed version number.
  • elo-rating/trunk/elo-rating-algorithm.php

    r526245 r526301  
    11<?php
     2
    23/**
    3 * This class calculates ratings based on the Elo system used in chess.
    4 *
    5 * @author Priyesh Patel <priyesh@pexat.com> & Michal Chovanec <michalchovaneceu@gmail.com>
    6 * @copyright Copyright (c) 2011 onwards, Priyesh Patel
    7 * @license Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
    8 */
    9 class EloRatingAlgorithm
    10 {
    11 
    12     /**
    13 * @var int The K Factor used.
    14 */
    15     const KFACTOR = 16;
    16 
    17     /**
    18 * Protected & private variables.
    19 */
    20     protected $_ratingA;
    21     protected $_ratingB;
    22    
    23     protected $_scoreA;
    24     protected $_scoreB;
    25 
    26     protected $_expectedA;
    27     protected $_expectedB;
    28 
    29     protected $_newRatingA;
    30     protected $_newRatingB;
    31 
    32     /**
    33 * Costructor function which does all the maths and stores the results ready
    34 * for retrieval.
    35 *
    36 * @param int Current rating of A
    37 * @param int Current rating of B
    38 * @param int Score of A
    39 * @param int Score of B
    40 */
    41     public function __construct($ratingA,$ratingB,$scoreA,$scoreB)
    42     {
    43         $this->_ratingA = $ratingA;
    44         $this->_ratingB = $ratingB;
    45         $this->_scoreA = $scoreA;
    46         $this->_scoreB = $scoreB;
    47 
    48         $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
    49         $this->_expectedA = $expectedScores['a'];
    50         $this->_expectedB = $expectedScores['b'];
    51 
    52         $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
    53         $this->_newRatingA = $newRatings['a'];
    54         $this->_newRatingB = $newRatings['b'];
    55     }
    56 
    57     /**
    58 * Set new input data.
    59 *
    60 * @param int Current rating of A
    61 * @param int Current rating of B
    62 * @param int Score of A
    63 * @param int Score of B
    64 */
    65     public function setNewSettings($ratingA,$ratingB,$scoreA,$scoreB)
    66     {
    67         $this -> _ratingA = $ratingA;
    68         $this -> _ratingB = $ratingB;
    69         $this -> _scoreA = $scoreA;
    70         $this -> _scoreB = $scoreB;
    71 
    72         $expectedScores = $this -> _getExpectedScores($this -> _ratingA,$this -> _ratingB);
    73         $this -> _expectedA = $expectedScores['a'];
    74         $this -> _expectedB = $expectedScores['b'];
    75 
    76         $newRatings = $this ->_getNewRatings($this -> _ratingA, $this -> _ratingB, $this -> _expectedA, $this -> _expectedB, $this -> _scoreA, $this -> _scoreB);
    77         $this -> _newRatingA = $newRatings['a'];
    78         $this -> _newRatingB = $newRatings['b'];
    79     }
    80 
    81     /**
    82 * Retrieve the calculated data.
    83 *
    84 * @return Array An array containing the new ratings for A and B.
    85 */
    86     public function getNewRatings()
    87     {
    88         return array (
    89             'a' => $this -> _newRatingA,
    90             'b' => $this -> _newRatingB
    91         );
    92     }
    93 
    94     /**
    95 * Protected & private functions begin here
    96 */
    97 
    98     protected function _getExpectedScores($ratingA,$ratingB)
    99     {
    100         $expectedScoreA = 1 / ( 1 + ( pow( 10 , ( $ratingB - $ratingA ) / 400 ) ) );
    101         $expectedScoreB = 1 / ( 1 + ( pow( 10 , ( $ratingA - $ratingB ) / 400 ) ) );
    102 
    103         return array (
    104             'a' => $expectedScoreA,
    105             'b' => $expectedScoreB
    106         );
    107     }
    108 
    109     protected function _getNewRatings($ratingA,$ratingB,$expectedA,$expectedB,$scoreA,$scoreB)
    110     {
    111         $newRatingA = $ratingA + ( self::KFACTOR * ( $scoreA - $expectedA ) );
    112         $newRatingB = $ratingB + ( self::KFACTOR * ( $scoreB - $expectedB ) );
    113 
    114         return array (
    115             'a' => $newRatingA,
    116             'b' => $newRatingB
    117         );
    118     }
    119 
     4 * Function to calculate ratings based on the Elo system used in chess.
     5 *
     6 * We use a K-Factor of 16.
     7 *
     8 * @param unknown_type $rating_a
     9 * @param unknown_type $rating_b
     10 * @param unknown_type $score_a
     11 * @param unknown_type $score_b
     12 */
     13function elo_rating__calculate_ratings($rating_a,$rating_b,$score_a,$score_b) {
     14  $expected_a = 1 / ( 1 + ( pow( 10 , ( $rating_b - $rating_a ) / 400 ) ) );
     15  $expected_b = 1 / ( 1 + ( pow( 10 , ( $rating_a - $rating_b ) / 400 ) ) );
     16 
     17  $new_rating_a = $rating_a + ( 16 * ( $score_a - $expected_a ) );
     18  $new_rating_b = $rating_b + ( 16 * ( $score_b - $expected_b ) );
     19 
     20  return array(
     21    'a' => $new_rating_a,
     22    'b' => $new_rating_b,
     23  );
    12024}
  • elo-rating/trunk/elo-rating.php

    r526262 r526301  
    44Plugin URI: http://davidn.de
    55Description: With this plugin you can let users <strong>rate posts agains each other</strong> just like it worked with pictures on the famous facemash by Mark Zuckerberg. The likes are triggered by a <strong>facebook like button</strong>.
    6 Version: 0.5
     6Version: 0.6
    77Author: David Nellessen
    88Author URI: http://davidn.de
     
    2727
    2828// Define environement vars.
    29 define('ELO_RATING_VERSION', '0.5');
     29define('ELO_RATING_VERSION', '0.6');
    3030
    3131/**
     
    259259 
    260260  // Calculate new ratings
    261   $handler = new EloRatingAlgorithm($current_rating_win, $current_rating_lost, $score_win, $score_lost );
    262  
     261  $new_ratings = elo_rating__calculate_ratings($current_rating_win, $current_rating_lost, $score_win, $score_lost );
    263262  //Save new ratings.
    264   $new_ratings = $handler->getNewRatings();
    265   update_post_meta($post_win, 'elo_rating__rating', $new_ratings[a], $current_rating_win);
    266   update_post_meta($post_lost, 'elo_rating__rating', $new_ratings[b], $current_rating_lost);
    267 }
     263  update_post_meta($post_win, 'elo_rating__rating', $new_ratings['a'], $current_rating_win);
     264  update_post_meta($post_lost, 'elo_rating__rating', $new_ratings['b'], $current_rating_lost);
     265}
Note: See TracChangeset for help on using the changeset viewer.