]> git.sesse.net Git - foosball/commitdiff
Support double assessment, now that it's fast.
authorSteinar H. Gunderson <sesse@debian.org>
Wed, 17 Oct 2007 19:14:02 +0000 (21:14 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Wed, 17 Oct 2007 19:14:02 +0000 (21:14 +0200)
foosrank.cpp
www/assess-double.pl [new file with mode: 0755]
www/assess-double.xml [new file with mode: 0644]
www/index.xml

index cae1dc39382c7fabfb554753204146a7d440c422..cc660764762885eacd62abf9362e7b7cca54e3c3 100644 (file)
@@ -488,7 +488,7 @@ int main(int argc, char **argv)
        double mu2 = atof(argv[3]);
        double sigma2 = atof(argv[4]);
 
-       if (argc > 8) {
+       if (argc > 10) {
                double mu3 = atof(argv[5]);
                double sigma3 = atof(argv[6]);
                double mu4 = atof(argv[7]);
@@ -498,6 +498,36 @@ int main(int argc, char **argv)
                double mu, sigma;
                compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, score1, score2, mu, sigma);
                printf("%f %f\n", mu, sigma);
+       } else if (argc > 8) {
+               double mu3 = atof(argv[5]);
+               double sigma3 = atof(argv[6]);
+               double mu4 = atof(argv[7]);
+               double sigma4 = atof(argv[8]);
+               int k = atoi(argv[9]);
+               
+               // assess all possible scores
+               for (int i = 0; i < k; ++i) {
+                       double newmu1_1, newmu1_2, newmu2_1, newmu2_2;
+                       double newsigma1_1, newsigma1_2, newsigma2_1, newsigma2_2;
+                       compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, k, i, newmu1_1, newsigma1_1);
+                       compute_new_double_rating(mu2, sigma2, mu1, sigma1, mu3, sigma3, mu4, sigma4, k, i, newmu1_2, newsigma1_2);
+                       compute_new_double_rating(mu3, sigma3, mu4, sigma4, mu1, sigma1, mu2, sigma2, i, k, newmu2_1, newsigma2_1);
+                       compute_new_double_rating(mu4, sigma4, mu3, sigma3, mu1, sigma1, mu2, sigma2, i, k, newmu2_2, newsigma2_2);
+                       printf("%u-%u,%f,%+f,%+f,%+f,%+f\n",
+                               k, i, prob_score(k, i, mu3+mu4-(mu1+mu2)), newmu1_1-mu1, newmu1_2-mu2,
+                               newmu2_1-mu3, newmu2_2-mu4);
+               }
+               for (int i = k; i --> 0; ) {
+                       double newmu1_1, newmu1_2, newmu2_1, newmu2_2;
+                       double newsigma1_1, newsigma1_2, newsigma2_1, newsigma2_2;
+                       compute_new_double_rating(mu1, sigma1, mu2, sigma2, mu3, sigma3, mu4, sigma4, i, k, newmu1_1, newsigma1_1);
+                       compute_new_double_rating(mu2, sigma2, mu1, sigma1, mu3, sigma3, mu4, sigma4, i, k, newmu1_2, newsigma1_2);
+                       compute_new_double_rating(mu3, sigma3, mu4, sigma4, mu1, sigma1, mu2, sigma2, k, i, newmu2_1, newsigma2_1);
+                       compute_new_double_rating(mu4, sigma4, mu3, sigma3, mu1, sigma1, mu2, sigma2, k, i, newmu2_2, newsigma2_2);
+                       printf("%u-%u,%f,%+f,%+f,%+f,%+f\n",
+                               i, k, prob_score(k, i, mu1+mu2-(mu3+mu4)), newmu1_1-mu1, newmu1_2-mu2,
+                               newmu2_1-mu3, newmu2_2-mu4);
+               }
        } else if (argc > 6) {
                int score1 = atoi(argv[5]);
                int score2 = atoi(argv[6]);
diff --git a/www/assess-double.pl b/www/assess-double.pl
new file mode 100755 (executable)
index 0000000..bc60069
--- /dev/null
@@ -0,0 +1,85 @@
+#! /usr/bin/perl
+use strict;
+use warnings;
+use DBI;
+use CGI;
+use CGI::Carp qw(fatalsToBrowser);
+use lib qw(/srv/bzr.sesse.net/www/xml-template/perl/);
+use XML::Template;
+require '../foosball.pm';
+
+my $cgi = CGI->new;
+
+my $username1_1 = $cgi->param('team1_username1');
+$username1_1 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 1.1";
+$username1_1 = $1;
+
+my $username1_2 = $cgi->param('team1_username2');
+$username1_2 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 1.2";
+$username1_2 = $1;
+
+my $username2_1 = $cgi->param('team2_username1');
+$username2_1 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 2.1";
+$username2_1 = $1;
+
+my $username2_2 = $cgi->param('team2_username2');
+$username2_2 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 2.2";
+$username2_2 = $1;
+
+my $dbh = foosball::db_connect();
+
+# fetch the double ratings
+my ($rating1_1, $rd1_1) = foosball::find_double_rating($dbh, $username1_1);
+my ($rating1_2, $rd1_2) = foosball::find_double_rating($dbh, $username1_2);
+my ($rating2_1, $rd2_1) = foosball::find_double_rating($dbh, $username2_1);
+my ($rating2_2, $rd2_2) = foosball::find_double_rating($dbh, $username2_2);
+
+# 10-x table
+open ASSESS, "/srv/foosball.sesse.net/foosrank $rating1_1 $rd1_1 $rating1_2 $rd1_2 $rating2_1 $rd2_1 $rating2_2 $rd2_2 10 |"
+       or die "foosrank: $!";
+
+my @results10 = ();
+while (<ASSESS>) {
+       my ($score, $prob, $rdiff1, $rdiff2, $rdiff3, $rdiff4) = split /,/, $_;
+       push @results10, {
+               score => $score,
+               prob => (sprintf "%.3f", $prob),
+               rdiff1 => (sprintf "%+d", int($rdiff1+0.5)),
+               rdiff2 => (sprintf "%+d", int($rdiff2+0.5)),
+               rdiff3 => (sprintf "%+d", int($rdiff3+0.5)),
+               rdiff4 => (sprintf "%+d", int($rdiff4+0.5)),
+       };
+}
+
+# 7-x table
+open ASSESS, "/srv/foosball.sesse.net/foosrank $rating1_1 $rd1_1 $rating1_2 $rd1_2 $rating2_1 $rd2_1 $rating2_2 $rd2_2 7 |"
+       or die "foosrank: $!";
+
+my @results7 = ();
+while (<ASSESS>) {
+       my ($score, $prob, $rdiff1, $rdiff2, $rdiff3, $rdiff4) = split /,/, $_;
+       push @results7, {
+               score => $score,
+               prob => (sprintf "%.3f", $prob),
+               rdiff1 => (sprintf "%+d", int($rdiff1+0.5)),
+               rdiff2 => (sprintf "%+d", int($rdiff2+0.5)),
+               rdiff3 => (sprintf "%+d", int($rdiff3+0.3)),
+               rdiff4 => (sprintf "%+d", int($rdiff4+0.4)),
+       };
+}
+
+print CGI->header(-type=>'application/xhtml+xml');
+
+my $doc = XML::Template::process_file('assess-double.xml', {
+       'username1' => $username1_1,
+       'username2' => $username1_2,
+       'username3' => $username2_1,
+       'username4' => $username2_2,
+       'rating1' => int($rating1_1+0.5),
+       'rating2' => int($rating1_2+0.5),
+       'rating3' => int($rating2_1+0.5),
+       'rating4' => int($rating2_2+0.5),
+       '#results10' => \@results10,
+       '#results7' => \@results7,
+});
+print $doc->toString;
diff --git a/www/assess-double.xml b/www/assess-double.xml
new file mode 100644 (file)
index 0000000..9f44738
--- /dev/null
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE
+  html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+  "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" xmlns:t="http://template.sesse.net/">
+  <head>
+    <title>Foosball!</title>
+    <link rev="made" href="mailto:sgunderson@bigfoot.com" />
+    <meta name="MSSmartTagsPreventParsing" content="TRUE" />
+  </head>
+  <body>
+    <h1>Assessment of singles match between <t:username1 />/<t:username2 />
+      (<t:rating1 />/<t:rating2 />) and
+      <t:username3 />/<t:username4 /> (<t:rating3 />/<t:rating4 />)</h1>
+    
+    <table>
+      <thead>
+        <tr>
+          <th>Score</th>
+         <th>Probability</th>
+         <th><t:username1 /></th>
+         <th><t:username2 /></th>
+         <th><t:username3 /></th>
+         <th><t:username4 /></th>
+       </tr>
+      </thead>
+      <tbody t:id="results10">
+        <tr>
+         <td><t:score /></td>
+         <td><t:prob /></td>
+         <td><t:rdiff1 /></td>
+         <td><t:rdiff2 /></td>
+         <td><t:rdiff3 /></td>
+         <td><t:rdiff4 /></td>
+       </tr>
+      </tbody>
+    </table>
+    
+    <table>
+      <thead>
+        <tr>
+          <th>Score</th>
+         <th>Probability</th>
+         <th><t:username1 /></th>
+         <th><t:username2 /></th>
+         <th><t:username3 /></th>
+         <th><t:username4 /></th>
+       </tr>
+      </thead>
+      <tbody t:id="results7">
+        <tr>
+         <td><t:score /></td>
+         <td><t:prob /></td>
+         <td><t:rdiff1 /></td>
+         <td><t:rdiff2 /></td>
+         <td><t:rdiff3 /></td>
+         <td><t:rdiff4 /></td>
+       </tr>
+      </tbody>
+    </table>
+
+    <p>Don't want to click the back button? <a href="/">Here's a link</a>, you
+      lazy sod.</p>
+  </body>
+</html>        
+
index 315a7ac0f7c0cf1d46aed79441adf8e5cd052081..ec452699b717b5cfabdfb35e764fa80187cb044c 100644 (file)
       </table>
     </form>
     
+    <h2>Assess a doubles match</h2>
+
+    <form method="post" action="assess-double.pl">
+      <table>
+        <tr>
+         <th>Team 1 (usernames)</th>
+         <td>
+           <input name="team1_username1" value="" size="10" /> and 
+           <input name="team1_username2" value="" size="10" />
+         </td>
+       </tr>
+        <tr>
+         <th>Team 2 (usernames)</th>
+         <td>
+           <input name="team2_username1" value="" size="10" /> and 
+           <input name="team2_username2" value="" size="10" />
+         </td>
+       </tr>
+       <tr>
+         <td colspan="2"><input type="submit" /></td>
+       </tr>
+      </table>
+    </form>
 
     <h2>About the ratings</h2>