Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Big Error: Single rating becomes average rating

Quote Reply
Big Error: Single rating becomes average rating
After having been working on the upgrade to 2.0.3 on the side, I finally went public with it last night.

Everything seems fine, except for one BIG problem -- whenever someone rates a site, their rating is set as the AVERAGE rating. This, obviously, makes the ratings useless, and is causing me to lose all of the correct ratings for any site that gets a vote.

Example: Site A has 313 votes, and an average rating of 7.50. I rate it with a score of 9. Site A now has 314 votes, with an average rating of 9.00.

Some excerpts from my error log -- in the following bit, the link ID 22 got a rating of 10, and 10 was then set as the average rating.
In Reply To:
GT::SQL::Driver::MYSQL (8627): Preparing query: SELECT * FROM Links WHERE ( ID = '22' ) at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (8627): Preparing query: SELECT Title, URL FROM Links WHERE ID = 22 at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (8627): Preparing query: SELECT COUNT(*) FROM ClickTrack WHERE ClickType = 'Rate' AND IP = '213.123.132.239' AND LinkID = '22' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (8627): Preparing query: SELECT Votes,ID,Rating FROM Links WHERE ID = '22' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (8627): Preparing query: UPDATE Links SET Votes = '415' , Rating = '10' WHERE ID = '22' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (8627): Preparing query: SELECT COUNT(*) FROM ClickTrack WHERE ClickType = 'Rate' AND IP = '213.123.132.239' AND LinkID = '22' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (8627): Preparing query: INSERT INTO ClickTrack (Created,ClickType,IP,LinkID) VALUES (NOW(),'Rate','213.123.132.239','22') at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.
Also, I'm using the SearchLogger plug-in, and just noticed this in my error logs:
In Reply To:
GT::SQL::Driver::MYSQL (11976): Preparing query: SELECT * FROM SearchLog WHERE ( Term = 'bronze' ) at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (11976): Preparing query: SELECT Term,Results,HitCount FROM SearchLog WHERE Term = 'bronze' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (11976): Preparing query: UPDATE SearchLog SET Results = '6' , HitCount = '3' WHERE Term = 'bronze' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.
I don't know what the problem is, but the term "bronze" isn't in my search log.

Any help -- especially on the ratings problem -- would be greatly appreciated!

Jamie Marie


---------------------
BuffyGuide.com
Quote Reply
Re: Big Error: Single rating becomes average rating In reply to
I have 2.04 installed, and looking at the rate code:

Code:
my $tmp = $rec->{Rating} * $rec->{Votes};
$rec->{Rating} = ($rec->{Rating} * $rec->{Votes}) + $rating;
$rec->{Votes} = $rec->{Votes} + 1;
$rec->{Rating} = $rec->{Rating} / $rec->{Votes};
$db->indexing(0);
$db->update ( { Votes => $rec->{Votes}, Rating => $rec->{Rating} }, { ID => $rec->{ID} });
$db->indexing(1);
$click_db->insert ( { LinkID => $id, IP => $ENV{REMOTE_ADDR}, ClickType => 'Rate', Created => \"NOW()" } );
return $rec;
I see the $tmp variable not being used, but it looks like it should work.

Using the $tmp variable, the code would probably look like:

Code:
my $tmp = $rec->{Rating} * $rec->{Votes};
$tmp = $tmp + $rating;
$rec->{Votes} = $rec->{Votes} + 1;
$rec->{Rating} = $tmp / $rec->{Votes};
$db->indexing(0);
$db->update ( { Votes => $rec->{Votes}, Rating => $rec->{Rating} }, { ID => $rec->{ID} });
$db->indexing(1);
$click_db->insert ( { LinkID => $id, IP => $ENV{REMOTE_ADDR}, ClickType => 'Rate', Created => \"NOW()" } );
return $rec;
PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: Big Error: Single rating becomes average rating In reply to
Nope, no change; exact same result and resulting error log entries. Frown


I've noticed something else odd -- when I was looking at my error logs this time, I noticed that each hit to a link also yields errors in the log:
In Reply To:
GT::SQL::Driver::MYSQL (2871): Preparing query: SELECT * FROM Links WHERE ( ID = '637' ) at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (2871): Preparing query: SELECT COUNT(*) FROM ClickTrack WHERE ClickType = 'Hits' AND IP = '217.34.74.30' AND LinkID = '637' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (2871): Preparing query: SELECT Hits,ID FROM Links WHERE ID = '637' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (2871): Preparing query: UPDATE Links SET Hits = Hits + 1 WHERE ID = '637' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (2871): Preparing query: SELECT COUNT(*) FROM ClickTrack WHERE ClickType = 'Hits' AND IP = '217.34.74.30' AND LinkID = '637' at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.

GT::SQL::Driver::MYSQL (2871): Preparing query: INSERT INTO ClickTrack (Created,ClickType,IP,LinkID) VALUES (NOW(),'Hits','217.34.74.30','637') at /home/httpd/cgi-bin/linkssql/admin/GT/SQL/Driver/MYSQL.pm line 35.
As far as I can tell, the hits are being counted correctly, but then why the output to the error log?


~~~~~~~~~~~~~~~~~~~~~~
Jamie Marie
BuffyGuide.com
Quote Reply
Re: Big Error: Single rating becomes average rating In reply to
You probably have debug set to 1, rather than 0

This may have to be addressed by Alex. This is something that may actually be having a problem somewhere else.

I haven't hit this, maybe, because I've redone my hit/rate counting, and once I release the rating/review system, it will revamp all that as well.


PUGDOGŪ Enterprises, Inc.
FAQ:http://LinkSQL.com/FAQ
Forum:http://LinkSQL.com/forum
Quote Reply
Re: Big Error: Single rating becomes average rating In reply to
Oh for bugger's sake. Nevermind -- I'd had a hack in rate.cgi for version 1.11 (giving voters confirmation of what rating they'd given the site), and I'd apparently gone ahead and copied it over to 2.0.3. Removing it did the trick, so it was obviously uncompatible. Crazy

It's always something that should be obvious from the get-go. Thanks for trying to help, pugdog!


~~~~~~~~~~~~~~~~~~~~~~
Jamie Marie
BuffyGuide.com