User rank does not sort right

walker2238 - November 24, 2008 - 07:24
Project:User Points Top Contributors
Version:5.x-1.0
Component:Miscellaneous
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

I have a list of the top ten users sorted by points. The problem is that when two users have the same number of points, everything gets messed up. So if user A and user B had the same amount of user points the ranking order gets messed up... So if it has user A ranked 5th and user B was ranked 4th, it will show user B above user A... so the numbers would go like, 1, 2, 3, 5, 4, 6, 7, 8, 9, 10. Where 4 and 5 are switched around...

#1

mpaler - February 26, 2009 - 02:44

I agree that the way rank is doled out is a little counterintuitive. I have alot of users who have the same number of user points, yet their ranks are all different. Personally, I think all people with the same # of points should have the same rank.

Here's my way of handling that...

Around line 265 in userpoints_top_contributors.module

<?php
        
// Populate the rank field
   
$result = db_query("SELECT *
      FROM {userpoints_top_contributors}
      ORDER BY lifetime_points DESC"
);

       
$rank = 1;
        while (
$data = db_fetch_object($result)) {
            if (!isset(
$current_points)){
                static
$current_points;
               
$current_points = $data->lifetime_points;
            }
            if(
$data->lifetime_points < $current_points){
               
$current_points = $data->lifetime_points;
               
$rank++;
            }
           
         
db_query("UPDATE {userpoints_top_contributors}
            SET rank = %d
            WHERE uid = %d"
, $rank, $data->uid
         
);
        }
?>

#2

walker2238 - February 27, 2009 - 04:34

Hey good idea. I actually made a block with something like that but only returning the first 10 results. It never crossed my mind to just apply it to everything. I'll give it a try.

 
 

Drupal is a registered trademark of Dries Buytaert.