From: Arun Persaud Date: Mon, 26 May 2008 21:28:29 +0000 (-0700) Subject: LAYOUT: more tables on the statistics page X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=commitdiff_plain;h=af2ee6fe421192cd2b42fcb4bbd09179bbce3943;hp=61ced3e42a77e624e2209a94c5f324a2071eef7d LAYOUT: more tables on the statistics page changed the last two tables to the new CSS-tables. Signed-off-by: Arun Persaud --- diff --git a/include/functions.php b/include/functions.php index 9f58f51..a338f38 100644 --- a/include/functions.php +++ b/include/functions.php @@ -934,6 +934,8 @@ function generate_score_table($session) function generate_global_score_table() { + $return = array(); + /* get all ids */ $gameids = DB_get_gameids_of_finished_games_by_session(0); @@ -967,7 +969,6 @@ function generate_global_score_table() } } - echo "\n \n"; function cmp($a,$b) { if($a['nr']==0 ) return 1; @@ -981,14 +982,15 @@ function generate_global_score_table() return ($a > $b) ? -1 : 1; } usort($player,"cmp"); + foreach($player as $pl) { + /* limit to players with at least 10 games */ if($pl['nr']>10) - echo " \n"; + $return[] = array( $pl['name'], round($pl['points']/$pl['nr'],3) ); } - echo "
",$pl['name'],"",round($pl['points']/$pl['nr'],3),"
\n"; - return; + return $return; } diff --git a/include/stats.php b/include/stats.php index a702a88..c1b81ab 100644 --- a/include/stats.php +++ b/include/stats.php @@ -41,6 +41,37 @@ while( $r = DB_fetch_array($result)) echo $r[0]; echo " games.

\n"; +/* longest and shortest game */ +$r=DB_query("SELECT timediff(mod_date,create_date) ,session,id". + " FROM Game WHERE status='gameover'". + " ORDER BY time_to_sec(timediff(mod_date,create_date)) ASC LIMIT 1"); + +if($r) + { + $short= DB_fetch_array($r); + $names = DB_get_all_names_by_gameid($short[2]); + echo "

The shortest game took only ".$short[0]." hours and was played by ".join(", ",$names).".
\n"; + } + +$r=DB_query("SELECT datediff(mod_date,create_date) ,session,id". + " FROM Game WHERE status='gameover'". + " ORDER BY time_to_sec(timediff(mod_date,create_date)) DESC LIMIT 1"); +if($r) + { + $long= DB_fetch_array($r); + echo "The longest game took ".$long[0]." days.

\n"; + } + +$r=DB_query("SELECT COUNT(*) as c, session, id FROM Game ". + " GROUP BY session ORDER BY c DESC LIMIT 1"); +if($r) + { + $long = DB_fetch_array($r); + $names = DB_get_all_names_by_gameid($long[2]); + echo "The longest session is session ".$long[1]." with ".$long[0]. + " games played by ".join(", ",$names).".

\n"; + } + /* number of solos */ echo "

These kind of games have been played this often:
"; @@ -85,36 +116,6 @@ array_unshift($result,array("Name","Points")); echo output_table($result,"stats"); echo "

\n"; -/* longest and shortest game */ -$r=DB_query("SELECT timediff(mod_date,create_date) ,session,id". - " FROM Game WHERE status='gameover'". - " ORDER BY time_to_sec(timediff(mod_date,create_date)) ASC LIMIT 1"); - -if($r) - { - $short= DB_fetch_array($r); - $names = DB_get_all_names_by_gameid($short[2]); - echo "

The shortest game took only ".$short[0]." hours and was played by ".join(", ",$names).".
\n"; - } - -$r=DB_query("SELECT datediff(mod_date,create_date) ,session,id". - " FROM Game WHERE status='gameover'". - " ORDER BY time_to_sec(timediff(mod_date,create_date)) DESC LIMIT 1"); -if($r) - { - $long= DB_fetch_array($r); - echo "The longest game took ".$long[0]." days.

\n"; - } - -$r=DB_query("SELECT COUNT(*) as c, session, id FROM Game ". - " GROUP BY session ORDER BY c DESC LIMIT 1"); -if($r) - { - $long = DB_fetch_array($r); - $names = DB_get_all_names_by_gameid($long[2]); - echo "The longest session is session ".$long[1]." with ".$long[0]. - " games played by ".join(", ",$names).".

\n"; - } /* most reminders */ echo "

These players got the most reminders per game:
\n"; @@ -171,19 +172,18 @@ echo "

\n"; /* which position wins the most tricks */ echo "

Which positions at the table make the most tricks:
\n"; -$result = DB_query("SELECT COUNT(*) AS c,winner FROM Trick". - " GROUP BY winner". - " ORDER BY winner ASC " ); -$r = DB_fetch_array($result); -if($r[1]==NULL) /* ongoing games, no winner yet */ - $r = DB_fetch_array($result); -echo " left ".$r[0]."
\n"; -$r = DB_fetch_array($result); -echo " top ".$r[0]."
\n"; -$r = DB_fetch_array($result); -echo " right ".$r[0]."
\n"; -$r = DB_fetch_array($result); -echo " bottom ".$r[0]."
\n"; +$result = DB_query_array_all("SELECT CASE winner ". + " WHEN 1 THEN 'left' ". + " WHEN 2 THEN 'top' ". + " WHEN 3 THEN 'right' ". + " WHEN 4 THEN 'bottom' END,". + " COUNT(*) AS c FROM Trick". + " GROUP BY winner ". + " HAVING LENGTH(winner)>0 ". + " ORDER BY winner ASC " ); + +array_unshift($result,array("Position","Number of tricks")); +echo output_table($result,"stats"); echo "

\n"; /* most games */ @@ -225,7 +225,9 @@ echo "

\n"; echo " games

\n"; */ echo "

Points/game (you need at least 10 games to be in this statistic):
\n"; -generate_global_score_table(); +$result = generate_global_score_table(); +array_unshift($result,array("Name","Average score per game")); +echo output_table($result,"stats"); echo "

\n"; /* how often is the last trick a non-trump trick