4 use lib qw(/srv/bzr.sesse.net/www/xml-template/perl/);
7 require '../foosball.pm',
9 my $dbh = foosball::db_connect();
11 # Single score board (whoa, inefficient)
13 my $q = $dbh->prepare('select username from users');
15 while (my $ref = $q->fetchrow_hashref) {
16 my $username = $ref->{'username'};
17 my ($rating, $rd) = foosball::find_single_rating($dbh, $username);
18 my ($oldrating) = foosball::find_single_rating($dbh, $username, 'AND ratetime::date < current_date ');
21 if (defined($oldrating)) {
22 $trend = (sprintf "%+d", int($rating-$oldrating+0.5));
26 'username' => $username,
27 'rating' => int($rating+0.5),
29 'lowerbound' => int($rating - 3.0*$rd + 0.5),
33 @single_top = sort { $b->{'lowerbound'} <=> $a->{'lowerbound'} } @single_top;
37 $q = $dbh->prepare('select username from users');
39 while (my $ref = $q->fetchrow_hashref) {
40 my $username = $ref->{'username'};
41 my ($rating, $rd) = foosball::find_double_rating($dbh, $username);
42 my ($oldrating) = foosball::find_double_rating($dbh, $username, 'AND ratetime::date < current_date ');
45 if (defined($oldrating)) {
46 $trend = (sprintf "%+d", int($rating-$oldrating+0.5));
50 'username' => $username,
51 'rating' => int($rating+0.5),
53 'lowerbound' => int($rating - 3.0*$rd + 0.5),
57 @double_top = sort { $b->{'lowerbound'} <=> $a->{'lowerbound'} } @double_top;
61 $q = $dbh->prepare('select * from ( select to_char(gametime, \'IYYY-MM-DD HH24:MI\') as gametime,\'Double\' as type,team1_username1 || \' / \' || team1_username2 as username1, team2_username1 || \' / \' || team2_username2 as username2,score1,score2 from double_results union all select to_char(gametime, \'IYYY-MM-DD HH24:MI\') as gametime,\'Single\' as type,username1,username2,score1,score2 from single_results ) t1 order by gametime desc limit 10');
63 while (my $ref = $q->fetchrow_hashref) {
64 push @last_games, $ref;
69 print CGI->header(-type=>'application/xhtml+xml');
71 my $doc = XML::Template::process_file('index.xml', {
72 '#singletop' => \@single_top,
73 '#doubletop' => \@double_top,
74 '#lastgames' => \@last_games,