$q->execute;
while (my $ref = $q->fetchrow_hashref) {
for my $user (($ref->{'username1'}, $ref->{'username2'})) {
if (!exists($ratings{$user})) {
$q->execute;
while (my $ref = $q->fetchrow_hashref) {
for my $user (($ref->{'username1'}, $ref->{'username2'})) {
if (!exists($ratings{$user})) {
my ($newr1, $newrd1) = foosball::calc_rating($rating1, $rd1, $rating2, $rd2, $score1, $score2);
my ($newr2, $newrd2) = foosball::calc_rating($rating2, $rd2, $rating1, $rd1, $score2, $score1);
printf("%-10s - %-10s: %u - %u, new ratings %u/%u %u/%u\n",
$ref->{'username1'}, $ref->{'username2'}, $ref->{'score1'},
$ref->{'score2'}, $newr1, $newrd1, $newr2, $newrd2);
my ($newr1, $newrd1) = foosball::calc_rating($rating1, $rd1, $rating2, $rd2, $score1, $score2);
my ($newr2, $newrd2) = foosball::calc_rating($rating2, $rd2, $rating1, $rd1, $score2, $score1);
printf("%-10s - %-10s: %u - %u, new ratings %u/%u %u/%u\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);
- $dbh->do('insert into single_rating values (?,?,?,?)', undef,
- $ref->{'username2'}, $ref->{'gametime'}, $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 ];
- $ratings{$ref->{'username2'}} = [ $newr2, $newrd2 ];
+ $ratings{$ref->{'username1'}} = [ $newr1, $newrd1, $ref->{'eptime'} ];
+ $ratings{$ref->{'username2'}} = [ $newr2, $newrd2, $ref->{'eptime'} ];