]> git.sesse.net Git - wloh/blobdiff - www/rating.pl
Output when we last synced.
[wloh] / www / rating.pl
index d4a6f904253fbf6250ea6203af5ea40667cc07f7..89c75b96e2ee89a6e64f862fd61bc8757ce5c096 100755 (executable)
@@ -11,6 +11,7 @@ use HTML::Entities;
 use utf8;
 use locale;
 require '../config.pm';
+require '../common.pm';
 
 my $dbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password)
        or die "connect: " . $DBI::errstr;
@@ -32,44 +33,27 @@ print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
 POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8');
 
 printf <<"EOF", $params{-3}, $match_stddev;
-<html>
+<?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="no">
   <head>
     <title>WLoH-rating</title>
-    <style type="text/css">
-body {
-       color: black;
-       background: white;
-       font-family: sans-serif;
-}
-table {
-       border-collapse: collapse;
-       border: 1px solid black;
-}
-td, th {
-       border: 1px solid black;
-       padding: 5px;
-}
-td.num {
-       text-align: right;
-}
-.even {
-       background-color: #ddd;
-}
-    </style>
+    <link rel="stylesheet" href="/style" type="text/css" />
   </head>
   <body>
     <h1>WLoH-rating</h1>
 
-    <p>Ratingen er basert på spilledata fra WLoH (takk til Lobotommy
+    <p><em>Dette er et hobbyprosjekt fra tredjepart, og ikke en offisiell del av
+      <a href="http://wordfeud.aasmul.net/">Wordfeud Leage of Honour</a>.</em></p>
+
+    <p>Ratingen er dog basert på spilledata fra WLoH (takk til Lobotommy
       for tilgang!), og oppdateres
       hver hele time. Den er fullstendig uoffisiell, og har ingen innflytelse
       på WLoH, men brukes for å estimere vinnersannsynligheter i
       <a href="/">sannsynlighetsberegningen</a>.</p>
 
-    <p>Vær obs på at det
-      er betydelig usikkerhetsmargin, spesielt for spillere som ikke
-      har spilt spesielt mange kamper.</p>
-
     <p>Modellen kan endre seg når som helst når jeg føler for det :-)
       Ikke ta ratingen alt for alvorlig, selv om den er basert på
       relativt fornuftige matematiske modeller. Husk at all statistikk
@@ -77,7 +61,8 @@ td.num {
 
     <h2>Modellparametre</h2>
 
-    <p>For de som vet litt om slikt. Mer utførlig forklaring for begynnere kommer seinere.</p>
+    <p>For de som vet litt om slikt. Det finnes også en lengre, mer detaljert
+      <a href="/ratings-explained">forklaring</a> beregnet på ikke-matematikere.</p>
 
     <ul>
       <li>MLE-basert modell med én skalar (styrke) per spiller og to globale skalarer (begge standardavvik, se under), løst med syklisk MM (minorization-maximization). Antall iterasjoner før konvergens: $params{-1}.</li>
@@ -89,13 +74,43 @@ td.num {
         150-0, 0-150 eller 150-150 ignoreres.</li>
     </ul>
 
+    <h2>Divisjonsoversikt</h2>
+
+    <table>
+      <tr>
+        <th>Div.</th>
+        <th>Snitt</th>
+        <th>Std.avvik</th>
+      </tr>
+EOF
+
+$q = $dbh->prepare('SELECT divisjon,AVG(rating) AS avg_rating,STDDEV(rating) AS stddev_rating FROM ratings NATURAL JOIN siste_divisjon GROUP BY divisjon ORDER BY divisjon');
+$q->execute;
+
+my $i = 0;
+while (my $ref = $q->fetchrow_hashref) {
+       if (++$i % 2 == 0) {
+               print "      <tr class=\"odd\">\n";
+       } else {
+               print "      <tr class=\"even\">\n";
+       }
+       printf "        <th>%d.</th>\n", $ref->{'divisjon'};
+       printf "        <td class=\"num\">%.1f</td>\n", $ref->{'avg_rating'};
+       printf "        <td class=\"num\">%.1f</td>\n", $ref->{'stddev_rating'};
+       print "      </tr>\n";
+}
+
+print <<"EOF";
+    </table>
+
   <h2>Rankingliste</h2>
 
   <table>
     <tr>
       <th></th>
       <th>Nick</th>
-      <th>Ranking</th>
+      <th>Rating</th>
+      <th>Std.avvik</th>
       <th>Sist sett</th>
     </tr>
 EOF
@@ -108,7 +123,7 @@ FROM ratings
 ORDER BY rating DESC');
 $q->execute;
 
-my $i = 0;
+$i = 0;
 while (my $ref = $q->fetchrow_hashref) {
        if (++$i % 2 == 0) {
                print "    <tr class=\"odd\">\n";
@@ -118,12 +133,15 @@ while (my $ref = $q->fetchrow_hashref) {
        printf "      <th>%d.</th>\n", $i;
        printf "      <td><a href=\"http://wordfeud.aasmul.net/bruker-%d\">%s</a></td>\n", $ref->{'id'}, HTML::Entities::encode_entities(Encode::decode_utf8($ref->{'navn'}));
        printf "      <td class=\"num\">%.1f</td>\n", $ref->{'rating'};
+       printf "      <td class=\"num\">%.1f</td>\n", $ref->{'rating_stddev'};
        printf "      <td><a href=\"http://wordfeud.aasmul.net/serie-%d\">%s</a></td>\n", $ref->{'serie_id'}, $ref->{'serie_navn'};
        print "    </tr>\n";
 }
+print "    </table>\n";
+
+wloh_common::output_last_sync($dbh);
 
 print <<"EOF";
-    </table>
   </body>
 </html>
 EOF