]> git.sesse.net Git - foosball/blobdiff - foosball.pm
Switch to more accurate double score calculation.
[foosball] / foosball.pm
index f87f7637d2039dd407db7aa6eca2d12af1f53cdc..a2b0d55b041ab4d8f6084f523dc8d680a31c4ecc 100644 (file)
@@ -15,6 +15,12 @@ sub find_single_rating {
        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);
 }
 
@@ -23,9 +29,23 @@ sub find_double_rating {
        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=?',
@@ -52,7 +72,7 @@ sub apply_aging {
 
 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;
 
@@ -61,4 +81,16 @@ sub calc_rating {
        return ($newr1, $newrd1);
 }
 
+sub calc_rating_double {
+       my ($rating1, $rd1, $rating2, $rd2, $rating3, $rd3, $rating4, $rd4, $score1, $score2) = @_;
+       my $result = `/srv/foosball.sesse.net/foosrank $rating1 $rd1 $rating2 $rd2 $rating3 $rd3 $rating4 $rd4 $score1 $score2`;
+       chomp $result;
+       my ($newr1, $newrd1) = split / /, $result;
+
+       $newrd1 = 30.0 if ($newrd1 < 30.0);
+
+       return ($newr1, $newrd1);
+}
+
+
 1;