BUGFIX: wrong SQL query for min and max time of games
[e-DoKo.git] / stats.php
index 83106cf48223f96f45073958f045e797d85a4f96..ba32a9269077c0954b202b96e87becfe8592c65c 100644 (file)
--- a/stats.php
+++ b/stats.php
@@ -19,7 +19,6 @@ if(DB_open()<0)
 
 /* start a session, if it is not already running */
 session_start();
-
 /* done major error checking, output header of HTML page */
 output_header();
 
@@ -29,7 +28,8 @@ if(myisset("logout"))
     session_unset();
     session_destroy();
     $_SESSION = array();
-    echo "you are now logged out!";
+    echo "<div class=\"message\"><span class=\"bigger\">You are now logged out!</span><br />\n".
+      "(<a href=\"$host\">This will take you back to the home-page</a>)</div>";
   }
 /* user status page */
 else if( isset($_SESSION["name"]) )
@@ -80,6 +80,16 @@ else if( isset($_SESSION["name"]) )
         $GameN =  $r[0];
         echo " $GameN </p>\n";
 
+        echo "<p>The contra party wins in ";
+        $result = mysql_query("SELECT COUNT(*) from Score".
+                              " LEFT JOIN Game ON Game.id=game_id".
+                              " WHERE score='againstqueens'".
+                              " AND Game.status='gameover'");
+        while( $r = mysql_fetch_array($result,MYSQL_NUM))
+          echo $r[0];
+        echo " games.</p>\n";
+
+
         /* number of solos */
         echo "<p>These kind of games have been played this often: <br />";
         $result = mysql_query("SELECT COUNT(*) as c,type from Game".
@@ -87,7 +97,7 @@ else if( isset($_SESSION["name"]) )
                               " GROUP BY type".
                               " ORDER BY c DESC");
         while( $r = mysql_fetch_array($result,MYSQL_NUM))
-          echo "".$r[1]." (".$r[0].")<br />";
+          echo "".$r[1]." (".$r[0].") <br />";
         echo " </p>\n";
 
         /* break up solos in types */
@@ -113,33 +123,47 @@ else if( isset($_SESSION["name"]) )
  select id,type,solo,status from game where id in (select id from game where randomnumbers in (select randomnumbers from game where id=27));
 
         */
-        echo "<p>Most extra points in a game::<br />\n";
+        echo "<p>Most extra points (doko, fox, karlchen) in a single game:<br />\n";
         $result = mysql_query("SELECT COUNT(*) as c,fullname FROM Score".
                               " LEFT JOIN User ON User.id=winner_id" .
                               " WHERE score IN ('fox','doko','karlchen')".
-                              " GROUP BY fullname".
-                              " ORDER BY c DESC LIMIT 1" );
+                              " GROUP BY game_id,fullname".
+                              " ORDER BY c DESC LIMIT 3" );
         while( $r = mysql_fetch_array($result,MYSQL_NUM))
           echo $r[1]." (".$r[0].") <br />\n";
         echo "</p>\n";
 
         /* longest and shortest game */
-        $r=mysql_query("SELECT MIN(datediff(mod_date,create_date)),session".
-                       " FROM Game WHERE status='gameover' GROUP BY status");
+        $r=mysql_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= mysql_fetch_array($r,MYSQL_NUM);
-            echo "<p> The shortest game took only ".$short[0]." days.<br />\n";
+            $names = DB_get_all_names_by_gameid($short[2]);
+            echo "<p> The shortest game took only ".$short[0]." hours and was played by  ".join(", ",$names).".<br />\n";
           }
 
-        $r=mysql_query("SELECT MAX(datediff(mod_date,create_date)),session".
-                       " FROM Game where status='gameover' GROUP BY status");
+        $r=mysql_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= mysql_fetch_array($r,MYSQL_NUM);
             echo "The longest game took ".$long[0]." days.</p>\n";
           }
 
+        $r=mysql_query("SELECT COUNT(*) as c, session, id FROM Game ".
+                       " GROUP BY session ORDER BY c DESC LIMIT 1");
+        if($r)
+          {
+            $long  = mysql_fetch_array($r,MYSQL_NUM);
+            $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).".</p>\n";
+          }
+
         /* most reminders */
         echo "<p>These players got the most reminders:<br />\n";
         $result = mysql_query("SELECT COUNT(*) as c,fullname from Reminder".
@@ -202,15 +226,6 @@ else if( isset($_SESSION["name"]) )
         echo " games</p>\n";
         */
 
-        echo "<p>The contra party wins in ";
-        $result = mysql_query("SELECT COUNT(*) from Score".
-                              " LEFT JOIN Game ON Game.id=game_id".
-                              " WHERE score='againstqueens'".
-                              " AND Game.status='gameover'".
-                              " AND Game.type<>'solo'");
-        while( $r = mysql_fetch_array($result,MYSQL_NUM))
-          echo $r[0];
-        echo " games</p>\n";
 
         /*
          how often is the last trick a non-trump trick
@@ -222,7 +237,8 @@ else if( isset($_SESSION["name"]) )
  else
    {
      /* send them back to the login page */
-     echo "<p>Please log in</p>";
+    echo "<div class=\"message\"><span class=\"bigger\">You need to log in!</span><br />\n".
+      "(<a href=\"$host\">This will take you back to the login-page</a>)</div>";
    }
 
 output_footer();