Author Topic: MOD: More correct variant of a TOP-rating  (Read 15703 times)

0 Members and 1 Guest are viewing this topic.

Offline Eld

  • Pre-Newbie
  • Posts: 3
    • View Profile
    • Northern International University
MOD: More correct variant of a TOP-rating
« on: February 16, 2006, 06:37:48 AM »
Hello!


2006-04-05 - the special formula was corrected (mawenzi)
2006-04-05 - the mistake in realization of the formula is corrected (Eld)


Excuse for my bad English, but I would like to share with you a little change in gallery.
I did not accept rating system (TOP 10) in gallery, becouse they a not correct.
Because in top of a rating table there were voices as which it is impossible to consider correct.
eg.
rating: 5, votes: 1
rating: 5, votes: 1
rating: 5, votes: 2
rating: 4.8, votes: 20
rating: 4.5, votes: 15

IT'S NOT CORRECT!
Must be:

rating: 4.8, votes: 20
rating: 4.5, votes: 15
rating: 5, votes: 2
rating: 5, votes: 1
rating: 5, votes: 1


Having reflected, I have thought up other variant of an estimation of a rating of photos.
The estimation of a rating is made under the special formula on the basis of standard data about votings for a photo.

This special formula:  rating = (POW((i.image_votes/15),(1/3))) * (i.image_rating-3)

Where 15 - a number of poll when voting can be considered taken place.
The formula correctly considers influence of negative voices on voting.

All possible variants of votings have been counted up and checked up in Excel and is found out, that the formula is true.

And

For change of your TOP-rating make following changes:
------------------------------------------------------------------------------

Step 1

Open /top.php

Find code:

Code: [Select]
$sql = "SELECT i.image_id, i.user_id, i.cat_id, i.image_name, i.image_rating, i.image_votes, c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM ".IMAGES_TABLE." i, ".CATEGORIES_TABLE." c
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND i.cat_id = c.cat_id
        $cat_match_sql
        ORDER BY i.image_rating DESC, i.image_votes DESC, i.image_name ASC
        LIMIT 10";

and REPLACE WITH:

Code: [Select]
$sql = "SELECT i.image_id, i.user_id, i.cat_id, i.image_name, i.image_rating, i.image_votes, c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM ".IMAGES_TABLE." i, ".CATEGORIES_TABLE." c
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND i.cat_id = c.cat_id
        $cat_match_sql
        ORDER BY (POW((i.image_votes/15),(1/3))) * (i.image_rating-3) DESC
        LIMIT 10";

Or if you want that it was the RATING of WEEK (as it was made by me for myself)
AND if you wish to deduce in a rating of photos preview:


REPLACE WITH
------------------------------------------

Code: [Select]
$new_time = time() - 60 * 60 * 24 * 7;

// $new_time - for what term to deduce photos (for example for last week)

$sql = "SELECT i.image_id, i.user_id, i.cat_id, i.image_name, i.image_thumb_file, i.image_rating, i.image_votes, c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM ".IMAGES_TABLE." i, ".CATEGORIES_TABLE." c
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_date >= $new_time AND i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND i.cat_id = c.cat_id
        $cat_match_sql
        ORDER BY (POW((i.image_votes/15),(1/3))) * (i.image_rating-3) DESC
        LIMIT 10";


Step 2

Open: your_template_path/top.html[/b]
find block of code, where your TOP rating is displaying:

