Gossamer Forum
Home : Products : Links 2.0 : Customization :

Minor ratings bug

Quote Reply
Minor ratings bug
Hi!
It seems to me, that there is a little bug in rating from links 2.0. It only stores ratings with two digits precision. If a link as more then 1000 votes, each new vote will change only the third digit, and this is removed by sprintf. So new votes will never change the rating, and will be lost! (It's very easy to change your code to avoid this!)

Bye
Tiggr

Quote Reply
Re: Minor ratings bug In reply to
Thanks for posting the "bug"...You might consider sharing the bug fix, so that others can benefit from your knowledge.

Regards,

Eliot Lee
Quote Reply
Re: Minor ratings bug In reply to
Hi!

> Thanks for posting the "bug"...

I think this isn't realy a bug...

>You might consider sharing the bug fix, so
>that others can benefit from your knowledge.

It was very easy, but my links 2.0 is very "messed up", so I hope this will helpfull someone with a more original links 2.0.

First in build_update_ratings in nph-build.cgi, I changed the line in which the rating is formated by sprintf from

Code:
$values[$db_rating] = sprintf("%.2f", $values[$db_rating]);
(the original line looked something like this, I doesn't kept the "old" code) to

Code:
$values[$db_rating] = $values[$db_rating];
(Yes, this is senseless, in fact...)

And in site_html_templates.pl, I changed site_html_link like this:

Code:
return &load_template ('link.html', {
detailed_url => "$db_detailed_url/$rec{'ID'}$build_extension",
new_img => $new_img,
%rec,
%globals,
Rating => sprintf ("%.2f", $rec{Rating})
});
(Shure, you have to finde all the other places where you use the ratings-value too, and change it too!)

That's all! (It's not very clever done, you have to change all places you output the value, but it was the easiest way to me. Perhabs it would be better to add a second ratings-field to the db, and store the unformated rating in it, and using the old one only for output?)

Bye
Tiggr