X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=recalc-single-result.pl;h=efcd4c73891ef5a8af3aec31a168596261180bf0;hb=3516ce72f3ea14baaa54c3286e49cb9d7a1eee86;hp=679478791027ecb283f9ea6a88028b9ac8fc3d19;hpb=63503a1ac42bc03c97642b1ccbc07b2cfdad7a98;p=foosball diff --git a/recalc-single-result.pl b/recalc-single-result.pl index 6794787..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'); @@ -21,7 +29,7 @@ my $cll = 0.0; while (my $ref = $q->fetchrow_hashref) { for my $user (($ref->{'username1'}, $ref->{'username2'})) { if (!exists($ratings{$user})) { - $ratings{$user} = [ 1500, 350, 0 ]; + $ratings{$user} = [ $foosball::initial_rating, $foosball::initial_rd, 0 ]; } } @@ -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",