Advertisement:

Author Topic: Showing Highest and Lowest Karma Rating in Stats Page  (Read 95154 times)

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Showing Highest and Lowest Karma Rating in Stats Page
« on: October 24, 2004, 05:05:33 AM »
Hello,
  This small mod adds the top 5 karma ratings, and the lowest 5 karma ratings to the stats page. You can see an example of it here:
http://forums.tauonline.org/index.php?action=stats

Update: This has been updated on 4/12/04. The changes are:
  • If you have karma disabled on your forum, this mod won't take effect, if you have it on 'Enable Karma Total' this mod will show the highest and lowest total karma, and if you have it on 'Enable Karma Positive/Negative' this mod will show the members with the highest positive karma, and the members with the lowest negative karma. Thanks to NiXnAx for helping make the showing of karma totals display correctly.
  • The members' names are now linked to their profile. Thanks to Burpee for helping out with this


Here's what to change:

In /Sources/Stats.php
Find:

Code: [Select]
// Activity by month.
Add above it:
Code: [Select]
// Top 5 Karma Rating
$karma_results = db_query("
SELECT realName, karmaGood, ID_MEMBER FROM {$db_prefix}members ORDER BY karmaGood DESC LIMIT 5", __FILE__, __LINE__);

$context['karma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['gkarma'][] = array(
'Karma' => $row_karma['karmaGood'],
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>'
);
}

// Bottom 5 Karma Rating
$karma_results = db_query("
SELECT realName, karmaBad, ID_MEMBER FROM {$db_prefix}members ORDER BY karmaBad DESC LIMIT 5", __FILE__, __LINE__);

$context['bkarma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['bkarma'][] = array(
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>',
'Karma' => $row_karma['karmaBad']
);
}

// Highest Total Karma
$karma_results = db_query("
SELECT karmaGood, karmaBad, realName, ID_MEMBER FROM {$db_prefix}members ORDER BY FLOOR(karmaGood-karmaBad) DESC LIMIT 5", __FILE__, __LINE__);

$context['htkarma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['htkarma'][] = array(
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>',
'Good' => $row_karma['karmaGood'],
'Bad' => $row_karma['karmaBad']
);
}

