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 next if ($rating == 0 || $rating == 1500);
20 my ($oldrating) = foosball::find_single_rating($dbh, $username, 'AND ratetime::date < current_date ');
23 if (defined($oldrating)) {
24 $trend = (sprintf "%+d", int($rating-$oldrating+0.5));
28 'username' => $username,
29 'rating' => int($rating+0.5),
31 'lowerbound' => int($rating - 3.0*$rd + 0.5),
35 @single_top = sort { $b->{'lowerbound'} <=> $a->{'lowerbound'} } @single_top;
39 $q = $dbh->prepare('select username from users');
41 while (my $ref = $q->fetchrow_hashref) {
42 my $username = $ref->{'username'};
43 my ($rating, $rd) = foosball::find_double_rating($dbh, $username);
44 next if ($rating == 0 || $rating == 1500);
46 my ($oldrating) = foosball::find_double_rating($dbh, $username, 'AND ratetime::date < current_date ');
49 if (defined($oldrating)) {
50 $trend = (sprintf "%+d", int($rating-$oldrating+0.5));
54 'username' => $username,
55 'rating' => int($rating+0.5),
57 'lowerbound' => int($rating - 3.0*$rd + 0.5),
61 @double_top = sort { $b->{'lowerbound'} <=> $a->{'lowerbound'} } @double_top;
65 $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');
67 while (my $ref = $q->fetchrow_hashref) {
68 push @last_games, $ref;
73 print CGI->header(-type=>'application/xhtml+xml');
75 my $doc = XML::Template::process_file('index.xml', {
76 '#singletop' => \@single_top,
77 '#doubletop' => \@double_top,
78 '#lastgames' => \@last_games,