Code: [Select]
   
                       <tr>
                            <td class="head1" valign="top" colspan="5">{lang_top_image_rating}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row1" align="center"><b>1</b></td>
                            <td valign="top" class="row1">{image_rating_1}</td>
                            <td valign="top" class="row1">{image_rating_user_1}</td>
                            <td valign="top" class="row1">{image_rating_cat_1}</td>
                            <td valign="top" class="row1" nowrap>{image_rating_number_1}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row2" align="center"><b>2</b></td>
                            <td valign="top" class="row2">{image_rating_2}</td>
                            <td valign="top" class="row2">{image_rating_user_2}</td>
                            <td valign="top" class="row2">{image_rating_cat_2}</td>
                            <td valign="top" class="row2" nowrap>{image_rating_number_2}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row1" align="center"><b>3</b></td>
                            <td valign="top" class="row1">{image_rating_3}</td>
                            <td valign="top" class="row1">{image_rating_user_3}</td>
                            <td valign="top" class="row1">{image_rating_cat_3}</td>
                            <td valign="top" class="row1" nowrap>{image_rating_number_3}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row2" align="center"><b>4</b></td>
                            <td valign="top" class="row2">{image_rating_4}</td>
                            <td valign="top" class="row2">{image_rating_user_4}</td>
                            <td valign="top" class="row2">{image_rating_cat_4}</td>
                            <td valign="top" class="row2" nowrap>{image_rating_number_4}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row1" align="center"><b>5</b></td>
                            <td valign="top" class="row1">{image_rating_5}</td>
                            <td valign="top" class="row1">{image_rating_user_5}</td>
                            <td valign="top" class="row1">{image_rating_cat_5}</td>
                            <td valign="top" class="row1" nowrap>{image_rating_number_5}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row2" align="center"><b>6</b></td>
                            <td valign="top" class="row2">{image_rating_6}</td>
                            <td valign="top" class="row2">{image_rating_user_6}</td>
                            <td valign="top" class="row2">{image_rating_cat_6}</td>
                            <td valign="top" class="row2" nowrap>{image_rating_number_6}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row1" align="center"><b>7</b></td>
                            <td valign="top" class="row1">{image_rating_7}</td>
                            <td valign="top" class="row1">{image_rating_user_7}</td>
                            <td valign="top" class="row1">{image_rating_cat_7}</td>
                            <td valign="top" class="row1" nowrap>{image_rating_number_7}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row2" align="center"><b>8</b></td>
                            <td valign="top" class="row2">{image_rating_8}</td>
                            <td valign="top" class="row2">{image_rating_user_8}</td>
                            <td valign="top" class="row2">{image_rating_cat_8}</td>
                            <td valign="top" class="row2" nowrap>{image_rating_number_8}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row1" align="center"><b>9</b></td>
                            <td valign="top" class="row1">{image_rating_9}</td>
                            <td valign="top" class="row1">{image_rating_user_9}</td>
                            <td valign="top" class="row1">{image_rating_cat_9}</td>
                            <td valign="top" class="row1" nowrap>{image_rating_number_9}</td>
                          </tr>
                          <tr>
                            <td valign="top" class="row2" align="center"><b>10</b></td>
                            <td valign="top" class="row2">{image_rating_10}</td>
                            <td valign="top" class="row2">{image_rating_user_10}</td>
                            <td valign="top" class="row2">{image_rating_cat_10}</td>
                            <td valign="top" class="row2" nowrap>{image_rating_number_10}</td>
                          </tr>

and REPLACE WITH:

Code: [Select]
<tr>
  <td class="head1" valign="top" colspan="5">{lang_top_image_rating}</td>
</tr>
<tr>
  <td valign="top" class="row1" align="center"><b>1</b></td>
  <td valign="top" class="row1" align="left">{image_rating_image_1}</td>
  <td valign="top" colspan=3 class="row1" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_1}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_1}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_1}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_1}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row2" align="center"><b>2</b></td>
  <td valign="top" class="row2" align="left">{image_rating_image_2}</td>
  <td valign="top" colspan=3 class="row2" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_2}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_2}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_2}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_2}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row1" align="center"><b>3</b></td>
  <td valign="top" class="row1" align="left">{image_rating_image_3}</td>
  <td valign="top" colspan=3 class="row1" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_3}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_3}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_3}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_3}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row2" align="center"><b>4</b></td>
  <td valign="top" class="row2" align="left">{image_rating_image_4}</td>
  <td valign="top" colspan=3 class="row2" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_4}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_4}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_4}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_4}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row1" align="center"><b>5</b></td>
  <td valign="top" class="row1" align="left">{image_rating_image_5}</td>
  <td valign="top" colspan=3 class="row1" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_5}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_5}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_5}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_5}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row2" align="center"><b>6</b></td>
  <td valign="top" class="row2" align="left">{image_rating_image_6}</td>
  <td valign="top" colspan=3 class="row2" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_6}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_6}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_6}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_6}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row1" align="center"><b>7</b></td>
  <td valign="top" class="row1" align="left">{image_rating_image_7}</td>
  <td valign="top" colspan=3 class="row1" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_7}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_7}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_7}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_7}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row2" align="center"><b>8</b></td>
  <td valign="top" class="row2" align="left">{image_rating_image_8}</td>
  <td valign="top" colspan=3 class="row2" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_8}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_8}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_8}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_8}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row1" align="center"><b>9</b></td>
  <td valign="top" class="row1" align="left">{image_rating_image_9}</td>
  <td valign="top" colspan=3 class="row1" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_9}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_9}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_9}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_9}</td></tr>
                                          </table>
  </td>
