X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=www%2Findex.pl;h=c1ab7d17a2993e2dab12c7a66cfcb31556c88645;hb=1f8489da48b9721d9c44b97749078a94b935a7b2;hp=6f77c3323de3117a4bdae5d32a0c8ff734472029;hpb=da3fa6c4de949158716dd130551cf6494f3766da;p=foosball diff --git a/www/index.pl b/www/index.pl index 6f77c33..c1ab7d1 100755 --- a/www/index.pl +++ b/www/index.pl @@ -21,14 +21,14 @@ while (my $ref = $q->fetchrow_hashref) { my $trend = ""; if (defined($oldrating)) { - $trend = (sprintf "%+d", int($rating-$oldrating+0.5)); + $trend = (sprintf "%+d", foosball::round($rating-$oldrating)); } push @single_top, { 'username' => $username, - 'rating' => int($rating+0.5), - 'rd' => int($rd+0.5), - 'lowerbound' => int($rating - 3.0*$rd + 0.5), + 'rating' => foosball::round($rating), + 'rd' => foosball::round($rd), + 'lowerbound' => foosball::round($rating - 3.0*$rd), 'trend' => $trend, }; } @@ -47,14 +47,14 @@ while (my $ref = $q->fetchrow_hashref) { my $trend = ""; if (defined($oldrating)) { - $trend = (sprintf "%+d", int($rating-$oldrating+0.5)); + $trend = (sprintf "%+d", foosball::round($rating-$oldrating)); } push @double_top, { 'username' => $username, - 'rating' => int($rating+0.5), - 'rd' => int($rd+0.5), - 'lowerbound' => int($rating - 3.0*$rd + 0.5), + 'rating' => foosball::round($rating), + 'rd' => foosball::round($rd), + 'lowerbound' => foosball::round($rating - 3.0*$rd), 'trend' => $trend, }; } @@ -65,6 +65,7 @@ my @last_games = (); $q = $dbh->prepare(' select * from ( select + gametime as sort_gametime, to_char(gametime, \'IYYY-MM-DD HH24:MI\') as gametime, \'Double\' as type, team1_username1 || \' / \' || team1_username2 as username1, @@ -72,7 +73,9 @@ select * from ( score1, score2, ra1.rating_diff as diff1, - ra2.rating_diff as diff2 + ra2.rating_diff as diff2, + ra3.rating_diff as diff3, + ra4.rating_diff as diff4 from double_results re join double_rating ra1 @@ -80,9 +83,16 @@ select * from ( and re.team1_username1=ra1.username join double_rating ra2 on re.gametime=ra2.ratetime - and re.team2_username1=ra2.username + and re.team1_username2=ra2.username + join double_rating ra3 + on re.gametime=ra3.ratetime + and re.team2_username1=ra3.username + join double_rating ra4 + on re.gametime=ra4.ratetime + and re.team2_username2=ra4.username union all select + gametime as sort_gametime, to_char(gametime, \'IYYY-MM-DD HH24:MI\') as gametime, \'Single\' as type, username1, @@ -90,7 +100,9 @@ select * from ( score1, score2, ra1.rating_diff as diff1, - ra2.rating_diff as diff2 + null as diff2, + ra2.rating_diff as diff3, + null as diff4 from single_results re join single_rating ra1 @@ -100,11 +112,20 @@ select * from ( on re.gametime=ra2.ratetime and re.username2=ra2.username ) t1 -order by gametime desc limit 10'); +order by sort_gametime desc limit 10'); $q->execute(); while (my $ref = $q->fetchrow_hashref) { - $ref->{'diff1'} = sprintf "%+d", int($ref->{'diff1'} + 0.5); - $ref->{'diff2'} = sprintf "%+d", int($ref->{'diff2'} + 0.5); + if (defined($ref->{'diff2'})) { + $ref->{'diff1'} = sprintf "%+d / %+d", + foosball::round($ref->{'diff1'}), + foosball::round($ref->{'diff2'}); + $ref->{'diff2'} = sprintf "%+d / %+d", + foosball::round($ref->{'diff3'}), + foosball::round($ref->{'diff4'}); + } else { + $ref->{'diff1'} = sprintf "%+d", foosball::round($ref->{'diff1'}); + $ref->{'diff2'} = sprintf "%+d", foosball::round($ref->{'diff3'}); + } push @last_games, $ref; } @@ -113,8 +134,8 @@ $dbh->disconnect; print CGI->header(-type=>'application/xhtml+xml'); my $doc = XML::Template::process_file('index.xml', { - '#singletop' => \@single_top, - '#doubletop' => \@double_top, - '#lastgames' => \@last_games, + '#singletop' => XML::Template::alternate('tr/class', \@single_top, 'odd', 'even'), + '#doubletop' => XML::Template::alternate('tr/class', \@double_top, 'odd', 'even'), + '#lastgames' => XML::Template::alternate('tr/class', \@last_games, 'odd', 'even'), }); print $doc->toString;