X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Findex.pl;h=eb6d1761f613376d16bc4dd9dc98d07043337621;hb=HEAD;hp=0bf35594f8e385c7878badb0b6678c4b012e1124;hpb=79ca58ab629b09e8fe59415578d2ee1ea5cb2079;p=wloh diff --git a/www/index.pl b/www/index.pl index 0bf3559..eb6d176 100755 --- a/www/index.pl +++ b/www/index.pl @@ -31,10 +31,6 @@ my %ratings = (); my %ratings_stddev = (); my @matches = (); -sub sanitize { - return HTML::Entities::encode_entities(shift); -} - sub color { my $x = shift; return int(255.0 * ($x ** (1.80))); @@ -93,7 +89,7 @@ sub get_players_and_ratings { while (my $ref = $q->fetchrow_hashref) { my $id = $ref->{'id'}; - $players{$id} = sanitize(Encode::decode_utf8($ref->{'navn'})); + $players{$id} = Encode::decode_utf8($ref->{'navn'}); $ratings{$id} = $ref->{'rating'}; $ratings_stddev{$id} = $ref->{'rating_stddev'}; } @@ -142,9 +138,9 @@ sub get_covariance_matrix { } sub write_parms_to_file { - my ($aux_parms, $match_stddev, $used_ratings, $used_cov) = @_; + my ($locale, $aux_parms, $match_stddev, $used_ratings, $used_cov) = @_; - POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); + wloh_common::set_locale($locale); my @sorted_players = sort { $players{$a} cmp $players{$b} } keys %players; @@ -179,7 +175,7 @@ sub write_parms_to_file { } close MCCALC; - POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); + wloh_common::set_locale($locale); return $tmpnam; } @@ -187,7 +183,7 @@ sub write_parms_to_file { sub make_table { my ($locale, $aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov, $division, $subdivision, $table_id) = @_; - my $tmpnam = write_parms_to_file($aux_parms, $match_stddev, $used_ratings, $used_cov); + my $tmpnam = write_parms_to_file($locale, $aux_parms, $match_stddev, $used_ratings, $used_cov); my %prob = (); open MCCALC, "$config::base_dir/mcwordfeud $trials < $tmpnam |" @@ -204,12 +200,11 @@ sub make_table { my $num_games = scalar keys %prob; - # Make list of ranks. + # Make list of ranks. (Relegation is handled specially.) my @ranks = (); for my $i (1..$num_games) { - push @ranks, { 'th' => "$i." }; + push @ranks, { 'th' => wloh_common::get_ordinal($i, $locale) }; } - push @ranks, { 'th' => 'NEDRYKK' } unless ($lowest_division); my @players = (); @@ -243,7 +238,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')" }; } } @@ -266,10 +261,12 @@ sub make_table { }; } - return { + my $parms = { 'ranks' => \@ranks, 'tbody' => \@players, }; + $parms->{'relegation'} = '' if ($lowest_division); + return $parms; } sub make_cov_table { @@ -356,8 +353,7 @@ 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); + my $tmpnam = write_parms_to_file($locale, $aux_parms, $match_stddev, \%ratings, $cov); --$match_player; --$match_position; @@ -368,7 +364,11 @@ if (defined($match_player) && defined($match_position)) { while () { /(\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,20 +377,21 @@ if (defined($match_player) && defined($match_position)) { my $player_name = $players{$sorted_players[$match_player]}; if (scalar @scenario == 0) { - printf "

Fant ingen måte %s kan ende på %d. plass 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', $locale, { + '#nick' => $player_name, + '#rank' => wloh_common::get_ordinal($match_position + 1, $locale) + }); } else { - printf "

Scenario der %s ender på %d. plass:

\n", - $player_name, ($match_position + 1); - print " \n"; + print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m'); + wloh_common::process_template('scenario', $locale, { + '#nick' => $player_name, + '#rank' => wloh_common::get_ordinal($match_position + 1, $locale), + '#results' => \@scenario + }); } - print_footer(); } else { - POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); + wloh_common::set_locale($locale); my $max_division = $divisions[$#divisions]; my $lowest_division = ($division == $max_division); @@ -401,7 +402,7 @@ if (defined($match_player) && defined($match_position)) { my $avg_rating = find_avg_rating(\%ratings); print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m'); - wloh_common::process_template('index.xml', { + wloh_common::process_template('index', $locale, { '#navbar' => wloh_common::get_navbar($cgi, $dbh, $locale), '#division-selector/action' => "/$locale/", '#division' => get_division_selector(\@divisions, $division),