Changeset 526301
- Timestamp:
- 04/02/2012 03:52:11 PM (14 years ago)
- Location:
- elo-rating
- Files:
-
- 3 edited
- 8 copied
-
tags/0.6 (copied) (copied from elo-rating/trunk)
-
tags/0.6/README.txt (copied) (copied from elo-rating/trunk/README.txt) (2 diffs)
-
tags/0.6/css (copied) (copied from elo-rating/trunk/css)
-
tags/0.6/css/frontend.css (copied) (copied from elo-rating/trunk/css/frontend.css)
-
tags/0.6/elo-rating-algorithm.php (copied) (copied from elo-rating/trunk/elo-rating-algorithm.php) (1 diff)
-
tags/0.6/elo-rating.php (copied) (copied from elo-rating/trunk/elo-rating.php) (3 diffs)
-
tags/0.6/js (copied) (copied from elo-rating/trunk/js)
-
tags/0.6/screenshot-1.png (copied) (copied from elo-rating/trunk/screenshot-1.png)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/elo-rating-algorithm.php (modified) (1 diff)
-
trunk/elo-rating.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
elo-rating/tags/0.6/README.txt
r526262 r526301 5 5 Requires at least: 3.0 6 6 Tested up to: 3.3.1 7 Stable tag: 0. 57 Stable tag: 0.6 8 8 9 9 With this plugin you can let users rate posts agains each other just like it worked with pictures on the famous facemash by Mark Zuckerberg. … … 52 52 == Changelog == 53 53 54 = 0.6 = 55 - Implemented own elo algorithm. 56 54 57 = 0.5 = 55 58 - Fixed version number. -
elo-rating/tags/0.6/elo-rating-algorithm.php
r526245 r526301 1 1 <?php 2 2 3 /** 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 */ 13 function 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 ); 120 24 } -
elo-rating/tags/0.6/elo-rating.php
r526262 r526301 4 4 Plugin URI: http://davidn.de 5 5 Description: 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. 56 Version: 0.6 7 7 Author: David Nellessen 8 8 Author URI: http://davidn.de … … 27 27 28 28 // Define environement vars. 29 define('ELO_RATING_VERSION', '0. 5');29 define('ELO_RATING_VERSION', '0.6'); 30 30 31 31 /** … … 259 259 260 260 // 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 ); 263 262 //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 5 5 Requires at least: 3.0 6 6 Tested up to: 3.3.1 7 Stable tag: 0. 57 Stable tag: 0.6 8 8 9 9 With this plugin you can let users rate posts agains each other just like it worked with pictures on the famous facemash by Mark Zuckerberg. … … 52 52 == Changelog == 53 53 54 = 0.6 = 55 - Implemented own elo algorithm. 56 54 57 = 0.5 = 55 58 - Fixed version number. -
elo-rating/trunk/elo-rating-algorithm.php
r526245 r526301 1 1 <?php 2 2 3 /** 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 */ 13 function 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 ); 120 24 } -
elo-rating/trunk/elo-rating.php
r526262 r526301 4 4 Plugin URI: http://davidn.de 5 5 Description: 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. 56 Version: 0.6 7 7 Author: David Nellessen 8 8 Author URI: http://davidn.de … … 27 27 28 28 // Define environement vars. 29 define('ELO_RATING_VERSION', '0. 5');29 define('ELO_RATING_VERSION', '0.6'); 30 30 31 31 /** … … 259 259 260 260 // 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 ); 263 262 //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.