]> git.sesse.net Git - wloh/commitdiff
Unbreak/templatify scenario analysis.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 10 Jun 2012 01:17:55 +0000 (03:17 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 10 Jun 2012 01:19:51 +0000 (03:19 +0200)
templates/scenario-not-found.xml [new file with mode: 0644]
templates/scenario.xml [new file with mode: 0644]
www/index.pl

diff --git a/templates/scenario-not-found.xml b/templates/scenario-not-found.xml
new file mode 100644 (file)
index 0000000..b7be7bb
--- /dev/null
@@ -0,0 +1,13 @@
+<?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" xmlns:t="http://template.sesse.net/">
+  <head>
+    <title>WLoH-plasseringsannsynlighetsberegning</title>
+    <link rel="stylesheet" href="style" type="text/css" />
+  </head>
+  <body>
+    <p>Fant ingen måte <strong t:id="nick" /> kan ende på <strong t:id="rank" /> plass på.</p>
+  </body>
+</html>
diff --git a/templates/scenario.xml b/templates/scenario.xml
new file mode 100644 (file)
index 0000000..7ea71e2
--- /dev/null
@@ -0,0 +1,16 @@
+<?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" xmlns:t="http://template.sesse.net/">
+  <head>
+    <title>WLoH-plasseringsannsynlighetsberegning</title>
+    <link rel="stylesheet" href="style" type="text/css" />
+  </head>
+  <body>
+    <p>Scenario der <strong t:id="nick" /> ender på <strong t:id="rank" /> plass:</p>
+    <ul t:id="results">
+      <li><t:player-1 /> – <t:player-2 />: <t:result /></li>
+    </ul>
+  </body>
+</html>
index 0bf35594f8e385c7878badb0b6678c4b012e1124..a01f514c25e50dd95cc6a481b317245bb653d619 100755 (executable)
@@ -243,7 +243,7 @@ sub make_table {
                                push @player_ranks, {
                                        'td/style' => "background-color: rgb($r, $g, $b)",
                                        'a' => sprintf("%.1f%%", $pn * 100.0),
-                                       'a/href' => "javascript:showScenario('$table_id', '/$locale/?divisjon=$division;avdeling=$subdivision;spiller=$pnum;posisjon=$i"
+                                       'a/href' => "javascript:showScenario('$table_id', '/$locale/?divisjon=$division;avdeling=$subdivision;spiller=$pnum;posisjon=$i')"
                                };
                        }
                }
@@ -356,7 +356,6 @@ get_players_and_ratings($dbh, $locale, $season, $division, $subdivision);
 my $cov = get_covariance_matrix($dbh, keys %players);
 
 if (defined($match_player) && defined($match_position)) {
-       print_header($cgi, 'WLoH-plasseringsannsynlighetsberegning');
        my $tmpnam = write_parms_to_file($aux_parms, $match_stddev, \%ratings, $cov);
 
        --$match_player;
@@ -368,7 +367,11 @@ if (defined($match_player) && defined($match_position)) {
        while (<MCCALC>) {
                /(\d+) (\d+) (-?\d+)/ or next;
                chomp;
-               push @scenario, [ $1, $2, $3 ];
+               push @scenario, {
+                       'player-1' => $players{$1},
+                       'player-2' => $players{$2},
+                       'result' => sprintf("%+d", $3),
+               };
        }
        close MCCALC;
        unlink $tmpnam;
@@ -377,18 +380,19 @@ if (defined($match_player) && defined($match_position)) {
        my $player_name = $players{$sorted_players[$match_player]};
 
        if (scalar @scenario == 0) {
-               printf "    <p>Fant ingen m&aring;te <strong>%s</strong> kan ende p&aring; <strong>%d.</strong> plass p&aring;.</p>\n",
-                       $player_name, ($match_position + 1);
+               print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+               wloh_common::process_template('scenario-not-found.xml', {
+                       '#nick' => $player_name,
+                       '#rank' => sprintf("%d.", $match_position + 1)
+               });
        } else {
-               printf "    <p>Scenario der <strong>%s</strong> ender p&aring; <strong>%d.</strong> plass:</p>\n",
-                       $player_name, ($match_position + 1);
-               print "    <ul>\n";
-               for my $m (@scenario) {
-                       printf "    <li>%s &ndash; %s: %+d</li>\n", $players{$m->[0]}, $players{$m->[1]}, $m->[2];
-               }
-               print "    </ul>\n";
+               print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m');
+               wloh_common::process_template('scenario.xml', {
+                       '#nick' => $player_name,
+                       '#rank' => sprintf("%d.", $match_position + 1),
+                       '#results' => \@scenario
+               });
        }
-       print_footer();
 } else {
        POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8');