// Lowest karma total
$karma_results = db_query("
SELECT karmaGood, karmaBad, realName, ID_MEMBER FROM {$db_prefix}members ORDER BY FLOOR(karmaGood-karmaBad) ASC LIMIT 5", __FILE__, __LINE__);

$context['ltkarma'] = array();

while( $row_karma = mysql_fetch_assoc($karma_results) )
{
$context['ltkarma'][] = array(
'Link' => '<a href="' . $scripturl . '?action=profile;u=' . $row_karma['ID_MEMBER'] . '">' . $row_karma['realName'] . '</a>',
'Good' => $row_karma['karmaGood'],
'Bad' => $row_karma['karmaBad']
);
}

In /Themes/(ThemeFolder)/Stats.template.php
Find:

Code: [Select]
foreach ($context['top_time_online'] as $poster)
echo '
<tr>
<td width="60%" valign="top">', $poster['link'], '</td>
<td width="20%" align="left" valign="top">', $poster['time_online'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $poster['time_percent'] . '" height="15" alt="" border="0" />' : '&nbsp;', '</td>
<td width="20%" align="right" valign="top" nowrap="nowrap">', $poster['time_online'], '</td>
</tr>';
echo '
</table>
</td>
</tr><tr>
<td class="catbg" colspan="4"><b>', $txt['smf_stats_5'], '</b></td>
</tr><tr>
<td class="windowbg" width="20" valign="middle" align="center"><img src="', $settings['images_url'], '/stats_history.gif" border="0" width="20" height="20" alt="" /></td>
<td class="windowbg2" colspan="4">';

Replace with:
Code: [Select]
foreach ($context['top_time_online'] as $poster)
            echo '
                                                <tr>
                                                        <td width="60%" valign="top">', $poster['link'], '</td>
                                                        <td width="20%" align="left" valign="top">', $poster['time_online'] > 0 ? '<img src="' . $settings['images_url'] . '/bar.gif" width="' . $poster['time_percent'] . '" height="15" alt="" border="0" />' : '&nbsp;', '</td>
                                                        <td width="20%" align="right" valign="top" nowrap="nowrap">', $poster['time_online'], '</td>
                                                </tr>';
        echo ' </table></td></tr>';

if( $modSettings['karmaMode'] == 1 )
{
echo '<tr>
<td class="catbg" colspan="2">Highest Karma Total</td>
<td class="catbg" colspan="2">Lowest Karma Total</td>
</tr>
<tr>
<td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';

foreach($context['htkarma'] as $htkarma)
{
$total = $htkarma['Good'] - $htkarma['Bad'];
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr>
<td class="windowbg2" width="80%" align="left">'.
$htkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">'.$total.'</td>
</tr></table>';
}

echo'</td><td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';


foreach($context['ltkarma'] as $ltkarma)
{
$total = $ltkarma['Good'] - $ltkarma['Bad'];
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr>
<td class="windowbg2" width="80%" align="left">'.
$ltkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">'.$total.'</td>
</tr></table>';
}
}

if( $modSettings['karmaMode'] == 2)
{
echo '<tr>
<td class="catbg" colspan="2">Highest Karma Rating</td>
<td class="catbg" colspan="2">Lowest Karma Rating</td>
</tr>
<tr>
<td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';

foreach($context['gkarma'] as $gkarma)
{
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%"><tr>
<td class="windowbg2" width="80%" align="left">'.
$gkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">+'.$gkarma['Karma'].'</td>
</tr></table>';
}

echo'</td><td class="windowbg" colspan="1">
<img src="'. $settings['images_url']. '/stats_posters.gif" width="20" height="20" />
</td>
<td class="windowbg2">';

foreach($context['bkarma'] as $bkarma)
{
echo '<table border="0" cellpadding="1" cellspacing="0" width="100%">
<tr valign="top"><td class="windowbg2" width="80%" align="left">'.
$bkarma['Link']
.'</td>
<td class="windowbg2" width="20%" align="right">-'.$bkarma['Karma'].'</td>
</tr></table>';
}
}

echo'</tr></td><tr><td class="catbg" colspan="4"><b>', $txt['smf_stats_5'], '</b></td>
                        </tr>
<tr>
                                <td class="windowbg" width="20" valign="middle" align="center"><img src="', $settings['images_url'], '/stats_history.gif" border="0" width="20" height="20" alt="" /></td>
                                <td class="windowbg2" colspan="4">';


If you want it to show more (Or less) stats then:
In /Sources/Stats.php
Find the following:

SELECT realName, karmaGood, ID_MEMBER FROM {$db_prefix}members ORDER BY karmaGood DESC LIMIT 5

SELECT realName, karmaBad, ID_MEMBER FROM {$db_prefix}members ORDER BY karmaBad DESC LIMIT 5

SELECT karmaGood, karmaBad, realName, ID_MEMBER FROM {$db_prefix}members ORDER BY FLOOR(karmaGood-karmaBad) DESC LIMIT 5

SELECT karmaGood, karmaBad, realName, ID_MEMBER FROM {$db_prefix}members ORDER BY FLOOR(karmaGood-karmaBad) ASC LIMIT 5 5

And replace the number bolded above to however many results you want shown.


That's it! Please say if you have any questions/queries about this,
 TauOnline.Org
« Last Edit: March 04, 2007, 11:10:02 AM by Tau Online »

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #1 on: October 24, 2004, 11:16:48 AM »
nice tip .. thanks for sharing it.
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #2 on: October 24, 2004, 11:29:29 AM »
nice tip .. thanks for sharing it.
Thanks and your welcome  :) Also whatever happened to the links to all these tips? They were in the sticky, but now they aren't.. Was it too much work?

