]> git.sesse.net Git - foosball/commitdiff
Added an assessment function.
authorSteinar H. Gunderson <sesse@debian.org>
Fri, 5 Oct 2007 16:45:11 +0000 (18:45 +0200)
committerSteinar H. Gunderson <sesse@debian.org>
Fri, 5 Oct 2007 16:45:11 +0000 (18:45 +0200)
www/assess-single.pl [new file with mode: 0644]
www/assess.xml [new file with mode: 0644]
www/index.xml

diff --git a/www/assess-single.pl b/www/assess-single.pl
new file mode 100644 (file)
index 0000000..0d24a58
--- /dev/null
@@ -0,0 +1,48 @@
+#! /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 = $cgi->param('username1');
+$username1 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 1";
+$username1 = $1;
+
+my $username2 = $cgi->param('username2');
+$username2 =~ /^([a-z][a-z0-9]*)$/ or die "Invalid user name 2";
+$username2 = $1;
+
+my $dbh = foosball::db_connect();
+
+# fetch the single ratings
+my ($rating1, $rd1) = foosball::find_single_rating($dbh, $username1);
+my ($rating2, $rd2) = foosball::find_single_rating($dbh, $username2);
+
+open ASSESS, "/srv/foosball.sesse.net/foorank $rating1 $rd1 $rating2 $rd2 |"
+       or die "foorank: $!";
+
+my @results = ();
+while (<ASSESS>) {
+       my ($score, $prob, $rdiff1, $rdiff2) = split /,/, $_;
+       push @results, {
+               score => $score,
+               prob => (sprintf "%.3f", $prob),
+               rdiff1 => (sprintf "%+d", int($rdiff1+0.5)),
+               rdiff2 => (sprintf "%+d", int($rdiff2+0.5)),
+       };
+}
+
+print CGI->header(-type=>'application/xhtml+xml');
+
+my $doc = XML::Template::process_file('assess.xml', {
+       'username1' => $username1,
+       'username2' => $username2,
+       '#results' => \@results,
+});
+print $doc->toString;
diff --git a/www/assess.xml b/www/assess.xml
new file mode 100644 (file)
index 0000000..44f7ddf
--- /dev/null
@@ -0,0 +1,37 @@
+<?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 /> and <t:username2 /></h1>
+    
+    <table>
+      <thead>
+        <tr>
+          <th>Score</th>
+         <th>Probability</th>
+         <th><t:username1 /></th>
+         <th><t:username2 /></th>
+       </tr>
+      </thead>
+      <tbody t:id="results">
+        <tr>
+         <td><t:score /></td>
+         <td><t:prob /></td>
+         <td><t:rdiff1 /></td>
+         <td><t:rdiff2 /></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 8c63fb2e6dc88e0e56907f330fc61dd0fcabd6b8..dbd5359983acd332a1df0b1b3bd7a1a3fb90e867 100644 (file)
        </tr>
       </tbody>
     </table>
+    
+    <h2>Assess a singles match</h2>
+
+    <form method="post" action="assess-single.pl">
+      <table>
+        <tr>
+         <th>User name 1</th>
+         <td><input name="username1" value="" size="10" /></td>
+       </tr>
+        <tr>
+         <th>User name 2</th>
+         <td><input name="username2" value="" size="10" /></td>
+       </tr>
+       <tr>
+         <td colspan="2"><input type="submit" /></td>
+       </tr>
+      </table>
+    </form>
+    
 
     <h2>About the ratings</h2>