]> git.sesse.net Git - foosball/blobdiff - foosball.pm
Switch to using Simpson's rule for the moment estimation as well, which seems
[foosball] / foosball.pm
index fd46aae029677a34122ddd1f9033c522a6fbe48d..f87f7637d2039dd407db7aa6eca2d12af1f53cdc 100644 (file)
@@ -40,21 +40,6 @@ sub create_user_if_not_exists {
        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;
 
@@ -65,38 +50,11 @@ sub apply_aging {
        return $rd;
 }
 
-our $q = log(10)/400.0;
-our $pi = 3.1415926535897932384626433832795;
-
-# computes a^b
-sub pow {
-       my ($a, $b) = @_;
-
-       # a^b = exp(log(a^b)) = exp(b log a)
-       return exp($b * log($a));
-}
-
-sub g {
-       my $rd = shift;
-       return 1.0 / sqrt(1.0 + 3.0 * $q * $q * $rd * $rd / ($pi*$pi));
-}
-
-sub E {
-       my ($r, $rating, $rd) = @_;
-       return 1.0 / (1.0 + pow(10.0, -g($rd) * ($r - $rating) / 400.0));
-}
-
-sub dsq {
-       my ($r, $rating, $rd) = @_;
-       return 1.0 / ($q*$q * g($rd) * g($rd) * E($r, $rating, $rd) * (1 - E($r, $rating, $rd)));
-}
-
 sub calc_rating {
        my ($rating1, $rd1, $rating2, $rd2, $score1, $score2) = @_;
-       my $s1 = find_score($score1, $score2);
-       my $d1sq = dsq($rating1, $rating2, $rd2);
-       my $newr1 = $rating1 + ($q / (1.0/($rd1*$rd1) + 1.0 / $d1sq)) * g($rd2) * ($s1 - E($rating1, $rating2, $rd2));
-       my $newrd1 = sqrt(1.0 / (1.0 / ($rd1*$rd1) + 1.0 / $d1sq));
+       my $result = `/srv/foosball.sesse.net/foorank $rating1 $rd1 $rating2 $rd2 $score1 $score2`;
+       chomp $result;
+       my ($newr1, $newrd1) = split / /, $result;
 
        $newrd1 = 30.0 if ($newrd1 < 30.0);