<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Karma</title>
		<link>http://org.wikidot.com/forum/t-85716/karma</link>
		<description>Posts in the discussion thread &quot;Karma&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Thu, 21 May 2026 13:15:00 +0000</lastBuildDate>
		
					<item>
				<guid>http://org.wikidot.com/forum/t-85716#post-5811954</guid>
				<title>Re: Karma</title>
				<link>http://org.wikidot.com/forum/t-85716/karma#post-5811954</link>
				<description></description>
				<pubDate>Wed, 04 Jan 2023 22:49:58 +0000</pubDate>
								<wikidot:authorUserId>8402548</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>i have level 1 on my Karma level</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://org.wikidot.com/forum/t-85716#post-251881</guid>
				<title>Re: Karma</title>
				<link>http://org.wikidot.com/forum/t-85716/karma#post-251881</link>
				<description></description>
				<pubDate>Tue, 02 Sep 2008 20:49:45 +0000</pubDate>
								<wikidot:authorUserId>38854</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Inspect this file to see how it's calculated:</p> <blockquote> <p><strong><em>/var/www/wikidot/php/utils/KarmaCalculator.php</em></strong></p> </blockquote> <p>It looks to be well commented to make it easy to establish your own set of rules. I've pasted the code into the collapsible block below.</p> <p>-Ed</p> <div class="collapsible-block"> <div class="collapsible-block-folded"><a class="collapsible-block-link" href="javascript:;">Show&nbsp;KarmaCalculator.php</a></div> <div class="collapsible-block-unfolded" style="display:none"> <div class="collapsible-block-unfolded-link"><a class="collapsible-block-link" href="javascript:;">Hide&nbsp;Block</a></div> <div class="collapsible-block-content"> <div class="code"> <pre><code>&lt;?php /** * Wikidot - free wiki collaboration software * Copyright (c) 2008, Wikidot Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * For more information about licensing visit: * http://www.wikidot.org/license * * @category Wikidot * @package Wikidot * @version $Id$ * @copyright Copyright (c) 2008, Wikidot Inc. * @license http://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License */ class KarmaCalculator { protected $_rules = array(); public function __construct(){ /* Init rules. */ $rulesPath = WIKIDOT_ROOT.'/php/utils/karmarules/'; $files = ls($rulesPath, '*.php'); foreach($files as $f){ require_once($rulesPath.'/'.$f); $cn = str_replace('.php', '', basename($f)); $this-&gt;_rules[] = new $cn(); } } public function calculate($user){ $p = 0; foreach($this-&gt;_rules as $rule) { $p += $rule-&gt;calculate($user); } return $p; } public function update($user){ $p = $this-&gt;calculate($user); /* Get the karma object. */ $c = new Criteria(); $c-&gt;add('user_id', $user-&gt;getUserId()); $karma = DB_UserKarmaPeer::instance()-&gt;selectOne($c); if(!$karma){ $karma = new DB_UserKarma(); $karma-&gt;setUserId($user-&gt;getUserId()); } $karma-&gt;setPoints($p); $karma-&gt;save(); } public function updateLevels(){ /* How many points you need to have to get to a level. */ $minPointsLevel1 = 30; $minPointsLevel2 = 100; $minPointsLevel3 = 200; $minPointsLevel4 = 300; $minPointsLevel5 = 500; /* Once you pass this limit, we will not take your level5 limit back. */ $keepLevel5Limit = 1000; /* Calculate the distribution. */ $db = Database::$connection; $totalUsers = DB_UserKarmaPeer::instance()-&gt;selectCount(); /* Make karma=none for non-active users. */ $q = &quot;UPDATE user_karma SET level=0 WHERE points &lt; $minPointsLevel1&quot;; $db-&gt;query($q); /* Calculate total users but excluding these with less that $minPointsLevel1 points. */ $c = new Criteria(); $c-&gt;add('points', $minPointsLevel1, '&gt;='); $totalUsers = DB_UserKarmaPeer::instance()-&gt;selectCount($c); /* Number of users to fall into a given level. */ $limits = array(); $limitLevel5 = ceil($totalUsers * 0.05); $limitLevel4 = ceil($totalUsers * 0.10); $limitLevel3 = ceil($totalUsers * 0.20); $limitLevel2 = ceil($totalUsers * 0.30); //$c = new Criteria(); //$c-&gt;add('points', $minPointsLevel5, '.='); //$c-&gt;setLimit() /* Set level one by default. */ $q = array(); $q[] = &quot;UPDATE user_karma SET level=1 WHERE points &gt;= $minPointsLevel1 AND (level &lt; 5 OR points &lt; $keepLevel5Limit)&quot;; $q[] = &quot;UPDATE user_karma SET level=5 WHERE user_id IN (SELECT user_id FROM user_karma WHERE points &gt;= $minPointsLevel5 ORDER BY points DESC LIMIT $limitLevel5)&quot;; $q[] = &quot;UPDATE user_karma SET level=4 WHERE user_id IN (SELECT user_id FROM user_karma WHERE points &gt;= $minPointsLevel4 AND level &lt; 5 ORDER BY points DESC LIMIT $limitLevel4)&quot;; $q[] = &quot;UPDATE user_karma SET level=3 WHERE user_id IN (SELECT user_id FROM user_karma WHERE points &gt;= $minPointsLevel3 AND level &lt; 4 ORDER BY points DESC LIMIT $limitLevel3)&quot;; $q[] = &quot;UPDATE user_karma SET level=2 WHERE user_id IN (SELECT user_id FROM user_karma WHERE points &gt;= $minPointsLevel2 AND level &lt; 3 ORDER BY points DESC LIMIT $limitLevel2)&quot;; $db-&gt;query($q); } public function updateAll(){ $offset = 0; $step = 1000; $db = Database::$connection; $db-&gt;begin(); while (true) { $users = null; $c = new Criteria(); $c-&gt;add(&quot;user_id&quot;, 0, &quot;&gt;&quot;); $c-&gt;addOrderAscending(&quot;user_id&quot;); $c-&gt;setLimit($step, $offset); $users = DB_OzoneUserPeer::instance()-&gt;select($c); if (count($users) == 0) { break; } foreach ($users as $user) { $this-&gt;update($user); } $offset += $step; } $this-&gt;updateLevels(); $db-&gt;commit(); } }</code></pre></div> </div> </div> </div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://org.wikidot.com/forum/t-85716#post-251597</guid>
				<title>Karma</title>
				<link>http://org.wikidot.com/forum/t-85716/karma#post-251597</link>
				<description></description>
				<pubDate>Tue, 02 Sep 2008 16:16:57 +0000</pubDate>
				<wikidot:authorName>SarahCavie</wikidot:authorName>				<wikidot:authorUserId>78725</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>The Karma FAQ on the main site says that guidelines for calculating karma are including with the open source package, but I haven't found them. Were they written or am I not looking in the right place?</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>