Gossamer Forum
Quote Reply
Ratings & Votes
I made some changes to the my_rate.cgi program. I may actually package it as a plugin, since it seems to be pretty good at the moment.

I need to remember how to hijack hooks, since one thing it does is replace the current build::rate routine. It gives a more accurate display, and the ability to set the limits on votes.

Check out http://postcards.com in the digital postcards area. The detail pages show the old hits/rating (as links was keeping score for the past few years), as well a the combined new/old total which is now stored in Votes and Rating for compatibility, and the new 1...10 detailed rating.

Also, the top_rated page was fixed up. A more proper ordering was given, and the page no longer says "Top 10 ..." anything, if only 3 links were found that met the vote criteria. If only 3 links were found, it says the "Top 3 Links with at least 2 votes" or whatever your vote cut off is. Also, I noticed that if you wanted the top 10 links with at least x-number of votes, the program did not find the top 10 rated links with the higest vote counts.... it should have. That's fixed now. So if you have 30 links with a rating of 10, but some have 3000 votes and some have 3 votes, those with the highest vote count get listed first.

If you want to make the changes to your site, edit the Build.pm routine, and look at the routine below. Fixing up the voting order requires *only* changing the two select statement lines in blue. Replace the "order by votes/rate" with the whole "group by...." string in quotes. That's all. You'll see the difference immediately. To add in the counting and phraseology changes, add in the other lines. Not portable... but it may eventually be a plugin that replaces the build_rate routine, but time ....


sub build_rating {
# ------------------------------------------------------------------
# Generate the rating pages.
my ($rated, $voted, $top_rated, $top_votes, $min_v, $max_v, $min_r, $max_r, $link);
my $cat_db = $DB->table('Category');
my $link_db = $DB->table('Links');
$GRAND_TOTAL ||= _grand_total();
my $VoteS = '2'; ## cut off for votes.
my $VoteS_Lim = '10'; ## max number of links to return.

$link_db->select_options ("GROUP BY Rating,Votes DESC ORDER BY Rating DESC ", "LIMIT $VoteS_Lim");
$rated = $link_db->select ( GT::SQL::Condition->new('Votes', '>=', $VoteS, 'isValidated', '=', 'Yes') );

$link_db->select_options ("GROUP BY Votes,Rating DESC ORDER BY Votes DESC", "LIMIT $VoteS_Lim");
$voted = $link_db->select ( GT::SQL::Condition->new('Votes', '>=', $VoteS, 'isValidated', '=', 'Yes') );

# Now build the html.
$top_rated = ''; ;$top_votes = '';
my $r_count = 0;
my $v_count= 0;

$min_v = 99999999; $max_v = 0;
my (@top_votes_loop, @top_rated_loop);
while ($link = $voted->fetchrow_hashref) {
$min_v = $link->{'Votes'} if ($min_v > $link->{'Votes'});
$max_v = $link->{'Votes'} if ($max_v < $link->{'Votes'});
push @top_votes_loop, $link;
$top_votes .= qq~<tr><td align=center>${$link}{'Votes'}</td><td align=center>${$link}{'Rating'}</td><td><a href="/cgi-bin/LinkSQL/my_rate.cgi?ID=${$link}{'ID'}">${$link}{'Title'}</a></td></tr>\n~;
$min_r = 99999999; $max_r = 0;
while ($link = $rated->fetchrow_hashref) {
$min_r = $link->{'Votes'} if ($min_r > $link->{'Votes'});
$max_r = $link->{'Votes'} if ($max_r < $link->{'Votes'});
push @top_rated_loop, $link;
$top_rated .= qq~<tr><td align=center>${$link}{'Rating'}</td><td align=center>${$link}{'Votes'}</td><td><a href="/cgi-bin/LinkSQL/my_rate.cgi?ID=${$link}{'ID'}">${$link}{'Title'}</a></td></tr>\n~;
# And write it to a file.
($min_v == 99999999) and ($min_v = 0);
($min_r == 99999999) and ($min_r = 0);
return Links::SiteHTML::display ('rate_top', {
vote_limit => $VoteS_Lim, # largest number of links returned either $r_count or $v_count
vote_cutoff => $VoteS, # largest number of links returned either $r_count or $v_count
vote_count => $v_count, # actual count of vote-links returned
rate_count => $r_count, # actual count of rate-links returned

top_rated => $top_rated,
top_rated_loop => \@top_rated_loop,
top_votes_loop => \@top_votes_loop,
top_votes => $top_votes

Add the lines in red, modify the lines in blue. The new select statement, gives a more accurate ordering of the votes and ratings.

On the rate_top.html page, use the following HTML fragment, it orders the "by vote" by votes first, and "by rate" with ratings first.


<p><strong>Top <%rate_count%> Resources (by Rating) -- with at least <%vote_cutoff%> votes</strong></p>
<table border=0>
<tr><th><strong>Rating</strong></th><th><strong># Votes</strong></th><th align=left><strong>Resource</strong></th></tr>
<p><strong>Top <%vote_count%> Resources (by Votes) -- with at least <%vote_cutoff%> votes</strong></p>
<table border=0>
<tr><th><strong># Votes</strong></th><th><strong>Rating</strong></th><th align=left><strong>Resource</strong></th></tr>

The my_rate advanced rating should be a plug in, but it needs to create 2 tables, add two columns to the links table and copy data, add 2 globals, change a few templates, override a hook, and a few other things. I also need to find, or rewrite, my change rating routine. That was lost somewhere, and I can't find it. eg: a user can vote once on a link, and only once, but they can change their vote if they'd like.

PUGDOG´┐Ż Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.