First, the algorithm. I take in several factors:
- How many stories a user moderates
- How many comments a user rates
- How many comments a user posts
- How many stories the user has submitted
- How many of the stories submitted have been posted
- Average Rating of the comments user has posted
Now the algorithm uses these factors in a simple manner:
(# stories moderated) + (# comments rated) + ((# comments posted}*(avg comment rating)) + (# stories submitted} + (10*(# stories that get posted)
Here is the code, the way I have it working uses a box and a special page. The box code (its very long):
#################################################
# Most Active Users Script
# Purpose: This uses a simple algorithm to
# determine who the most active users
# are on the system. For bragging
# rights, or in my case a contest to
# promote my scoop site.
# Author: Bryan Batchelder
# pontiphex@stetsonsucks.com
#################################################
my $ignore_uids = '-1,2,3,4';
my $info = qq{<table border="0" width="100%"><tr><td>|smallfont|This is the current list of the 50 most active users on the system|smallfont_end|
</td></tr></table>};
my $content = $info;
$content .= qq{
<table width="100%"
border="0"
cellpadding="0"
cellspacing="0">
<tr><td bgcolor="#1C574B">
<table width="100%"
border="0"
cellpadding="2"
cellspacing="1">
<tr>
<td><font color="#ffffff">rank</font></td>
<td><font color="#ffffff">uid</font></td>
<td><font color="#ffffff">total</font></td>
</tr>};
################################################
# How many stories have you moderated?
################################################
my ($rv_sm, $sth_sm) = $S->db_select({
WHAT => 'u.uid,
u.nickname,
count(vote) as num_moderations',
FROM => 'users u LEFT JOIN storymoderate s ON u.uid = s.uid',
WHERE => "u.uid NOT IN ($ignore_uids)",
GROUP_BY => 'u.uid',
ORDER_BY => 'u.uid'});
#################################################
# How many comments have you rated?
#################################################
my ($rv_cr, $sth_cr) = $S->db_select({
WHAT => 'u.uid,
count(rating) as num_ratings',
FROM => 'users u LEFT JOIN commentratings c ON u.uid = c.uid',
WHERE => "u.uid NOT IN ($ignore_uids)",
GROUP_BY => 'u.uid',
ORDER_BY => 'u.uid'});
#################################################
# How many comments have you written?
#################################################
my ($rv_cp, $sth_cp) = $S->db_select({
WHAT => 'u.uid,
count(c.cid) as num_comments',
FROM => 'users u LEFT JOIN comments c ON u.uid = c.uid',
WHERE => "u.uid NOT IN ($ignore_uids)",
GROUP_BY => 'u.uid',
ORDER_BY => 'u.uid'});
################################################
# Number of stories submitted
################################################
my ($rv_ss, $sth_ss) = $S->db_select({
WHAT => 'u.uid,
count(s.sid) as num_submitted',
FROM => 'users u LEFT JOIN stories s ON u.nickname = s.aid',
WHERE => "u.uid NOT IN ($ignore_uids)",
GROUP_BY => 'u.uid',
ORDER_BY => 'u.uid'});
################################################
# Quality of comments posted
################################################
my ($rv_cq, $sth_cq) = $S->db_select({
WHAT => 'u.uid,
IFNULL(avg(c.points), 1) as avg_points',
FROM => 'users u LEFT JOIN comments c ON u.uid = c.uid',
WHERE => "u.uid NOT IN ($ignore_uids)",
GROUP_BY => 'u.uid',
ORDER_BY => 'u.uid'});
################################################
# Number of stories posted
################################################
my ($rv_sp, $sth_sp) = $S->db_select({
WHAT => 'u.uid,
count(s.sid) as num_posted',
FROM => 'users u LEFT JOIN stories s ON u.nickname = s.aid AND displaystatus in (0,1)',
WHERE => "u.uid NOT IN ($ignore_uids)",
GROUP_BY => 'u.uid',
ORDER_BY => 'u.uid'});
my $counter = 0;
my @data;
while (my $sm = $sth_sm->fetchrow_hashref())
{
my $cr=$sth_cr->fetchrow_hashref();
my $cp=$sth_cp->fetchrow_hashref();
my $ss=$sth_ss->fetchrow_hashref();
my $cq=$sth_cq->fetchrow_hashref();
my $sp=$sth_sp->fetchrow_hashref();
my $total=$sm->{num_moderations}+$cr->{num_ratings}+($cp->{num_comments}*$cq->{avg_points})+$ss->{num_submitted}+(10*$sp->{num_posted});
push(@data,[int($total),$sm->{nickname}]);
$counter = $counter++;
}
sort {@{$a}[0] cmp @{$b}[0]} @data;
my $index=0;
my $pointlist;
my $point;
foreach $pointlist (sort {@{$b}[0] <=> @{$a}[0]} @data)
{
$index++;
my $bgcolor = "#B4C7C4";
if ($index > 10)
{
$bgcolor = "#F58D8D"
}
if ($index < 51)
{
$content .= qq{<tr><td bgcolor="$bgcolor">$index</td><td bgcolor="$bgcolor">@{$pointlist}[1]</td><td bgcolor="$bgcolor">@{$pointlist}[0]</td></tr>}
}
}
$content .= qq{</table></td></tr></table>};
return {content => $content};