</tr>
<tr>
  <td valign="top" class="row2" align="center"><b>10</b></td>
  <td valign="top" class="row2" align="left">{image_rating_image_10}</td>
  <td valign="top" colspan=3 class="row2" width=100%><table border=0>
                                          <tr><td>image:</td><td>{image_rating_openwindow_10}</td></tr>
                                          <tr><td>author:</td><td>{image_rating_user_10}</td></tr>
                                          <tr><td>category:</td><td>{image_rating_cat_10}</td></tr>
                                          <tr><td>rating:</td><td>{image_rating_number_10}</td></tr>
                                          </table>
  </td>
</tr>



EXAMPLE:
« Last Edit: April 05, 2006, 09:37:54 AM by mawenzi »

Offline trez

  • Hero Member
  • *****
  • Posts: 613
    • View Profile
    • blog / photography
Re: MOD: More correct variant of a TOP-rating
« Reply #1 on: February 16, 2006, 07:01:30 AM »
Great work! I will implement it after i finish some other MODs ;)

Offline TheOracle

  • Hero Member
  • *****
  • Posts: 875
    • View Profile
Re: MOD: More correct variant of a TOP-rating
« Reply #2 on: February 16, 2006, 04:47:57 PM »
Now, that's interesting. It was also on my TODO list. I guess I can remove it now. Thanks for posting this. ;)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: MOD: More correct variant of a TOP-rating
« Reply #3 on: February 22, 2006, 09:57:15 PM »
Hi, this is a great thing. One Question. What must i change to have it for the Mini Top Mod???

Here is the code from the mini_top.php

Code: [Select]
<?php

define
('GET_CACHES'1);
define('ROOT_PATH''./');
$user_access get_permission();

$imgtable_width ceil(intval($config['image_table_width']) / $config['image_cells']);
if ((
substr($config['image_table_width'], -1)) == "%") {
  
$imgtable_width .= "%";
}

 
$mini_top_images "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
 
$mini_top_images .= "<tr class=\"imagerow1\">\n";

 
$selection = array('rating''votes''hits''comments''downloads');
 
$selection_alt = array('votes DESC''rating DESC''name ASC''name ASC''name ASC');
# $selection_cutoff = array(' AND i.image_votes > 10', '', '', '', '');

 
$num_of_cells $config['image_cells'];
 
$num_of_cells $num_of_cells count($selection) ? count($selection) : $num_of_cells;

 for (
$cnt 0$cnt $num_of_cells$cnt++) {

 
$mini_top_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

$sql "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.""user_name")."
        FROM "
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
        LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id)
        WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN ("
.get_auth_cat_sql("auth_viewcat").")".$selection_cutoff[$cnt]."
        ORDER BY i.image_"
.$selection[$cnt]." DESC, i.image_".$selection_alt[$cnt];
        

 
$result $site_db->query_firstrow($sql);
 
show_image($result);
 
$site_template->register_vars("lang_mini_top_mode"$lang['mini_top_'.$selection[$cnt]]);
 
$mini_top_images .= $site_template->parse_template("mini_top_bit");
 
$mini_top_images .= "\n</td>\n";
}

 
$mini_top_images .= "</tr>\n";
 
$mini_top_images .= "</table>\n";

 
$site_template->register_vars(array(
  
"mini_top_images" => $mini_top_images,
  
"lang_hits" => $lang['hits'],
  
"lang_downloads" => $lang['downloads'],
  
"lang_mini_top_title" => $lang['mini_top_title']
 ));
unset(
$mini_top_images);

?>

