Gossamer Forum
Home : Products : Links 2.0 : Customization :

Expanding Ratings...

Quote Reply
Expanding Ratings...
I was wondering if anyone has attempted to make a ratings mod to allow you to expand the # of links listed on the top ratings page. What I'm looking for is somthing to allow me to list the top 10 links, by votes and ratings (already there), but also to list the rest of the links that have been voted on, but don't have a high enough rating/# of votes to be listed in the top 2 categories.

Anyone try anything like this? or care to try Smile ?

Regards,

------------------
Jacob Wheeler
jacob@123webmaster.com
http://www.123webmaster.com
http://www.online-freebies.com
ICQ:#390147
Quote Reply
Re: Expanding Ratings... In reply to
Shouldn't be too hard to do, if you know a little perl, just look at the routine, and after you find the top two tables, go through it again (duplicate the code) but this time look for everything BELOW the cut off and add it to the bottom of the page -- could be very, very long.....
Quote Reply
Re: Expanding Ratings... In reply to
man.. why did you have to log off icq? Smile

anyways.. after i ate.. i did your script..

here you go..

find this in nph-build.cgi sub build_ratings_page:

Code:
next if ($votes < 10);

[ next if ($votes < 5); in links2b5 Smile ]

change it to:

Code:
if ($votes < 10) {
if ($votes > 1) {
push (@{$top_others{$votes}}, @values);
if ($#top_other <= 10) {
push (@top_others, $votes);
@top_others = sort { $b <=> $a } @top_others;
}
else {
splice (@{$top_others{$#top_others}}, 0, $#db_cols);
$#{$top_others{$#top_others}} or delete $top_others{$#top_others};
delete $top_others{$top_others[$#top_others]-$id};
$top_others[$#top_others] = $votes;
@top_others = sort { $b <=> $a } @top_others;
}
}
next;
}

on the second line.. change the 1 to make the minimum vote Smile

find:

Code:
foreach (sort { $b <=> $a } @top_rate) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});
$top_rated .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;
}

and add this after it..

Code:
foreach (sort { $b <=> $a } @top_others) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_others{$_}});
$top_others .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;
}

now in site_html.pl (figure out templates yourself.. :P) hehe

add this anywhere inside sub site_html_ratings

Code:
<p><strong>Other Resources</strong></p>
<div class=margin>
<table border=0>
<tr><th><strong>Rating</strong></th><th><strong># Votes</strong></th><th align=left><strong>Resource</strong></th></tr>
$top_others
</table>
</div>

[This message has been edited by widgetz (edited July 20, 1999).]
Quote Reply
Re: Expanding Ratings... In reply to
Ok, here's what I got:

Code:
sub build_rate_page {
# --------------------------------------------------------
# Creates a Top 10 ratings page.

my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate);
local ($top_rated, $top_votes);

if ($build_ratings_path =~ m,^$build_root_path/(.*)$,) {
&build_dir ($1);
}

$total = 0;

open (LINKS, $db_links_name) or &cgierr ("unable to open links database: $db_links_name. Reason: $!");
LINE: while (<LINKS> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp;
@values = &split_decode ($_);
$id = $values[$db_key_pos];
$votes = $values[$db_votes];
$rate = $values[$db_rating];

if ($votes < 5) {
if ($votes > 1) {
push (@{$top_others{$votes}}, @values);
if ($#top_other <= 10) {
push (@top_others, $votes);
@top_others = sort { $b <=> $a } @top_others;
}
else {
splice (@{$top_others{$#top_others}}, 0, $#db_cols);
$#{$top_others{$#top_others}} or delete $top_others{$#top_others};
delete $top_others{$top_others[$#top_others]-$id};
$top_others[$#top_others] = $votes;
@top_others = sort { $b <=> $a } @top_others;
}

next;
}

else {
splice (@{$top_votes{$#top_votes}}, 0, $#db_cols);
$#{$top_votes{$#top_votes}} or delete $top_votes{$#top_votes};
delete $top_votes{$top_votes[$#top_votes]-$id};
$top_votes[$#top_votes] = $votes;
@top_votes = sort { $b <=> $a } @top_votes;
}
}
if (($#top_rate < 9) or ($rate > $top_rate[$#top_rate])) {
push (@{$top_rate{$rate}}, @values);
if ($#top_rate <= 5) {
push (@top_rate, $rate);
@top_rate = sort { $b <=> $a } @top_rate;
}
else {
splice (@{$top_rate{$#top_rate}}, 0, $#db_cols);
$#{$top_rate{$#top_rate}} or delete $top_rate{$#top_rate};
delete $top_rate{$top_rate[$#top_rate]-$id};
$top_rate[$#top_rate] = $rate;
@top_rate = sort { $b <=> $a } @top_rate;
}
}
}
close LINKS;

$top_rated = ''; $top_votes = '';

foreach (sort { $b <=> $a } @top_votes) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}});
$top_votes .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;
}
foreach (sort { $b <=> $a } @top_rate) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});
$top_rated .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;
}
foreach (sort { $b <=> $a } @top_others) {
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_others{$_}});
$top_others .= qq~<tr><td align=center>$link{'Rating'}</td><td align=center>$link{'Votes'}</td><td><a href="$link{'URL'}">$link{'Title'}</a></td></tr>\n~;
}

open (RATE, ">$build_ratings_path/$build_index") or &cgierr ("unable to open top rated page: $build_ratings_path/$build_index. Reason: $!");
print "\tVote Range: $top_votes[0] .. $top_votes[$#top_votes]\n";
print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";
print RATE &site_html_ratings;
close RATE;
}

And when I try and run it I get the following error:

Code:
fatal error: Modification of non-creatable array value attempted, subscript -1 at nph-build.cgi line 1077, chunk 1.

Whatever that means Smile

Thanks,


------------------
Jacob Wheeler
jacob@123webmaster.com
http://www.123webmaster.com
http://www.online-freebies.com
ICQ:#390147
Quote Reply
Re: Expanding Ratings... In reply to
oops.. put

%top_others, @top_others

in the top MY thing Smile