NEW FEATURES: show global statistic
authorArun Persaud <arun@nubati.net>
Mon, 5 May 2008 02:40:10 +0000 (19:40 -0700)
committerArun Persaud <arun@nubati.net>
Mon, 5 May 2008 02:40:10 +0000 (19:40 -0700)
show points/game for all players that have 10 or more games

Signed-off-by: Arun Persaud <arun@nubati.net>
include/db.php
include/functions.php
include/stats.php

index 42d2bef9341fd185d10077000a500b746726f2bf..b13c0f02866ecae86a0328240eb4352009f4c07d 100644 (file)
@@ -919,10 +919,15 @@ function DB_get_gameids_of_finished_games_by_session($session)
 {
   $ids = array ();
 
 {
   $ids = array ();
 
-  $queryresult = mysql_query("SELECT id FROM Game ".
-                            "  WHERE session=$session ".
-                            "   AND status='gameover' ".
-                            " ORDER BY create_date ASC");
+  if($session==0) /* return all games */
+    $queryresult = mysql_query("SELECT id FROM Game ".
+                              " WHERE status='gameover' ".
+                              " ORDER BY create_date ASC");
+  else   /* return games in a session */
+    $queryresult = mysql_query("SELECT id FROM Game ".
+                              "  WHERE session=$session ".
+                              "   AND status='gameover' ".
+                              " ORDER BY create_date ASC");
 
   $i=0;
   while($r = mysql_fetch_array($queryresult,MYSQL_NUM) )
 
   $i=0;
   while($r = mysql_fetch_array($queryresult,MYSQL_NUM) )
index 4abaf935ce9fd6bb2efccbce28e422367f503fa1..2e4c08392d051bf10a2e8c615dae162ec045c525 100644 (file)
@@ -838,7 +838,6 @@ function display_user_menu()
 
 function generate_score_table($session)
 {
 
 function generate_score_table($session)
 {
-
   /* get all ids */
   $gameids = DB_get_gameids_of_finished_games_by_session($session);
 
   /* get all ids */
   $gameids = DB_get_gameids_of_finished_games_by_session($session);
 
@@ -892,4 +891,65 @@ function generate_score_table($session)
   return $output;
 }
 
   return $output;
 }
 
+function generate_global_score_table()
+{
+  /* get all ids */
+  $gameids = DB_get_gameids_of_finished_games_by_session(0);
+
+  if($gameids == NULL)
+    return "";
+
+  /* get player id, names... from the User table */
+  $player = array();
+  $result = mysql_query("SELECT User.id, User.fullname FROM User");
+
+  while( $r = mysql_fetch_array($result,MYSQL_NUM))
+    $player[] = array( 'id' => $r[0], 'name'=> $r[1], 'points' => 0 ,'nr' => 0);
+
+  /* get points and generate table */
+  foreach($gameids as $gameid)
+    {
+      $re_score = DB_get_score_by_gameid($gameid);
+      /* TODO: this shouldn't loop over all players, just the 4 players that are in the game */
+      foreach($player as $key=>$pl)
+       {
+         $party = DB_get_party_by_gameid_and_userid($gameid,$pl['id']);
+         if($party == "re")
+           if(DB_get_gametype_by_gameid($gameid)=="solo")
+             $player[$key]['points'] += 3*$re_score;
+           else
+             $player[$key]['points'] += $re_score;
+         else if ($party == "contra")
+           $player[$key]['points'] -= $re_score;
+         if($party)
+           $player[$key]['nr']+=1;
+       }
+    }
+  
+  echo "<table>\n <tr>\n";
+  function cmp($a,$b)
+  {
+    if($a['nr']==0 ) return 1;
+    if($b['nr']==0) return 1;
+
+    $a=$a['points']/$a['nr'];
+    $b=$b['points']/$b['nr'];
+
+    if ($a == $b) 
+      return 0;
+    return ($a > $b) ? -1 : 1;
+  }
+  usort($player,"cmp");
+  foreach($player as $pl)
+    {
+      if($pl['nr']>10)
+       echo "  <tr><td>",$pl['name'],"</td><td>",round($pl['points']/$pl['nr'],3),"</td></tr>\n";
+    }
+  echo "</table>\n";
+    
+  return;
+}
+
+
+
 ?>
 ?>
index cbfd866a19ca3b3f4a3e1f7a10b5d58ede93d578..bde6a096b19cb0d0eab56a3fdaf6b707f2f5bfbb 100644 (file)
@@ -228,8 +228,9 @@ echo "</p>\n";
  echo $r[1]." (".$r[0].") <br />\n";
  echo " games</p>\n";
 */
  echo $r[1]." (".$r[0].") <br />\n";
  echo " games</p>\n";
 */
-
-
+echo "<p>Points/game (you need at least 10 games to be in this statistic): <br />\n";
+generate_global_score_table();
+echo "</p>\n";
 /*
  how often is the last trick a non-trump trick
 */
 /*
  how often is the last trick a non-trump trick
 */