2 /* make sure that we are not called from outside the scripts,
3 * use a variable defined in config.php to check this
8 $name = $_SESSION["name"];
9 $email = DB_get_email('name',$name);
11 $myid = DB_get_userid('email',$email);
17 $PREF = DB_get_PREF($myid);
19 DB_update_user_timestamp($myid);
24 echo "<div class=\"user\">\n";
26 /* always: if player logged in: add link to cards */
28 /* total number of games */
29 echo "<p>The number of finished games on this server is: ";
30 $r = DB_query_array("SELECT COUNT(*) from Game".
31 " WHERE status='gameover'");
33 echo " $GameN </p>\n";
35 echo "<p>The contra party wins in ";
36 $result = DB_query("SELECT COUNT(*) from Score".
37 " LEFT JOIN Game ON Game.id=game_id".
38 " WHERE score='againstqueens'".
39 " AND Game.status='gameover'");
40 while( $r = DB_fetch_array($result))
46 echo "<p>These kind of games have been played this often: <br />";
47 $result = DB_query_array_all("SELECT type,COUNT(*) as c from Game".
48 " WHERE status='gameover'".
51 array_unshift($result,array("Type","Frequency"));
52 echo output_table($result,"stats");
55 /* break up solos in types */
56 echo "<p>These kind of solos have been played this often: <br />";
57 $result = DB_query_array_all("SELECT solo,COUNT(*) as c from Game".
58 " WHERE status='gameover'".
62 array_unshift($result,array("Type","Frequency"));
63 echo output_table($result,"stats");
67 2 top user mit maximaler quote an solo (min 10 games)
69 top scoring game: winning players
71 game with the same cards: show 3 at random:
72 player who won, points, what kind of game
73 select g1.id, g2.id from game g1 left join game g2 on g1.randomnumbers=g2.randomnumbers where g1.id<g2.id order by g1.id
74 select id from game where randomnumbers like "blablabl%"; the % is like .* in regexp
75 select id,type,solo,status from game where id in (select id from game where randomnumbers in (select randomnumbers from game where id=27));
78 echo "<p>Most extra points (doko, fox, karlchen) in a single game:<br />\n";
79 $result = DB_query_array_all("SELECT fullname,COUNT(*) as c FROM Score".
80 " LEFT JOIN User ON User.id=winner_id" .
81 " WHERE score IN ('fox','doko','karlchen')".
82 " GROUP BY game_id,fullname".
83 " ORDER BY c DESC LIMIT 3" );
84 array_unshift($result,array("Name","Points"));
85 echo output_table($result,"stats");
88 /* longest and shortest game */
89 $r=DB_query("SELECT timediff(mod_date,create_date) ,session,id".
90 " FROM Game WHERE status='gameover'".
91 " ORDER BY time_to_sec(timediff(mod_date,create_date)) ASC LIMIT 1");
95 $short= DB_fetch_array($r);
96 $names = DB_get_all_names_by_gameid($short[2]);
97 echo "<p> The shortest game took only ".$short[0]." hours and was played by ".join(", ",$names).".<br />\n";
100 $r=DB_query("SELECT datediff(mod_date,create_date) ,session,id".
101 " FROM Game WHERE status='gameover'".
102 " ORDER BY time_to_sec(timediff(mod_date,create_date)) DESC LIMIT 1");
105 $long= DB_fetch_array($r);
106 echo "The longest game took ".$long[0]." days.</p>\n";
109 $r=DB_query("SELECT COUNT(*) as c, session, id FROM Game ".
110 " GROUP BY session ORDER BY c DESC LIMIT 1");
113 $long = DB_fetch_array($r);
114 $names = DB_get_all_names_by_gameid($long[2]);
115 echo "The longest session is session ".$long[1]." with ".$long[0].
116 " games played by ".join(", ",$names).".</p>\n";
120 echo "<p>These players got the most reminders per game:<br />\n";
121 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
122 " (SELECT COUNT(*) FROM Hand".
123 " WHERE user_id=User.id) as c".
125 " LEFT JOIN User ON User.id=user_id".
127 " ORDER BY c DESC LIMIT 5" );
128 array_unshift($result,array("Name","Reminders"));
129 echo output_table($result,"stats");
133 echo "<p>These players caught the most foxes per game:<br />\n";
134 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
135 " (SELECT COUNT(*) FROM Hand".
136 " WHERE user_id=User.id) as c".
138 " LEFT JOIN User ON User.id=winner_id".
139 " WHERE score='fox'".
140 " GROUP BY winner_id".
141 " ORDER BY c DESC LIMIT 5" );
142 array_unshift($result,array("Name","Number of foxes caught"));
143 echo output_table($result,"stats");
146 echo "<p>These players lost their fox most often per game:<br />\n";
147 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
148 " (SELECT COUNT(*) FROM Hand".
149 " WHERE user_id=User.id) as c".
151 " LEFT JOIN User ON User.id=looser_id".
152 " WHERE score='fox'".
153 " GROUP BY looser_id".
154 " ORDER BY c DESC LIMIT 5" );
155 array_unshift($result,array("Name","Number of foxes lost"));
156 echo output_table($result,"stats");
159 echo "<p>These players lost their fox least often per game:<br />\n";
160 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
161 " (SELECT COUNT(*) FROM Hand".
162 " WHERE user_id=User.id) as c".
164 " LEFT JOIN User ON User.id=looser_id".
165 " WHERE score='fox'".
166 " GROUP BY looser_id".
167 " ORDER BY c ASC LIMIT 5" );
168 array_unshift($result,array("Name","Number of foxes lost"));
169 echo output_table($result,"stats");
172 /* which position wins the most tricks */
173 echo "<p>Which positions at the table make the most tricks:<br />\n";
174 $result = DB_query("SELECT COUNT(*) AS c,winner FROM Trick".
176 " ORDER BY winner ASC " );
177 $r = DB_fetch_array($result);
178 if($r[1]==NULL) /* ongoing games, no winner yet */
179 $r = DB_fetch_array($result);
180 echo " left ".$r[0]." <br />\n";
181 $r = DB_fetch_array($result);
182 echo " top ".$r[0]." <br />\n";
183 $r = DB_fetch_array($result);
184 echo " right ".$r[0]." <br />\n";
185 $r = DB_fetch_array($result);
186 echo " bottom ".$r[0]." <br />\n";
190 echo "<p>Most games played on the server:<br />\n";
191 $result = DB_query_array_all("SELECT fullname, COUNT(*) as c " .
193 " LEFT JOIN User ON User.id=user_id".
195 " ORDER BY c DESC LIMIT 7" );
196 array_unshift($result,array("Name","Number of games"));
197 echo output_table($result,"stats");
200 /* most active games */
201 echo "<p>These players are involved in this many active games:<br />\n";
202 $result = DB_query_array_all("SELECT fullname, COUNT(*) as c " .
204 " LEFT JOIN User ON User.id=user_id".
205 " LEFT JOIN Game ON Game.id=game_id".
206 " WHERE Game.status<>'gameover'".
208 " ORDER BY c DESC LIMIT 7" );
209 array_unshift($result,array("Name","Number of active games"));
210 echo output_table($result,"stats");
215 does the party win more often if they start
217 echo "<p>The party playing first wins in";
218 $result = mysql_query("SELECT COUNT(*) from Score".
219 " LEFT JOIN Game ON Game.id=game_id".
220 " WHERE score='againstqueens'".
221 " AND Game.status='gameover'".
222 " AND Game.type<>'solo'");
223 while( $r = mysql_fetch_array($result,MYSQL_NUM))
224 echo $r[1]." (".$r[0].") <br />\n";
227 echo "<p>Points/game (you need at least 10 games to be in this statistic): <br />\n";
228 generate_global_score_table();
231 how often is the last trick a non-trump trick
234 echo "</div>\n"; /* end output */