Thanks for helping!
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: MOD: More correct variant of a TOP-rating
« Reply #4 on: February 23, 2006, 06:04:21 PM »
No One :(

I think it´s this line

Quote
ORDER BY i.image_".$selection[$cnt]." DESC, i.image_".$selection_alt[$cnt];

But which changes must i do???
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: MOD: More correct variant of a TOP-rating
« Reply #5 on: February 24, 2006, 01:19:11 AM »
Code: [Select]
ORDER BY ".(($selection[$cnt] == "rating") ? "((i.image_votes/15)^(1/3)) * (i.image_rating-3)" : "i.image_".$selection[$cnt])." DESC, i.image_".$selection_alt[$cnt];
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Eld

  • Pre-Newbie
  • Posts: 3
    • View Profile
    • Northern International University
Re: MOD: More correct variant of a TOP-rating
« Reply #6 on: February 24, 2006, 02:07:55 AM »
Code: [Select]
ORDER BY ".(($selection[$cnt] == "rating") ? "((i.image_votes/15)^(1/3)) * (i.image_rating-3)" : "i.image_".$selection[$cnt])." DESC, i.image_".$selection_alt[$cnt];

V@no, many thanks for the help!

Спасибо! :)

Offline JensF

  • Addicted member
  • ******
  • Posts: 1.028
    • View Profile
    • http://www.terraristik-galerie.de
Re: MOD: More correct variant of a TOP-rating
« Reply #7 on: February 25, 2006, 09:31:13 PM »
Yes. thanks for this. I have a Statistic in the Control Panel. Where can i found it to change this....???
Mit freundlichem Gruß
Jens Funk



-> Sorry for my bad English <-

Offline impss

  • Sr. Member
  • ****
  • Posts: 382
    • View Profile
    • Cusstom.net
Re: MOD: More correct variant of a TOP-rating
« Reply #8 on: April 04, 2006, 03:08:45 PM »

It led to incorrectly shown results of a rating.


I suggest you edit your first post, to include this change

Offline Eld

  • Pre-Newbie
  • Posts: 3
    • View Profile
    • Northern International University
Re: MOD: More correct variant of a TOP-rating
« Reply #9 on: April 05, 2006, 03:27:31 AM »
I suggest you edit your first post, to include this change

Ok. I have made a change in my first post.

Offline mawenzi

  • Moderator
  • 4images Guru
  • *****
  • Posts: 4.500
    • View Profile
Re: MOD: More correct variant of a TOP-rating
« Reply #10 on: April 05, 2006, 09:40:29 AM »
Thanks for this interesting extension.
Your first three "must do" before you ask a question ! ( © by V@no )
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

You are on search for top 4images MOD's ?
- then please search here ... Mawenzi's Top 100+ MOD List (unsorted sorted) ...

Offline boerdi

  • Newbie
  • *
  • Posts: 44
    • View Profile
Re: MOD: More correct variant of a TOP-rating
« Reply #11 on: May 03, 2006, 10:00:43 PM »
Hello!
hat leider incht funktioniert...wollte ebenfalls minitop.php anpassen!
okmmt aber  ne fehlermeldung..und zwar:
DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits, c.cat_name, u.username FROM 4images_images i, 4images_categories c LEFT JOIN user u ON (u.userid = i.user_id) WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.cat_id IN (0, 1, 4) ORDER BY ((i.image_votes/15)^(1/3)) * (i.image_rating-3) DESC, i.image_votes DESC
You have an error in your SQL syntax near '^(1/3)) * (i.image_rating-3) DESC, i.image_votes DESC' at line 5


kann mir wer helfen??
lg

Offline gustav

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: MOD: More correct variant of a TOP-rating
« Reply #12 on: June 06, 2006, 09:34:22 PM »
Same problem here.....

Offline gustav

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
Re: MOD: More correct variant of a TOP-rating
« Reply #13 on: June 07, 2006, 10:25:06 PM »
Oh,... and another problem... I show 10 imageas for ratings in the top list.... since the new algorythm, the last image is always one with 0 rating and 0 votes..... as soon as I rate it, it gets replaced by another one with 0/0.... any ideas?

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: MOD: More correct variant of a TOP-rating
« Reply #14 on: December 30, 2009, 10:40:40 AM »
Code: [Select]
ORDER BY ".(($selection[$cnt] == "rating") ? "((i.image_votes/15)^(1/3)) * (i.image_rating-3)" : "i.image_".$selection[$cnt])." DESC, i.image_".$selection_alt[$cnt];

For some reason this did not work for me... but this version did work just fine:
Code: [Select]
ORDER BY ".(($selection[$cnt] == "rating") ? "(POW((i.image_votes/15),(1/3))) * (i.image_rating-3)" : "i.image_".$selection[$cnt])." DESC, i.image_".$selection_alt[$cnt];