}
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'};
}
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'};
}
sub print_division_selector {
- my ($dbh, $divisions, $subdivisions, $division, $subdivision) = @_;
+ my ($dbh, $locale, $divisions, $subdivisions, $division, $subdivision) = @_;
print <<"EOF";
- <form method="get" action="/">
+ <form method="get" action="/$locale/">
EOF
my $max_division = $divisions->[(scalar @$divisions) - 1];
}
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'};
}
sub get_matches {
- my ($dbh, $season, $division, $subdivision) = @_;
+ my ($dbh, $locale, $season, $division, $subdivision) = @_;
my @matches = ();
my $q = $dbh->prepare('
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'} ];
for my $id1 (keys %players) {
for my $id2 (keys %players) {
if ($id1 == $id2) {
- printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // $aux_parms->{-3});
+ printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // $aux_parms->{'rating_prior_stddev'});
} else {
printf MCCALC "%f ", ($used_cov->{$id1}{$id2} // 0.0);
}
my $num_tables = 0;
sub make_table {
- my ($aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov, $division, $subdivision) = @_;
+ my ($locale, $aux_parms, $match_stddev, $lowest_division, $used_ratings, $used_cov, $division, $subdivision) = @_;
++$num_tables;
print <<"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} // $aux_parms->{-3});
+ my $player = sprintf "%s (%.0f ± %.0f)", $players{$id}, ($ratings{$id} // 500.0), ($ratings_stddev{$id} // $aux_parms->{'rating_prior_stddev'});
$prob{$player} = [ @x[1..$#x] ];
}
close MCCALC;
- #unlink $tmpnam;
+ unlink $tmpnam;
my $num_games = scalar keys %prob;
for my $i (1..$num_games) {
if (scalar @matches == $num_total_games || $prob{$player}->[$i - 1] == $trials) {
printf " <td style=\"background-color: rgb($r, $g, $b)\" class=\"num\">%.1f%%</td>\n", $pn * 100.0;
} else {
- printf " <td style=\"background-color: rgb($r, $g, $b)\" class=\"num\"><a class=\"unmarkedlink\" href=\"javascript:showScenario('scenario$num_tables', '/?divisjon=$division;avdeling=$subdivision;spiller=$pnum;posisjon=$i');\">%.1f%%</a></td>\n", $pn * 100.0;
+ printf " <td style=\"background-color: rgb($r, $g, $b)\" class=\"num\"><a class=\"unmarkedlink\" href=\"javascript:showScenario('scenario$num_tables', '/$locale/?divisjon=$division;avdeling=$subdivision;spiller=$pnum;posisjon=$i');\">%.1f%%</a></td>\n", $pn * 100.0;
}
}
my $sum_rating = 0.0;
for my $r (values %$ratings) {
- $sum_rating += $r;
+ $sum_rating += ($r // 500.0);
}
- return $sum_rating / scalar keys %ratings;
-}
-
-sub get_auxillary_parameters {
- my $q = $dbh->prepare('SELECT * FROM ratings WHERE id < 0');
- $q->execute;
-
- my $aux_parms = {};
- while (my $ref = $q->fetchrow_hashref) {
- $aux_parms->{$ref->{'id'}} = $ref->{'rating'};
- }
- return $aux_parms;
+ return $sum_rating / scalar keys %$ratings;
}
sub print_header {
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="no">
<head>
<title>$title</title>
- <link rel="stylesheet" href="/style" type="text/css" />
+ <link rel="stylesheet" href="style" type="text/css" />
</head>
<body>
EOF
EOF
}
-my $aux_parms = get_auxillary_parameters($dbh);
-my $match_stddev = $aux_parms->{-2} * sqrt(2.0);
+my $locale = wloh_common::get_locale($cgi);
+my $aux_parms = wloh_common::get_auxillary_parameters($dbh, $locale);
+my $match_stddev = $aux_parms->{'score_stddev'} * sqrt(2.0);
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 = wloh_common::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 $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');
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]};
<p>Spillerne er sortert etter nick.</p>
EOF
- print_division_selector($dbh, \@divisions, \@subdivisions, $division, $subdivision);
+ print_division_selector($dbh, $locale, \@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);
+ make_table($locale, $aux_parms, $match_stddev, $lowest_division, {}, {}, $division, $subdivision);
print <<"EOF";
<p style="clear: both; padding-top: 1em;">Under er en variant som tar relativ spillestyrke med i beregningen;
- se <a href="/rating">ratingsiden</a>.</p>
+ se <a href="rating">ratingsiden</a>.</p>
EOF
- make_table($aux_parms, $match_stddev, $lowest_division, \%ratings, $cov, $division, $subdivision);
+ make_table($locale, $aux_parms, $match_stddev, $lowest_division, \%ratings, $cov, $division, $subdivision);
my $avg_rating = find_avg_rating(\%ratings);
printf " <p style=\"clear: both; padding-top: 1em;\">Gjennomsnittlig rating i denne avdelingen er <strong>%.1f</strong>.</p>\n", $avg_rating;