From: Steinar H. Gunderson Date: Wed, 17 Oct 2007 19:14:02 +0000 (+0200) Subject: Support double assessment, now that it's fast. X-Git-Url: https://git.sesse.net/?p=foosball;a=commitdiff_plain;h=1371406e6263f6aaf6856cfc886e01a19f80f000 Support double assessment, now that it's fast. --- diff --git a/foosrank.cpp b/foosrank.cpp index cae1dc3..cc66076 100644 --- a/foosrank.cpp +++ b/foosrank.cpp @@ -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 index 0000000..bc60069 --- /dev/null +++ b/www/assess-double.pl @@ -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 () { + 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 () { + 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 index 0000000..9f44738 --- /dev/null +++ b/www/assess-double.xml @@ -0,0 +1,66 @@ + + + + + Foosball! + + + + +

Assessment of singles match between / + (/) and + / (/)

+ + + + + + + + + + + + + + + + + + + + + + +
ScoreProbability
+ + + + + + + + + + + + + + + + + + + + + + +
ScoreProbability
+ +

Don't want to click the back button? Here's a link, you + lazy sod.

+ + + diff --git a/www/index.xml b/www/index.xml index 315a7ac..ec45269 100644 --- a/www/index.xml +++ b/www/index.xml @@ -156,6 +156,29 @@ +

Assess a doubles match

+ +
+ + + + + + + + + + + + +
Team 1 (usernames) + and + +
Team 2 (usernames) + and + +
+

About the ratings