Scoop -- the swiss army chainsaw of content management
Front Page · Everything · News · Code · Help! · Wishlist · Project · Scoop Sites · Dev Notes · Latest CVS changes · Development Activities
User Activity Algorithm - Request For Comments New Code
By bbatchel , Section Help! []
Posted on Sun Feb 25, 2001 at 12:00:00 PM PST
Ok guys, I got about jack for feedback on my original story, hopefully now that I have some code, people will be more willing to suggest changes. My code, and an explanation of the algorithm are below. An example can be found at my site if you look in the main menu click on User Ranks.

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};

< User Activity Algorithms | An option for everything >

Menu
· create account
· faq
· search
· report bugs
· Scoop Administrators Guide
· Scoop Box Exchange

Login
Make a new account
Username:
Password:

Related Links
· Scoop
· my site
· More on New Code
· Also by bbatchel

Story Views
  24 Scoop users have viewed this story.

Display: Sort:
User Activity Algorithm - Request For Comments | 20 comments (20 topical, 0 hidden)
some feedback (5.00 / 1) (#1)
by kellan on Mon Feb 26, 2001 at 12:22:25 AM PST

(grrr, i lost the first version of this when mozilla decided to free, so i'll probably be much more direct and to the point this time. consider yourself lucky)

So a quick look at your algorithm(and some back of the envelope calcs) looks to me like you are weighting the score heavily in favor of comments. maybe that just reflects my usage pattern, but i doubt i'm that far outside the norm. Is this what you are trying to accomplish? To me well written stories, those strong enough to get accepted, and especially those strong enough to go the front page are the heart of a user's contribution to the site.

But maybe that isn't what you are measuring? Are you really trying to measure just activity with no value judgement?

Maybe Rusty can run this algorithm, pull up some numbers for us.

Are you planning to use this information internally or post it to the site? I imagine making the info public would engender the sort of silly competition you see in some irc channels where users try to be the top chatter. On the flip side I find this sort of meta information cool!

Activity seems to be a value over time. Have you considered adding a timed element to this equation? Perhaps only look at comments and stories per month? (Perhaps with a 10% carry over from last months score so that long time users are rewarded?)

Looking briefly at your code, it looks *very* expensive. Group bys, and avg() are both very expensive database calls, and looping over 5 statement handles of every user on the site can't be pretty either. How often will this code get called? If often, is there a way to pre-calculate and cache the results for display?(Perhaps showing my igonorance of scoop)

kellan




New Code (none / 0) (#11)
by bbatchel on Mon Feb 26, 2001 at 06:50:20 PM PST

If anyone is interested, the latest code for the box is at: http://helios.myip.org/activeusers.txt



Scoop should keep a running tally of how many peop (none / 0) (#20)
by newstart028 on Thu Jun 16, 2016 at 02:58:16 AM PST

Scoop should keep a running tally of how many people have accessed. 192.168.l.l



User Activity Algorithm - Request For Comments | 20 comments (20 topical, 0 hidden)
Display: Sort:

Hosted by ScoopHost.com Powered by Scoop
All trademarks and copyrights on this page are owned by their respective companies. Comments are owned by the Poster. The Rest © 1999 The Management

create account | faq | search