X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Findex.pl;h=2cecec4672ad48d7a1893ef4a951989f367c556b;hb=dec0ff92103e212921be03744323ed3a3074e996;hp=34cc7077471389d7ca4bde8343ae0ee40b773eb9;hpb=08f61ffb9de79072d37955e28aca1f9d6a44587e;p=wloh diff --git a/www/index.pl b/www/index.pl index 34cc707..2cecec4 100755 --- a/www/index.pl +++ b/www/index.pl @@ -29,8 +29,6 @@ my %players = (); my %ratings = (); my %ratings_stddev = (); my @matches = (); -my %parms = (); -my $match_stddev; sub sanitize { return HTML::Entities::encode_entities(shift); @@ -177,7 +175,7 @@ sub get_covariance_matrix { } sub write_parms_to_file { - my ($used_ratings, $used_cov) = @_; + my ($aux_parms, $match_stddev, $used_ratings, $used_cov) = @_; POSIX::setlocale(&POSIX::LC_ALL, 'C'); @@ -197,7 +195,7 @@ sub write_parms_to_file { for my $id1 (keys %players) { for my $id2 (keys %players) { if ($id1 == $id2) { - printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // $parms{-3}); + printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // $aux_parms->{-3}); } else { printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // 0.0); } @@ -216,7 +214,7 @@ sub write_parms_to_file { } sub make_table { - my ($lowest_division, $used_ratings, $used_cov) = @_; + my ($aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov) = @_; print <<"EOF"; @@ -225,7 +223,7 @@ sub make_table { EOF - my $tmpnam = write_parms_to_file($used_ratings, $used_cov); + my $tmpnam = write_parms_to_file($aux_parms, $match_stddev, $used_ratings, $used_cov); my %prob = (); open MCCALC, "$config::base_dir/mcwordfeud $trials < $tmpnam |" @@ -234,7 +232,7 @@ EOF chomp; my @x = split /\s+/; my $id = $x[0]; - my $player = sprintf "%s (%.0f ± %.0f)", $players{$id}, ($ratings{$id} // 500.0), ($ratings_stddev{$id} // $parms{-3}); + my $player = sprintf "%s (%.0f ± %.0f)", $players{$id}, ($ratings{$id} // 500.0), ($ratings_stddev{$id} // $aux_parms->{-3}); $prob{$player} = [ @x[1..$#x] ]; } close MCCALC; @@ -293,34 +291,65 @@ sub find_avg_rating { return $sum_rating / scalar keys %ratings; } -# Get auxillary parameters -my $q = $dbh->prepare('SELECT * FROM ratings WHERE id < 0'); -$q->execute; +sub get_auxillary_parameters { + my $q = $dbh->prepare('SELECT * FROM ratings WHERE id < 0'); + $q->execute; -while (my $ref = $q->fetchrow_hashref) { - $parms{$ref->{'id'}} = $ref->{'rating'}; + my $aux_parms = {}; + while (my $ref = $q->fetchrow_hashref) { + $aux_parms->{$ref->{'id'}} = $ref->{'rating'}; + } + return $aux_parms; } -$match_stddev = $parms{-2} * sqrt(2.0); - -my $season; -my $division = $cgi->param('divisjon') // -1; -my $subdivision = $cgi->param('avdeling') // -1; -my $last_division = 0; - -POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); -print $cgi->header(-type=>'text/html; charset=utf-8', -expires=>'now'); -printf <<"EOF", $match_stddev; +sub print_header { + my ($cgi, $title) = @_; + print $cgi->header(-type=>'text/html; charset=utf-8', -expires=>'now'); + print <<"EOF"; - WLoH-plasseringsannsynlighetsberegning + $title +EOF +} + +sub print_footer { + my $dbh = shift; + wloh_common::output_last_sync($dbh); + + print <<"EOF"; + + +EOF +} + +my $aux_parms = get_auxillary_parameters($dbh); +my $match_stddev = $aux_parms->{-2} * sqrt(2.0); + +my $season; +my $division = $cgi->param('divisjon') // -1; +my $subdivision = $cgi->param('avdeling') // -1; + +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); + +get_players_and_ratings($dbh, $season, $division, $subdivision); +my @matches = get_matches($dbh, $season, $division, $subdivision); +my $cov = get_covariance_matrix($dbh, keys %players); + +print_header($cgi, 'WLoH-plasseringsannsynlighetsberegning'); + +POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); +printf <<"EOF", $match_stddev;

WLoH-plasseringsannsynlighetsberegning

Dette er et hobbyprosjekt fra tredjepart, og ikke en offisiell del av @@ -334,37 +363,20 @@ printf <<"EOF", $match_stddev;

Spillerne er sortert etter nick.

EOF -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); - print_division_selector($dbh, \@divisions, \@subdivisions, $division, $subdivision); -get_players_and_ratings($dbh, $season, $division, $subdivision); - -my @matches = get_matches($dbh, $season, $division, $subdivision); - -my $cov = get_covariance_matrix($dbh, keys %players); - my $max_division = $divisions[$#divisions]; my $lowest_division = ($division == $max_division); -make_table($lowest_division, {}, {}); +make_table($aux_parms, $match_stddev, $lowest_division, {}, {}); print <<"EOF";

Under er en variant som tar relativ spillestyrke med i beregningen; se ratingsiden.

EOF -make_table($lowest_division, \%ratings, $cov); +make_table($aux_parms, $match_stddev, $lowest_division, \%ratings, $cov); my $avg_rating = find_avg_rating(\%ratings); printf "

Gjennomsnittlig rating i denne avdelingen er %.1f.

\n", $avg_rating; -wloh_common::output_last_sync($dbh); - -print <<"EOF"; - - -EOF +print_footer($dbh);