X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Findex.pl;h=916af5c55349cb1b5baa583d1aa584c158c64e27;hb=0ae9e34c70e35503e41d28af052c4957ca7b4f35;hp=8274574a23df52464c1c26a6a783d6d74d1be778;hpb=b055272098b04525aaea3631b4b20a0777f2b0ee;p=wloh diff --git a/www/index.pl b/www/index.pl index 8274574..916af5c 100755 --- a/www/index.pl +++ b/www/index.pl @@ -39,19 +39,13 @@ sub color { return int(255.0 * ($x ** (1.80))); } -sub get_max_season { - my $dbh = shift; - my $ref = $dbh->selectrow_hashref('SELECT MAX(sesong) AS max_sesong FROM fotballserier'); - return $ref->{'max_sesong'}; -} - sub get_divisions { - my ($dbh, $season) = @_; + my ($dbh, $locale, $season) = @_; my @divisions = (); - my $q = $dbh->prepare('SELECT DISTINCT(divisjon) FROM fotballserier WHERE sesong=? ORDER BY divisjon'); - $q->execute($season); + my $q = $dbh->prepare('SELECT DISTINCT(divisjon) FROM fotballserier se JOIN fotballspraak sp ON se.spraak=sp.id WHERE kultur=? AND sesong=? ORDER BY divisjon'); + $q->execute($locale, $season); while (my $ref = $q->fetchrow_hashref) { push @divisions, $ref->{'divisjon'}; @@ -61,12 +55,12 @@ sub get_divisions { } sub get_subdivisions { - my ($dbh, $season, $division) = @_; + my ($dbh, $locale, $season, $division) = @_; my @subdivisions = (); - my $q = $dbh->prepare('SELECT DISTINCT(avdeling) FROM fotballserier WHERE sesong=? AND divisjon=? ORDER BY avdeling'); - $q->execute($season, $division); + my $q = $dbh->prepare('SELECT DISTINCT(avdeling) FROM fotballserier se JOIN fotballspraak sp ON se.spraak=sp.id WHERE kultur=? AND sesong=? AND divisjon=? ORDER BY avdeling'); + $q->execute($locale, $season, $division); while (my $ref = $q->fetchrow_hashref) { push @subdivisions, $ref->{'avdeling'}; @@ -76,10 +70,10 @@ sub get_subdivisions { } sub print_division_selector { - my ($dbh, $divisions, $subdivisions, $division, $subdivision) = @_; + my ($dbh, $locale, $divisions, $subdivisions, $division, $subdivision) = @_; print <<"EOF"; -
+ EOF my $max_division = $divisions->[(scalar @$divisions) - 1]; @@ -120,10 +114,10 @@ EOF } sub get_players_and_ratings { - my ($dbh, $season, $division, $subdivision) = @_; + my ($dbh, $locale, $season, $division, $subdivision) = @_; - my $q = $dbh->prepare('SELECT fotballdeltagere.id,fotballdeltagere.navn,rating,rating_stddev FROM fotballdeltagere JOIN fotballserier ON fotballdeltagere.serie=fotballserier.nr LEFT JOIN ratings ON fotballdeltagere.id=ratings.id WHERE sesong=? AND divisjon=? AND avdeling=?'); - $q->execute($season, $division, $subdivision); + my $q = $dbh->prepare('SELECT fotballdeltagere.id,fotballdeltagere.navn,rating,rating_stddev FROM fotballdeltagere JOIN fotballserier ON fotballdeltagere.serie=fotballserier.nr NATURAL JOIN spiller_kultur LEFT JOIN ratings ON fotballdeltagere.id=ratings.id WHERE kultur=? AND sesong=? AND divisjon=? AND avdeling=?'); + $q->execute($locale, $season, $division, $subdivision); while (my $ref = $q->fetchrow_hashref) { my $id = $ref->{'id'}; @@ -135,7 +129,7 @@ sub get_players_and_ratings { } sub get_matches { - my ($dbh, $season, $division, $subdivision) = @_; + my ($dbh, $locale, $season, $division, $subdivision) = @_; my @matches = (); my $q = $dbh->prepare(' @@ -143,13 +137,14 @@ sub get_matches { d1.id AS p1, d2.id AS p2, maalfor AS score1, maalmot AS score2 FROM fotballresultater r JOIN fotballserier s ON r.serie=s.nr + JOIN fotballspraak sp ON s.spraak=sp.id JOIN fotballdeltagere d1 ON r.lagrecno=d1.nr AND r.serie=d1.serie JOIN fotballdeltagere d2 ON r.motstander=d2.nr AND r.serie=d2.serie WHERE - sesong=? AND divisjon=? AND avdeling=? + kultur=? AND sesong=? AND divisjon=? AND avdeling=? AND lagrecno > motstander '); - $q->execute($season, $division, $subdivision); + $q->execute($locale, $season, $division, $subdivision); while (my $ref = $q->fetchrow_hashref) { push @matches, [ $ref->{'p1'}, $ref->{'p2'}, $ref->{'score1'}, $ref->{'score2'} ]; @@ -177,6 +172,10 @@ sub get_covariance_matrix { sub write_parms_to_file { my ($aux_parms, $match_stddev, $used_ratings, $used_cov) = @_; + POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); + + my @sorted_players = sort { $players{$a} cmp $players{$b} } keys %players; + POSIX::setlocale(&POSIX::LC_ALL, 'C'); my $tmpnam = POSIX::tmpnam(); @@ -186,7 +185,7 @@ sub write_parms_to_file { printf MCCALC "%f\n", $match_stddev; printf MCCALC "%d\n", scalar keys %players; - for my $id (keys %players) { + for my $id (@sorted_players) { my $rating = $used_ratings->{$id} // 500.0; printf MCCALC "%s %f\n", $id, $rating; } @@ -213,12 +212,26 @@ sub write_parms_to_file { return $tmpnam; } +my $num_tables = 0; + sub make_table { - my ($aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov) = @_; + my ($locale, $aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov, $division, $subdivision) = @_; + ++$num_tables; print <<"EOF"; - - + +
EOF @@ -236,7 +249,7 @@ EOF $prob{$player} = [ @x[1..$#x] ]; } close MCCALC; - #unlink $tmpnam; + unlink $tmpnam; my $num_games = scalar keys %prob; for my $i (1..$num_games) { @@ -245,7 +258,9 @@ EOF print " \n" unless ($lowest_division); print " \n"; + my $pnum = 0; for my $player (sort { $a cmp $b } keys %prob) { + ++$pnum; print " \n"; print " \n"; @@ -262,7 +277,12 @@ EOF ($r, $b) = ($b, $r); } - printf " \n", $pn * 100.0; + my $num_total_games = ($num_games * ($num_games - 1)) / 2; + if (scalar @matches == $num_total_games || $prob{$player}->[$i - 1] == $trials) { + printf " \n", $pn * 100.0; + } else { + printf " \n", $pn * 100.0; + } } unless ($lowest_division) { @@ -278,6 +298,8 @@ EOF print << "EOF";
NEDRYKK
$player%.1f%%%.1f%%%.1f%%
+ +

EOF } @@ -286,9 +308,9 @@ sub find_avg_rating { my $sum_rating = 0.0; for my $r (values %$ratings) { - $sum_rating += $r; + $sum_rating += ($r // 500.0); } - return $sum_rating / scalar keys %ratings; + return $sum_rating / scalar keys %$ratings; } sub get_auxillary_parameters { @@ -313,7 +335,7 @@ sub print_header { $title - + EOF @@ -334,14 +356,17 @@ my $subdivision = $cgi->param('avdeling') // -1; my $match_player = $cgi->param('spiller'); my $match_position = $cgi->param('posisjon'); -my $season = get_max_season($dbh); -my @divisions = get_divisions($dbh, $season); -$division = 1 if (!grep { $_ == $division } @divisions); -my @subdivisions = get_subdivisions($dbh, $season, $division); -$subdivision = 1 if (!grep { $_ == $subdivision } @subdivisions); +my $locale = wloh_common::get_locale($cgi); +my $season = wloh_common::get_max_season($dbh, $locale); +die "Nonexistent locale!" if (!defined($season)); + +my @divisions = get_divisions($dbh, $locale, $season); +$division = $divisions[0] if (!grep { $_ == $division } @divisions); +my @subdivisions = get_subdivisions($dbh, $locale, $season, $division); +$subdivision = $subdivisions[0] if (!grep { $_ == $subdivision } @subdivisions); -get_players_and_ratings($dbh, $season, $division, $subdivision); -@matches = get_matches($dbh, $season, $division, $subdivision); +get_players_and_ratings($dbh, $locale, $season, $division, $subdivision); +@matches = get_matches($dbh, $locale, $season, $division, $subdivision); my $cov = get_covariance_matrix($dbh, keys %players); print_header($cgi, 'WLoH-plasseringsannsynlighetsberegning'); @@ -361,12 +386,17 @@ if (defined($match_player) && defined($match_position)) { push @scenario, [ $1, $2, $3 ]; } close MCCALC; - #unlink $tmpnam; + unlink $tmpnam; + + my @sorted_players = sort { $players{$a} cmp $players{$b} } keys %players; + my $player_name = $players{$sorted_players[$match_player]}; if (scalar @scenario == 0) { - # FIXME: distinguish between "all played" and "none found" - print "

Fant ingen måte dette kunne skje på.

\n"; + printf "

Fant ingen måte %s kan ende på %d. plass på.

\n", + $player_name, ($match_position + 1); } else { + printf "

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

\n", + $player_name, ($match_position + 1); print "