my ($age, $rating, $rd) = $dbh->selectrow_array('SELECT EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP-ratetime)), rating, rd FROM single_rating WHERE username=? '.$limit.' ORDER BY ratetime DESC LIMIT 1',
undef, $username);
$rd = apply_aging($rd, $age / 86400.0);
+
+ if (!defined($rating)) {
+ $rating = 1500;
+ $rd = 350;
+ }
+
return ($rating, $rd);
}
my ($age, $rating, $rd) = $dbh->selectrow_array('SELECT EXTRACT(EPOCH FROM (CURRENT_TIMESTAMP-ratetime)), rating, rd FROM double_rating WHERE username=? '.$limit.'ORDER BY ratetime DESC LIMIT 1',
undef, $username);
$rd = apply_aging($rd, $age / 86400.0);
+
+ if (!defined($rating)) {
+ $rating = 1500;
+ $rd = 350;
+ }
+
return ($rating, $rd);
}
+sub combine_ratings {
+ my ($rating1, $rd1, $rating2, $rd2) = @_;
+
+ my $rating_team = 0.5 * ($rating1 + $rating2);
+ my $rd_team = sqrt($rd1 * $rd1 + $rd2 * $rd2) / sqrt(2.0);
+ return ($rating_team, $rd_team);
+}
+
sub create_user_if_not_exists {
my ($dbh, $username) = @_;
my $count = $dbh->selectrow_array('SELECT count(*) FROM users WHERE username=?',
return $dbh;
}
-# 10-9 is 0.60
-# 10-0 is 1.00
-sub find_score {
- my ($score1, $score2) = @_;
- if ($score1 == 10) {
- # yay, a win
- return 0.60 + 0.40 * (9.0-$score2)/9.0;
- }
- if ($score2 == 10) {
- # a loss
- return 0.40 - 0.40 * (9.0-$score1)/9.0;
- }
- die "Nobody won?";
-}
-
# c=8 => RD=50 moves to RD=350 over approx. five years
our $c = 8;
sub calc_rating {
my ($rating1, $rd1, $rating2, $rd2, $score1, $score2) = @_;
- my $result = `/srv/foosball.sesse.net/foorank $rating1 $rd1 $rating2 $rd2 $score1 $score2`;
+ my $result = `/srv/foosball.sesse.net/foosrank $rating1 $rd1 $rating2 $rd2 $score1 $score2`;
chomp $result;
my ($newr1, $newrd1) = split / /, $result;