From 379a01dba1fd98ed632d495c7e6ca47244f8c60e Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 9 Dec 2007 15:33:04 +0100 Subject: [PATCH] Add a "dry run" mode to recalc-single-result, for easier testing. --- recalc-single-result.pl | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/recalc-single-result.pl b/recalc-single-result.pl index 8c6923b..efcd4c7 100755 --- a/recalc-single-result.pl +++ b/recalc-single-result.pl @@ -5,11 +5,19 @@ use DBI; use CGI; use CGI::Carp qw(fatalsToBrowser); require 'foosball.pm'; +no warnings 'once'; + +my $dryrun = 0; +if (defined($ARGV[0])) { + $dryrun = 1; + $foosball::initial_rd = $ARGV[0]; + $foosball::c = $ARGV[1]; +} my $dbh = foosball::db_connect(); $dbh->{AutoCommit} = 0; -$dbh->do('delete from single_rating'); +$dbh->do('delete from single_rating') unless $dryrun; my %ratings = (); my $q = $dbh->prepare('select *,extract(epoch from gametime) as eptime from single_results order by gametime'); @@ -44,19 +52,21 @@ while (my $ref = $q->fetchrow_hashref) { $cll += log($likelihood); - printf("%-10s - %-10s: %u - %u, new ratings %u/%u %u/%u [$likelihood]\n", - $ref->{'username1'}, $ref->{'username2'}, $ref->{'score1'}, - $ref->{'score2'}, $newr1, $newrd1, $newr2, $newrd2); - $dbh->do('insert into single_rating values (?,?,?,?,?)', undef, - $ref->{'username1'}, $ref->{'gametime'}, $newr1, $newrd1, $newr1-$rating1); - $dbh->do('insert into single_rating values (?,?,?,?,?)', undef, - $ref->{'username2'}, $ref->{'gametime'}, $newr2, $newrd2, $newr2-$rating2); + unless ($dryrun) { + printf("%-10s - %-10s: %u - %u, new ratings %u/%u %u/%u [$likelihood]\n", + $ref->{'username1'}, $ref->{'username2'}, $ref->{'score1'}, + $ref->{'score2'}, $newr1, $newrd1, $newr2, $newrd2); + $dbh->do('insert into single_rating values (?,?,?,?,?)', undef, + $ref->{'username1'}, $ref->{'gametime'}, $newr1, $newrd1, $newr1-$rating1); + $dbh->do('insert into single_rating values (?,?,?,?,?)', undef, + $ref->{'username2'}, $ref->{'gametime'}, $newr2, $newrd2, $newr2-$rating2); + } $ratings{$ref->{'username1'}} = [ $newr1, $newrd1, $ref->{'eptime'} ]; $ratings{$ref->{'username2'}} = [ $newr2, $newrd2, $ref->{'eptime'} ]; } -$dbh->commit; +$dbh->commit unless $dryrun; $dbh->disconnect; printf "\nCombined negative log-likelihood (smaller value means a better model): %f\n", -- 2.39.2