Offline A.M.A

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 2,133
  • Gender: Male
  • ..
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #3 on: October 24, 2004, 11:56:55 AM »
nope .. just thinking it is not hard to find a tip in here.
Really sorry .. real life is demanding my full attention .. will be back soon hopefully :)

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #4 on: October 25, 2004, 05:26:16 AM »
nope .. just thinking it is not hard to find a tip in here.
Ah right.  :) Will it come back if this board gets bigger?

Offline GiNi3D

  • Jr. Member
  • **
  • Posts: 382
  • Gender: Male
  • Be truthful
    • Nettouring.com
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #5 on: October 25, 2004, 09:57:08 AM »
Nice idea Tau, very useful. :)

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #6 on: October 25, 2004, 10:13:35 AM »
Nice idea Tau, very useful. :)
Thanks  :)

Offline Burpee

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,298
  • Gender: Male
    • Mafan.nl
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #7 on: November 16, 2004, 08:55:36 AM »
Hmm... would it be possible to show the lowest and highest totals, instead of the votes casted upon each user?

PS: Nice trick, Tau :D

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #8 on: November 16, 2004, 12:49:16 PM »
Hmm... would it be possible to show the lowest and highest totals, instead of the votes casted upon each user?

PS: Nice trick, Tau :D
Yeah it's possible, it's just that at the time of making the code, I couldn't be bothered to show the totals! I'll edit my first post soon to show the rating, or the totals depending on what setting you choose  :)


EDIT: It appears it's not as easy as I thought it'd be.. I've got the main bit of this script working, I just can't get an ordered list to show up... 

E.g: (Taken from my forum when testing this script)
Brother Edwin      -3
Orion                   -1
Fire Eater         -1
Feugan AM      -1
misfits Tau punk -2

... I'm not good enough with arrays right now to complete this... I can give you the code that I have done at the moment, although it doesn't show an ordered list and so is kind of pointless.. I'll keep working on this, although I doubt I can do this at the moment... Sorry  :-[ If anyone wants to help out, It'd be appreciated
« Last Edit: November 16, 2004, 03:37:14 PM by Tau Online »

Offline Burpee

  • SMF Friend
  • Sophist Member
  • *
  • Posts: 1,298
  • Gender: Male
    • Mafan.nl
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #9 on: November 16, 2004, 04:36:20 PM »
Hmm... perhaps you should share the code you have right now so people can try and help you...
I probably can't help you, but ofcourse I'm willing to give it a try :P

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #10 on: November 17, 2004, 03:04:40 PM »
Hmm... perhaps you should share the code you have right now so people can try and help you...
I probably can't help you, but ofcourse I'm willing to give it a try :P
I've updated my first post to do this  :)
« Last Edit: December 03, 2004, 12:35:37 PM by Tau Online »

Offline BigMike

  • Full Member
  • ***
  • Posts: 635
  • Gender: Male
    • http://facebook.com/huusoku on Facebook
    • Marlin Crawler, Inc.
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #11 on: November 17, 2004, 05:31:07 PM »
Wow, I tried doing this on my forum a while back and just gave up. Having a max and min is nice, but I was just trying to show the max listings. All you would have to do is sum their max and mins and then sort the highest n number of returns, and store those into a new array. Then run a counter from 0 to the number of names -1 and you would have it.

I dont have time right now, but when I do I'll see if I can figure it out. But Im only going to figure out how to show the Higest totals, not the lowest..

Here's your code running on my forum: http://board.marlincrawler.com/index.php?action=stats
Thanks for the code and I'll see what I can do...

Offline Tristan Perry

  • SMF Hero
  • ******
  • Posts: 2,498
  • Gender: Male
    • Tristan Perry
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #12 on: November 18, 2004, 11:02:09 AM »
Wow, I tried doing this on my forum a while back and just gave up. Having a max and min is nice, but I was just trying to show the max listings. All you would have to do is sum their max and mins and then sort the highest n number of returns, and store those into a new array. Then run a counter from 0 to the number of names -1 and you would have it.

I dont have time right now, but when I do I'll see if I can figure it out. But Im only going to figure out how to show the Higest totals, not the lowest..

