X-Git-Url: https://git.sesse.net/?p=wloh;a=blobdiff_plain;f=www%2Frating.pl;h=5eb822807d1859b7b013c6f17960f83de2c2aacc;hp=8c6026280a3de02ebfd0d8e02ed3d6e9f11f6f02;hb=854c8eb6e0a3f9836043faaf2f43c05c190619fb;hpb=6a2b648a88b67f71fa5adf9056e495c892483e71 diff --git a/www/rating.pl b/www/rating.pl index 8c60262..5eb8228 100755 --- a/www/rating.pl +++ b/www/rating.pl @@ -11,6 +11,7 @@ use HTML::Entities; use utf8; use locale; require '../config.pm'; +require '../common.pm'; my $dbh = DBI->connect($config::local_connstr, $config::local_username, $config::local_password) or die "connect: " . $DBI::errstr; @@ -19,23 +20,24 @@ $dbh->{RaiseError} = 1; binmode STDOUT, ':utf8'; -# Find auxillary parameters. -my %params = (); -my $q = $dbh->prepare('SELECT * FROM ratings WHERE id < 0'); -$q->execute; -while (my $ref = $q->fetchrow_hashref) { - $params{$ref->{'id'}} = $ref->{'rating'}; -} -my $match_stddev = $params{-2} * sqrt(2.0); +my $cgi = CGI->new; +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); print CGI->header(-type=>'text/html; charset=utf-8', -expires=>'+5m'); POSIX::setlocale(&POSIX::LC_ALL, 'nb_NO.UTF-8'); -printf <<"EOF", $params{-3}, $match_stddev; - +printf <<"EOF", $aux_parms->{'rating_prior_stddev'}, $match_stddev; + + + WLoH-rating - +

WLoH-rating

@@ -47,7 +49,7 @@ printf <<"EOF", $params{-3}, $match_stddev; for tilgang!), og oppdateres hver hele time. Den er fullstendig uoffisiell, og har ingen innflytelse på WLoH, men brukes for å estimere vinnersannsynligheter i - sannsynlighetsberegningen.

+ sannsynlighetsberegningen.

Modellen kan endre seg når som helst når jeg føler for det :-) Ikke ta ratingen alt for alvorlig, selv om den er basert på @@ -57,16 +59,16 @@ printf <<"EOF", $params{-3}, $match_stddev;

Modellparametre

For de som vet litt om slikt. Det finnes også en lengre, mer detaljert - forklaring beregnet på ikke-matematikere.

+ forklaring beregnet på ikke-matematikere.

Divisjonsoversikt

@@ -79,8 +81,23 @@ printf <<"EOF", $params{-3}, $match_stddev; EOF -$q = $dbh->prepare('SELECT divisjon,AVG(rating) AS avg_rating,STDDEV(rating) AS stddev_rating FROM ratings NATURAL JOIN siste_divisjon GROUP BY divisjon ORDER BY divisjon'); -$q->execute; +my $season = wloh_common::get_max_season($dbh, $locale); + +# Pick up all the subdivisions' ratings. +my %subdivision_ratings = (); +my $q = $dbh->prepare('SELECT divisjon, avdeling, serie_id, AVG(rating) AS avg_rating FROM ratings NATURAL JOIN siste_divisjon WHERE sesong=? GROUP BY divisjon, avdeling, serie_id ORDER BY divisjon, avdeling'); +$q->execute($season); + +while (my $ref = $q->fetchrow_hashref) { + my $division = $ref->{'divisjon'}; + my $rating = $ref->{'avg_rating'}; + my $id = $ref->{'serie_id'}; + + push @{$subdivision_ratings{$division}}, [ $id, $rating ]; +} + +$q = $dbh->prepare('SELECT divisjon,AVG(rating) AS avg_rating,STDDEV(rating) AS stddev_rating FROM ratings NATURAL JOIN siste_divisjon WHERE sesong=? GROUP BY divisjon ORDER BY divisjon'); +$q->execute($season); my $i = 0; while (my $ref = $q->fetchrow_hashref) { @@ -92,6 +109,11 @@ while (my $ref = $q->fetchrow_hashref) { printf " %d.\n", $ref->{'divisjon'}; printf " %.1f\n", $ref->{'avg_rating'}; printf " %.1f\n", $ref->{'stddev_rating'}; + + for my $arr (@{$subdivision_ratings{$ref->{'divisjon'}}}) { + my ($id, $rating) = @$arr; + printf " %.1f\n", $id, $rating; + } print " \n"; } @@ -115,8 +137,10 @@ SELECT * FROM ratings NATURAL JOIN kanonisk_navn NATURAL JOIN siste_divisjon + NATURAL JOIN spiller_kultur +WHERE kultur=? ORDER BY rating DESC'); -$q->execute; +$q->execute($locale); $i = 0; while (my $ref = $q->fetchrow_hashref) { @@ -132,13 +156,13 @@ while (my $ref = $q->fetchrow_hashref) { printf " %s\n", $ref->{'serie_id'}, $ref->{'serie_navn'}; print " \n"; } +print " \n"; + +wloh_common::output_last_sync($dbh); print <<"EOF"; - EOF -$match_stddev = $params{-2} * sqrt(2.0); - $dbh->rollback;