Skip to content
Snippets Groups Projects
Commit 74d3c351 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Took all "rating logic" out of the account.module and moved it into
  a seperate module called "rating.module".  This should allow people
  to experiment with different rating heuristics/algorithms.

- The rating module also generates a "Top 100 users" page, see:
     http://drop.org/module.php?mod=rating

- Adjusted ./scripts/php-clean to ignore png files.
  (I should do it the way around and make it ignore everything but
  our php files.)
parent 4df5b853
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
<? <?
$module = array("cron" => "account_cron", $module = array("help" => "account_help",
"help" => "account_help",
"find" => "account_find", "find" => "account_find",
"block" => "account_block",
"admin" => "account_admin"); "admin" => "account_admin");
function account_cron_ratings() {
$period = 5184000; // 60 days
$number = 30; // 30 comments
$offset = 5; // 5 comments
$r1 = db_query("SELECT id, userid FROM users");
while ($account = db_fetch_object($r1)) {
unset($bonus); unset($votes); unset($score); unset($value); unset($weight);
$r2 = db_query("SELECT COUNT(id) AS number FROM stories WHERE author = $account->id AND (". time() ." - timestamp < $period) AND status = 2");
if ($story = db_fetch_object($r2)) {
$bonus = $story->number;
}
$r3 = db_query("SELECT score, votes FROM comments WHERE author = $account->id AND (". time() ." - timestamp < $period) ORDER BY timestamp LIMIT $number");
while ($comment = db_fetch_object($r3)) {
$weight++;
$score += $weight * $comment->score;
$votes += $weight * $comment->votes;
}
if ($weight >= $offset && $votes > 0) {
$value = ($score + $weight) / $votes + $bonus;
db_query("UPDATE users SET rating = '$value' WHERE id = $account->id");
}
}
}
function account_cron() {
// update user ratings:
account_cron_ratings();
}
function account_help() { function account_help() {
?> ?>
<P>The account-module is responsible for maintaining the user database. It automatically handles tasks like registration, authentication, access rights, password retrieval, user settings and much more.</P> <P>The account-module is responsible for maintaining the user database. It automatically handles tasks like registration, authentication, access rights, password retrieval, user settings and much more.</P>
<P>The required administration can be accomplished through the "account" interface of the administration section. From here administrators can get a quick overview of all registered users and view/edit specific accounts using the links provided. Some useful operations include blocking specific accounts (e.g. a troublesome user) and giving/taking administration permissions. Note that you should only give these permissions to people you trust!</P> <P>The required administration can be accomplished through the "account" interface of the administration section. From here administrators can get a quick overview of all registered users and view/edit specific accounts using the links provided. Some useful operations include blocking specific accounts (e.g. a troublesome user) and giving/taking administration permissions. Note that you should only give these permissions to people you trust!</P>
<P>Check the documentation page for detailed information about user management.</P> <P>Check the documentation page for detailed information about user management.</P>
<H3>User rating</H3>
<P>The account cron will periodically calculate an overall rating of each user's contributed value that is a time-weighted average of his or her comments ratings with an additional bonus for the stories he or she contributed. The system can be best compared with <A HREF="http://slashcode.com/">SlashCode</A>'s karma and is - in fact - even more similar to <A HREF="http://scoop.kuro5hin.org/">Scoop</A>'s mojo implementation.</P>
<P>I won't elaborate on all the funny math involved and it suffices to say that the actual weighting is done in such a way:</P>
<OL>
<LI>that comments with a lot of votes count more then comments with only one or two votes.</LI>
<LI>that newer comments count for more then older comments.</LI>
</OL>
<P>The idea of (1) is that it favors comments that more people voted on, and thus whose rating is more likely to be accurate or justified.</P>
<P>The latter (2) makes the user rating that comes out of the calulations temporary, based on users' most recent activity and responsive to their current state. This is accomplished by taking each user's last 30 comments, or however many he or she posted in the last 60 days - whatever comes first.</P>
<P>Additionally, users that posted one or more succesful stories in the last 60 days gain extra bonus points which will boost up their overall rating.</P>
<? <?
} }
...@@ -208,23 +162,6 @@ function account_view($name) { ...@@ -208,23 +162,6 @@ function account_view($name) {
} }
} }
function account_block() {
$result = db_query("SELECT userid, rating FROM users ORDER BY rating DESC LIMIT 10");
$content .= "<TABLE CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$content .= "<TR><TH>Username</TH><TH>Rating</TH></TR>\n";
while ($account = db_fetch_object($result)) {
$content .= "<TR><TD>". format_username($account->userid) ."</TD><TD>". check_output($account->rating) ."</TD></TR>";
}
$content .= "</TABLE>\n";
$block[0]["subject"] = "Top 10:<BR>users";
$block[0]["content"] = $content;
$block[0]["info"] = "Top 10: users";
return $block;
}
function account_admin() { function account_admin() {
global $op, $edit, $order, $name; global $op, $edit, $order, $name;
......
<?
$module = array("cron" => "rating_cron",
"help" => "rating_help",
"page" => "rating_page",
"block" => "rating_block");
function rating_cron() {
$period = 5184000; // 60 days
$number = 30; // 30 comments
$offset = 5; // 5 comments
$r1 = db_query("SELECT id, userid FROM users");
while ($rating = db_fetch_object($r1)) {
unset($bonus); unset($votes); unset($score); unset($value); unset($weight);
$r2 = db_query("SELECT COUNT(id) AS number FROM stories WHERE author = $rating->id AND (". time() ." - timestamp < $period) AND status = 2");
if ($story = db_fetch_object($r2)) {
$bonus = $story->number;
}
$r3 = db_query("SELECT score, votes FROM comments WHERE author = $rating->id AND (". time() ." - timestamp < $period) ORDER BY timestamp LIMIT $number");
while ($comment = db_fetch_object($r3)) {
$weight++;
$score += $weight * $comment->score;
$votes += $weight * $comment->votes;
}
if ($weight >= $offset && $votes > 0) {
$value = ($score + $weight) / $votes + $bonus;
db_query("UPDATE users SET rating = '$value' WHERE id = $rating->id");
}
}
}
function rating_help() {
?>
<H3>User rating</H3>
<P>The rating cron will periodically calculate an overall rating of each user's contributed value that is a time-weighted average of his or her comments ratings with an additional bonus for the stories he or she contributed. The system can be best compared with <A HREF="http://slashcode.com/">SlashCode</A>'s karma and is - in fact - even more similar to <A HREF="http://scoop.kuro5hin.org/">Scoop</A>'s mojo implementation.</P>
<P>I won't elaborate on all the funny math involved and it suffices to say that the actual weighting is done in such a way:</P>
<OL>
<LI>that comments with a lot of votes count more then comments with only one or two votes.</LI>
<LI>that newer comments count for more then older comments.</LI>
</OL>
<P>The idea of (1) is that it favors comments that more people voted on, and thus whose rating is more likely to be accurate or justified.</P>
<P>The latter (2) makes the user rating that comes out of the calulations temporary, based on users' most recent activity and responsive to their current state. This is accomplished by taking each user's last 30 comments, or however many he or she posted in the last 60 days - whatever comes first.</P>
<P>Additionally, users that posted one or more succesful stories in the last 60 days gain extra bonus points which will boost up their overall rating.</P>
<?
}
function rating_list($limit) {
$result = db_query("SELECT userid, rating FROM users ORDER BY rating DESC LIMIT $limit");
$output .= "<TABLE CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
$output .= "<TR><TH>Username</TH><TH>Rating</TH></TR>\n";
while ($account = db_fetch_object($result)) {
$output .= "<TR><TD>". format_username($account->userid) ."</TD><TD>". check_output($account->rating) ."</TD></TR>";
}
$output .= "</TABLE>\n";
return $output;
}
function rating_page() {
global $theme;
$theme->header();
$theme->box("Top 100 users", rating_list(100));
$theme->footer();
}
function rating_block() {
$block[0]["subject"] = "Top 10:<BR>users";
$block[0]["content"] = rating_list(10);
$block[0]["info"] = "Top 10: users";
return $block;
}
?>
\ No newline at end of file
#!/bin/sh #!/bin/sh
find . -name "*~" -type f | xargs rm -f find . -name "*~" -type f | xargs rm -f
find . -name "DEADJOE" -type f | xargs rm -f find . -name "DEADJOE" -type f | xargs rm -f
find . -name "*" -type f | grep -v ".gif" | grep -v ".jpg" | grep -v ".tgz" | xargs perl -wi -pe 's/\s+$/\n/' find . -name "*" -type f | grep -v ".gif" | grep -v ".jpg" | grep -v ".png" | grep -v ".tgz" | xargs perl -wi -pe 's/\s+$/\n/'
find . -name "*" -type f | grep -v ".gif" | grep -v ".jpg" | grep -v ".tgz" | xargs perl -wi -pe 's/\t/ /g' find . -name "*" -type f | grep -v ".gif" | grep -v ".jpg" | grep -v ".png" | grep -v ".tgz" | xargs perl -wi -pe 's/\t/ /g'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment