my %ratings = ();
my %ratings_stddev = ();
my @matches = ();
-my %parms = ();
-my $match_stddev;
sub sanitize {
return HTML::Entities::encode_entities(shift);
}
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');
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);
}
}
sub make_table {
- my ($lowest_division, $used_ratings, $used_cov) = @_;
+ my ($aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov) = @_;
print <<"EOF";
<th></th>
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 |"
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;
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 $aux_parms = get_auxillary_parameters($dbh);
+my $match_stddev = $aux_parms->{-2} * sqrt(2.0);
my $season;
my $division = $cgi->param('divisjon') // -1;
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";
<p>Under er en variant som tar relativ spillestyrke med i beregningen;
se <a href="/rating">ratingsiden</a>.</p>
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 " <p>Gjennomsnittlig rating i denne avdelingen er <strong>%.1f</strong>.</p>\n", $avg_rating;