Hi,
I recently created a simple mod to the database, HitsPerWeek. It is exactly what it is called, the average amount of hits a link gets in a week.
This is displayed perfectly with the link.
As a supplement to this, I wanted to add the Top 10 Skins (by Hits Per Week) to the Top 10 page (which I have also modified to include the Top 10 Skins (by Total Downloads) (cool links).
I have gotten it to display 10 skins and their hitsperweek, but it is just the first 10 entries in my database, and not the *Top* 10 at all. I assume that the database needs to be sorted by the HitsPerWeek field, then selects the first 10 skins, instead of just selecting the first 10.
www.tobia.com/skins/ratings/ to view the current Top 10 page, complete with the Top 10 Skins (by Total Downloads), Top 10 Skins (by Hits Per Week) (which is currently not the top 10, just the first 10, etc.
My build_rate_page prcedure is as follows:
# --------------------------------------------------------
# Creates a Top 10 ratings page.
my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate, %link_output, $category_clean);
local ($top_rated, $top_votes, $total, $percent, $link_results, $title_linked);
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];
$hitsWeek = $values[$db_HitsPerWeek];
if (($#top_HitsWeek < 9) or ($HitsWeek > $top_HitsWeek[$#top_HitsWeek])) {
push (@{$top_HitsWeek{$HitsWeek}}, @values);
if ($#top_HitsWeek <= 9) {
push (@top_HitsWeek, $HitsWeek);
@top_HitsWeek = sort { $b <=> $a } @top_HitsWeek;
}
else {
splice (@{$top_HitsWeek{$#top_HitsWeek}}, 0, $#db_cols);
$#{$top_HitsWeek{$#top_HitsWeek}} or delete $top_HitsWeek{$#top_HitsWeek};
delete $top_HitsWeek{$top_HitsWeek[$#top_HitsWeek]-$id};
$top_HitsWeek[$#top_HitsWeek] = $HitsWeek;
@top_HitsWeek = sort { $b <=> $a } @top_HitsWeek;
}
}
next if ($votes < 10);
if (($#top_votes < 8) or ($votes > $top_votes[$#top_votes])) {
push (@{$top_votes{$votes}}, @values);
if ($#top_votes <= 8) {
push (@top_votes, $votes);
@top_votes = sort { $b <=> $a } @top_votes;
}
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 < 8) or ($rate > $top_rate[$#top_rate])) {
push (@{$top_rate{$rate}}, @values);
if ($#top_rate <= 8) {
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;
$total = 0;
CATEGORY: foreach $hit (sort {$b <=> $a} keys %cool_links) {
LINK: for ($i = 0; $i < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
%tmp = &array_to_hash ($i, @{$cool_links{$category}}, $total);
$link_output{$category} .= &site_popular_html_link (%tmp) . "\n";
}
}
foreach $hit (sort {$b <=> $a} keys %cool_links) {
$link_results .= $link_output{$hit};
}
$top_rated = ''; $top_votes = ''; $top_HitsWeek = ''; $countRate='0';
foreach (sort { $b <=> $a } @top_HitsWeek) {
$countRate++;
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_HitsWeek{$_}});
$top_HitsWeek .= qq~<tr><td>$countRate</td><td align=center width="15%">$link{'HitsPerWeek'}</td><td width="50%"><a href="$build_jump_url?$db_key=$link{$db_key}" title="Click here to download $link{'Title'}.">$link{'Title'}</a></td><td width="35%"><a href="$build_search_url?query=$link{'Title'}">View a Screen-Shot</a></td></tr>\n~;
}
$countRate='0';
foreach (sort { $b <=> $a } @top_votes) {
$countRate++;
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}});
$top_votes .= qq~<tr><td>$countRate</td><td align=center width="15%">$link{'Rating'}</td><td align=center width="15%">$link{'Votes'}</td><td width="35%"><a href="$build_jump_url?$db_key=$link{$db_key}" title="Click here to download $link{'Title'}.">$link{'Title'}</a></td><td width="35%"><a href="$build_search_url?query=$link{'Title'}">View a Screen-Shot</a></td></tr>\n~;
}
$countRate='0';
foreach (sort { $b <=> $a } @top_rate) {
$countRate++;
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});
$top_rated .= qq~<tr><td>$countRate</td><td align=center width="15%">$link{'Rating'}</td><td align=center width="15%">$link{'Votes'}</td><td width="35%"><a href="$build_jump_url?$db_key=$link{$db_key}" title="Click here to download $link{'Title'}.">$link{'Title'}</a></td><td width="35%"><a href="$build_search_url?query=$link{'Title'}">View a Screen-Shot</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 "\tHitsPerWeek Range: $top_HitsWeek[0] .. $top_HitsWeek[$#top_HitsWeek]\n";
print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";
print RATE &site_html_ratings;
close RATE;
}
ANY help would be GREATLY appreciate, as soon as possible too.
Thanks
Robbo
[This message has been edited by 1Robbo1 (edited March 24, 2000).]
[This message has been edited by 1Robbo1 (edited March 24, 2000).]
I recently created a simple mod to the database, HitsPerWeek. It is exactly what it is called, the average amount of hits a link gets in a week.
This is displayed perfectly with the link.
As a supplement to this, I wanted to add the Top 10 Skins (by Hits Per Week) to the Top 10 page (which I have also modified to include the Top 10 Skins (by Total Downloads) (cool links).
I have gotten it to display 10 skins and their hitsperweek, but it is just the first 10 entries in my database, and not the *Top* 10 at all. I assume that the database needs to be sorted by the HitsPerWeek field, then selects the first 10 skins, instead of just selecting the first 10.
www.tobia.com/skins/ratings/ to view the current Top 10 page, complete with the Top 10 Skins (by Total Downloads), Top 10 Skins (by Hits Per Week) (which is currently not the top 10, just the first 10, etc.
My build_rate_page prcedure is as follows:
Code:
sub build_rate_page { # --------------------------------------------------------
# Creates a Top 10 ratings page.
my (@values, $id, $votes, $rate, @top_votes, %top_votes, @top_rate, %top_rate, %link_output, $category_clean);
local ($top_rated, $top_votes, $total, $percent, $link_results, $title_linked);
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];
$hitsWeek = $values[$db_HitsPerWeek];
if (($#top_HitsWeek < 9) or ($HitsWeek > $top_HitsWeek[$#top_HitsWeek])) {
push (@{$top_HitsWeek{$HitsWeek}}, @values);
if ($#top_HitsWeek <= 9) {
push (@top_HitsWeek, $HitsWeek);
@top_HitsWeek = sort { $b <=> $a } @top_HitsWeek;
}
else {
splice (@{$top_HitsWeek{$#top_HitsWeek}}, 0, $#db_cols);
$#{$top_HitsWeek{$#top_HitsWeek}} or delete $top_HitsWeek{$#top_HitsWeek};
delete $top_HitsWeek{$top_HitsWeek[$#top_HitsWeek]-$id};
$top_HitsWeek[$#top_HitsWeek] = $HitsWeek;
@top_HitsWeek = sort { $b <=> $a } @top_HitsWeek;
}
}
next if ($votes < 10);
if (($#top_votes < 8) or ($votes > $top_votes[$#top_votes])) {
push (@{$top_votes{$votes}}, @values);
if ($#top_votes <= 8) {
push (@top_votes, $votes);
@top_votes = sort { $b <=> $a } @top_votes;
}
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 < 8) or ($rate > $top_rate[$#top_rate])) {
push (@{$top_rate{$rate}}, @values);
if ($#top_rate <= 8) {
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;
$total = 0;
CATEGORY: foreach $hit (sort {$b <=> $a} keys %cool_links) {
LINK: for ($i = 0; $i < ($#{$cool_links{$category}}+1) / ($#db_cols + 1); $i++) {
$total++;
%tmp = &array_to_hash ($i, @{$cool_links{$category}}, $total);
$link_output{$category} .= &site_popular_html_link (%tmp) . "\n";
}
}
foreach $hit (sort {$b <=> $a} keys %cool_links) {
$link_results .= $link_output{$hit};
}
$top_rated = ''; $top_votes = ''; $top_HitsWeek = ''; $countRate='0';
foreach (sort { $b <=> $a } @top_HitsWeek) {
$countRate++;
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_HitsWeek{$_}});
$top_HitsWeek .= qq~<tr><td>$countRate</td><td align=center width="15%">$link{'HitsPerWeek'}</td><td width="50%"><a href="$build_jump_url?$db_key=$link{$db_key}" title="Click here to download $link{'Title'}.">$link{'Title'}</a></td><td width="35%"><a href="$build_search_url?query=$link{'Title'}">View a Screen-Shot</a></td></tr>\n~;
}
$countRate='0';
foreach (sort { $b <=> $a } @top_votes) {
$countRate++;
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_votes{$_}});
$top_votes .= qq~<tr><td>$countRate</td><td align=center width="15%">$link{'Rating'}</td><td align=center width="15%">$link{'Votes'}</td><td width="35%"><a href="$build_jump_url?$db_key=$link{$db_key}" title="Click here to download $link{'Title'}.">$link{'Title'}</a></td><td width="35%"><a href="$build_search_url?query=$link{'Title'}">View a Screen-Shot</a></td></tr>\n~;
}
$countRate='0';
foreach (sort { $b <=> $a } @top_rate) {
$countRate++;
$seen{$_}++;
%link = &array_to_hash ($seen{$_} - 1, @{$top_rate{$_}});
$top_rated .= qq~<tr><td>$countRate</td><td align=center width="15%">$link{'Rating'}</td><td align=center width="15%">$link{'Votes'}</td><td width="35%"><a href="$build_jump_url?$db_key=$link{$db_key}" title="Click here to download $link{'Title'}.">$link{'Title'}</a></td><td width="35%"><a href="$build_search_url?query=$link{'Title'}">View a Screen-Shot</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 "\tHitsPerWeek Range: $top_HitsWeek[0] .. $top_HitsWeek[$#top_HitsWeek]\n";
print "\tRate Range: $top_rate[0] .. $top_rate[$#top_rate]\n";
print RATE &site_html_ratings;
close RATE;
}
ANY help would be GREATLY appreciate, as soon as possible too.
Thanks
Robbo
[This message has been edited by 1Robbo1 (edited March 24, 2000).]
[This message has been edited by 1Robbo1 (edited March 24, 2000).]