Here's your code running on my forum: http://board.marlincrawler.com/index.php?action=stats
Thanks for the code and I'll see what I can do...
Cool, thanks  :) Also I'm glad you liked the code  :)

Offline ozmafans

  • Semi-Newbie
  • *
  • Posts: 20
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #13 on: December 02, 2004, 09:33:53 AM »
Hey this is great and all, but I have a question:

http://www.ozmafans.com/forum [nofollow]

People seem to show up multiple times.

For example: "stefanie" has the highest at +123, but also the lowest at -118 ? How is this possible?

I just read some of the comments, I understand now. If someone could make this a real feature, that includes BOTH totals and the original stats (as both are interesting) I would love it.
« Last Edit: December 02, 2004, 09:35:42 AM by ozmafans »

Offline NiXnAx

  • Semi-Newbie
  • *
  • Posts: 26
  • Gender: Male
    • Silent Initiative Network (CS clan)
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #14 on: December 02, 2004, 11:53:29 AM »
To get the lowest total karma correct, you have to use this query:
Code: [Select]
SELECT karmaGood, karmaBad, realName FROM smf_members ORDER BY (karmaGood-karmaBad) ASC LIMIT 5", __FILE__, __LINE__);

Offline ozmafans

  • Semi-Newbie
  • *
  • Posts: 20
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #15 on: December 02, 2004, 01:35:04 PM »
To get the lowest total karma correct, you have to use this query:
Code: [Select]
SELECT karmaGood, karmaBad, realName FROM smf_members ORDER BY (karmaGood-karmaBad) ASC LIMIT 5", __FILE__, __LINE__);

that worked perfectly (karmaBad-karmaGood) as well, for the Top 5 posters.

Offline ozmafans

  • Semi-Newbie
  • *
  • Posts: 20
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #16 on: December 02, 2004, 02:11:46 PM »
sorry for double-replying, but I am noticing now that after increasing the count to 10, the stats are no longer in order.

To see for yourself, www.ozmafans.com/forum [nofollow]

Offline NiXnAx

  • Semi-Newbie
  • *
  • Posts: 26
  • Gender: Male
    • Silent Initiative Network (CS clan)
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #17 on: December 02, 2004, 02:45:14 PM »
To get the lowest total karma correct, you have to use this query:
Code: [Select]
SELECT karmaGood, karmaBad, realName FROM smf_members ORDER BY (karmaGood-karmaBad) ASC LIMIT 5", __FILE__, __LINE__);

that worked perfectly (karmaBad-karmaGood) as well, for the Top 5 posters.

You only need to change ASC to DESC to get the top 5 karma total.

Offline ozmafans

  • Semi-Newbie
  • *
  • Posts: 20
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #18 on: December 02, 2004, 09:27:15 PM »
To get the lowest total karma correct, you have to use this query:
Code: [Select]
SELECT karmaGood, karmaBad, realName FROM smf_members ORDER BY (karmaGood-karmaBad) ASC LIMIT 5", __FILE__, __LINE__);

that worked perfectly (karmaBad-karmaGood) as well, for the Top 5 posters.

You only need to change ASC to DESC to get the top 5 karma total.
Thank you for that tip, I know very little about php/sql.

The problem seems to be that say I had -100 karma points given to me, and 100 positive karma points given to me.

karmaBad (100) - karmaGood (100) = -200, when it should really be 0. Is there an absolute value function?

Offline NiXnAx

  • Semi-Newbie
  • *
  • Posts: 26
  • Gender: Male
    • Silent Initiative Network (CS clan)
Re: Showing Highest and Lowest Karma Rating in Stats Page
« Reply #19 on: December 02, 2004, 09:40:55 PM »
when you remove good karma from bad karma, you usually get negative karma. (that is supposed when you are nice on the forum), and int (the value of karma, stored in the database cannot be negative) ant that is the reason there is two karma colums. So when you substract 100 (goodkarma) from 100 (badkarma) you get, well you guessed it, 0.