Gossamer Forum
Home : Products : DBMan : Customization :

Ask for adding the "Rate" into dbman-sql version

(Page 3 of 3)
> >
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
Hi Eliot,

I finally got the Rating to show correctly (via Crontab) by adding a field to default.cfg called "Votes" and the code:

Code:
$db_votes = 15;

However, when I run buildrates.cgi, the ID file in the temp Ratings folder and the default.db.bak files are deleted. Is this supposed to happen? Also, the number of votes in the DB is not recorded although the rating correctly shows as 8.00 if I vote 8, etc. If I rate again (i.e. 3), the 8.00 is replaced with 3.0. Hope this is helpful. Thanks.

Cary
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
That could possibly be happening with the exclusion of the following line in the build_update_ratings:

Code:
$values[$db_votes] = $values[$db_votes] + $votes{$id};

Although if you are using the crontab method...you cannot use the buildrate.cgi file. If you are using the crontab method...do NOT use the buildrate.cgi script! Also, make sure that you have not included the sub build_update_rating routine and also the call for this routine (&build_update_rating, in the rate.cgi script. DO NOT mix up these methods...Use one of them...not all.

BTW: The id files in the $db_rates_path should be deleted upon updating the ratings. However, the database file and bak file
should NOT be deleted. If you are not on a UNIX server, then the problem could be with the chmod 666 codes.

Are you on a UNIX server??

Replace the sub build_update_ratings with the following codes:

Code:
sub build_update_ratings {
# --------------------------------------------------------
# Updates the ratings of each link.
#

# Let's collect the ratings.
my ($id, %rating, %votes, @values, $input);
opendir (HITS, $db_rates_path) or &cgierr ("unable to open ratings directory: $db_rates_path. Reason: $!");
while (defined ($id = readdir HITS)) {
next unless ($id =~ /^\d+$/);
open (HIT, "$db_rates_path/$id") or &cgierr ("unable to open rating counter: $db_rates_path/$id. Reason: $!");
my $input = <HIT>;
chomp $input;
($votes{$id}, $rating{$id}) = split /\s/, $input;
close HIT;
}
closedir HITS;

# Update the links database.
open (DB, "$db_file_name") or &cgierr ("unable to open links database: $db_file_name. Reason: $!");
open (DBTMP, ">$db_file_name.bak") or &cgierr ("unable to open temp links database: $db_file_name.bak. Reason: $!");
LINE: while (<DB> ) {
/^#/ and print OUT and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@values = split /\Q$db_delim\E/;
$id = $values[0];

if (exists $votes{$id}) {
$values[$db_rating] = (($values[$db_rating] * $values[$db_votes]) + $rating{$id}) /
($values[$db_votes] + $votes{$id});
$values[$db_rating] = sprintf ("%.2f", $values[$db_rating]);
$values[$db_votes] = $values[$db_votes] + $votes{$id};
print "\tUpdating rating to $values[$db_rating] for link id $id\n";
}
print DBTMP &join_encode(&array_to_hash(0, @values));
}
close DB;
close DBTMP;

if (-s "$db_file_name.bak" > 0) {
if (! rename ("$db_file_name.bak", $db_file_name)) {
print "\tCouldn't rename! Had to copy. Strange: $!\n";
open (DBTMP, ">$db_file_name") or
&cgierr ("unable to open links database: $db_file_name. Reason: $!");
open (DB, "$db_file_name.bak") or
&cgierr ("unable to open temp links database: $db_file_name.bak. Reason: $!");
while ( ) { print DBTMP; }
close DB;
close DBTMP;
}
else { chmod 0666, $db_file_name; }
}
else {
&cgierr ("Error building! Links database is 0 bytes!");
}


# Delete the ratings.
foreach (keys %votes) {
unlink ("$db_rates_path/$_") or &cgierr ("unable to remove rating: $db_rates_path/$_. Reason: $!");
}
}

Hope this helps.

Regards,

------------------
Eliot Lee....
* Check Resource Center
* Search Forums



[This message has been edited by AnthroRules (edited February 20, 2000).]
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
Hi Eliot,

Should I be concerned that it's deleting the BAK file? I will be running the cron hourly. Thanks Smile

Cary
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
No not really...If you do not want to delete the .bak file and be able to restore recent Ratings, then delete the following codes in the sub-routine that I recently gave you in my recent reply:

Code:
if (-s "$db_file_name.bak" > 0) {
if (! rename ("$db_file_name.bak", $db_file_name)) {
print "\tCouldn't rename! Had to copy. Strange: $!\n";
open (DBTMP, ">$db_file_name") or
&cgierr ("unable to open links database: $db_file_name. Reason: $!");
open (DB, "$db_file_name.bak") or
&cgierr ("unable to open temp links database: $db_file_name.bak. Reason: $!");
while ( ) { print DBTMP; }
close DB;
close DBTMP;
}
else { chmod 0666, $db_file_name; }
}
else {
&cgierr ("Error building! Links database is 0 bytes!");
}

See if that keeps the .bak file.

Regards,

------------------
Eliot Lee....
* Check Resource Center
* Search Forums

Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
Hi Eliot,

That keeps the BAK file, but it updates the BAK file instead of the regular DB. Thanks.

Cary
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
Just leave the codes as I wrote...Do not delete the .bak file codes that I suggested you delete.

I have lost patience with dealing with this Mod...Let me sit on it for a couple of days. It is a small bug since the ratings are being incremented.

If you find a solution, great...but I have loss patience to deal with this.

Sorry..

Regards,

------------------
Eliot Lee....
* Check Resource Center
* Search Forums



[This message has been edited by AnthroRules (edited February 20, 2000).]
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
Hi Cary,

If you get a chance, I would love to get a copy of the final working instructions and edits for this rating mod - looks great!

Please follow Eliot's suggestion and post it under 'mods' or can you email the files to me?

Cheers!

Miles.
Quote Reply
Re: Ask for adding the "Rate" into dbman-sql version In reply to
Yes...that would be best, since Mods posted in the Forums tend to get lost in the shuffle.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
> >