X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Findex.pl;h=697470cdd75a6002c92ed6b2919bef3b15258007;hb=8964d30bbe836e9c0989208be582d3c7213eb574;hp=34ae134437183c253420723537499059e1baebd4;hpb=b2d20ed5f0b30fe09a896edd4f7f540a638681a9;p=wloh diff --git a/www/index.pl b/www/index.pl index 34ae134..697470c 100755 --- a/www/index.pl +++ b/www/index.pl @@ -177,6 +177,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 +190,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 +217,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 ($aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov, $division, $subdivision) = @_; + ++$num_tables; print <<"EOF"; - -
EOF @@ -245,7 +263,9 @@ EOF print " | NEDRYKK | \n" unless ($lowest_division); print "||
---|---|---|---|
$player | \n"; @@ -262,7 +282,12 @@ EOF ($r, $b) = ($b, $r); } - printf "%.1f%% | \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 "%.1f%% | \n", $pn * 100.0; + } else { + printf "%.1f%% | \n", $pn * 100.0; + } } unless ($lowest_division) { @@ -278,6 +303,8 @@ EOF print << "EOF";
Dette er et hobbyprosjekt fra tredjepart, og ikke en offisiell del av - Wordfeud Leage of Honour.
+sub print_footer { + print <<"EOF"; + + +EOF +} -Beregningen tar ikke hensyn til ujevn spillestyrke, ting som er sagt i forumet e.l.; - den antar at samtlige uspilte kamper trekkes fra en normalfordeling med standardavvik - %.1f poeng. Sannsynlighetene kan summere til andre tall enn 100%% pga. avrunding. - Tallene vil variere litt fra gang til gang fordi utregningen skjer ved randomisering.
+my $aux_parms = get_auxillary_parameters($dbh); +my $match_stddev = $aux_parms->{-2} * sqrt(2.0); -Spillerne er sortert etter nick.
-EOF +my $division = $cgi->param('divisjon') // -1; +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); @@ -343,31 +367,78 @@ $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); +@matches = get_matches($dbh, $season, $division, $subdivision); +my $cov = get_covariance_matrix($dbh, keys %players); -my @matches = get_matches($dbh, $season, $division, $subdivision); +print_header($cgi, 'WLoH-plasseringsannsynlighetsberegning'); -my $cov = get_covariance_matrix($dbh, keys %players); +if (defined($match_player) && defined($match_position)) { + my $tmpnam = write_parms_to_file($aux_parms, $match_stddev, \%ratings, $cov); + + --$match_player; + --$match_position; + + my @scenario = (); + open MCCALC, "$config::base_dir/mcwordfeud $trials $match_player $match_position < $tmpnam |" + or die "mccalc: $!"; + while (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 "Dette er et hobbyprosjekt fra tredjepart, og ikke en offisiell del av + Wordfeud Leage of Honour.
-print <<"EOF"; -Under er en variant som tar relativ spillestyrke med i beregningen; +
Beregningen tar ikke hensyn til ujevn spillestyrke, ting som er sagt i forumet e.l.; + den antar at samtlige uspilte kamper trekkes fra en normalfordeling med standardavvik + %.1f poeng. Sannsynlighetene kan summere til andre tall enn 100%% pga. avrunding. + Tallene vil variere litt fra gang til gang fordi utregningen skjer ved randomisering. + For scenarioeksempel, klikk i en rute.
+ +Spillerne er sortert etter nick.
+EOF + + print_division_selector($dbh, \@divisions, \@subdivisions, $division, $subdivision); + + my $max_division = $divisions[$#divisions]; + my $lowest_division = ($division == $max_division); + make_table($aux_parms, $match_stddev, $lowest_division, {}, {}, $division, $subdivision); + + print <<"EOF"; +Under er en variant som tar relativ spillestyrke med i beregningen; se ratingsiden.
EOF -make_table($aux_parms, $match_stddev, $lowest_division, \%ratings, $cov); + make_table($aux_parms, $match_stddev, $lowest_division, \%ratings, $cov, $division, $subdivision); -my $avg_rating = find_avg_rating(\%ratings); -printf "Gjennomsnittlig rating i denne avdelingen er %.1f.
\n", $avg_rating; + my $avg_rating = find_avg_rating(\%ratings); + printf "Gjennomsnittlig rating i denne avdelingen er %.1f.
\n", $avg_rating; -wloh_common::output_last_sync($dbh); + wloh_common::output_last_sync($dbh); +} -print <<"EOF"; -