6 use CGI::Carp qw( fatalsToBrowser );
13 use lib qw(../include);
17 my $dbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password)
18 or die "connect: " . $DBI::errstr;
19 $dbh->{AutoCommit} = 0;
20 $dbh->{RaiseError} = 1;
22 binmode STDOUT, ':utf8';
25 my $locale = wloh_common::get_locale($cgi);
27 my $aux_parms = wloh_common::get_auxillary_parameters($dbh, $locale);
29 wloh_common::set_locale($locale);
31 my $season = wloh_common::get_max_season($dbh, $locale);
33 # Pick up all the subdivisions' ratings.
34 my %subdivision_ratings = ();
35 my $q = $dbh->prepare('SELECT divisjon, avdeling, serie_id, AVG(rating) AS avg_rating FROM ratings NATURAL JOIN siste_divisjon NATURAL JOIN spiller_kultur WHERE kultur=? AND sesong=? GROUP BY divisjon, avdeling, serie_id ORDER BY divisjon, avdeling');
36 $q->execute($locale, $season);
38 while (my $ref = $q->fetchrow_hashref) {
39 my $division = $ref->{'divisjon'};
40 my $rating = $ref->{'avg_rating'};
41 my $id = $ref->{'serie_id'};
43 push @{$subdivision_ratings{$division}}, [ $id, $rating ];
46 $q = $dbh->prepare('SELECT divisjon,AVG(rating) AS avg_rating,STDDEV(rating) AS stddev_rating FROM ratings NATURAL JOIN siste_divisjon NATURAL JOIN spiller_kultur WHERE kultur=? AND sesong=? GROUP BY divisjon ORDER BY divisjon');
47 $q->execute($locale, $season);
52 while (my $ref = $q->fetchrow_hashref) {
55 $division{'#rank'} = wloh_common::get_ordinal($ref->{'divisjon'}, $locale);
56 $division{'#average'} = sprintf "%.1f", $ref->{'avg_rating'};
57 $division{'#stddev'} = sprintf "%.1f", $ref->{'stddev_rating'};
59 my @subdivisions = ();
60 for my $arr (@{$subdivision_ratings{$ref->{'divisjon'}}}) {
61 my ($id, $rating) = @$arr;
63 '#divlink' => sprintf("%.1f", $rating),
64 '#divlink/href' => sprintf("http://wordfeud.aasmul.net/serie-%d", $id)
68 $division{'subdivisions'} = \@subdivisions;
70 push @divisions, \%division;
76 NATURAL JOIN kanonisk_navn
77 NATURAL JOIN siste_divisjon
78 NATURAL JOIN spiller_kultur
80 ORDER BY rating DESC');
86 while (my $ref = $q->fetchrow_hashref) {
89 $player{'#rank'} = wloh_common::get_ordinal(++$i, $locale);
90 $player{'#user'} = Encode::decode_utf8($ref->{'navn'});
91 $player{'#user/href'} = sprintf "http://wordfeud.aasmul.net/bruker-%d", $ref->{'id'};
92 $player{'#rating'} = sprintf "%.1f", $ref->{'rating'};
93 $player{'#stddev'} = sprintf "%.1f", $ref->{'rating_stddev'};
94 $player{'#divlink'} = $ref->{'serie_navn'};
95 $player{'#divlink/href'} = sprintf "http://wordfeud.aasmul.net/serie-%d", $ref->{'serie_id'};
97 push @players, \%player;
100 print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+75m');
101 wloh_common::process_template('rating', $locale, {
102 '#navbar' => wloh_common::get_navbar($cgi, $dbh, $locale),
103 'iterations' => $aux_parms->{'num_iterations'},
104 'rating-prior-stddev' => sprintf("%.1f", $aux_parms->{'rating_prior_stddev'}),
105 'match-stddev' => sprintf("%.1f", $aux_parms->{'score_stddev'} * sqrt(2.0)),
106 '#divisions' => XML::Template::alternate('tr/class', \@divisions, 'even', 'odd'),
107 '#players' => XML::Template::alternate('tr/class', \@players, 'even', 'odd'),
108 'last-sync' => wloh_common::get_last_sync($dbh)