2 /* Copyright 2006, 2007, 2008, 2009, 2010 Arun Persaud <arun@nubati.net>
4 * This file is part of e-DoKo.
6 * e-DoKo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * e-DoKo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with e-DoKo. If not, see <http://www.gnu.org/licenses/>.
21 /* make sure that we are not called from outside the scripts,
22 * use a variable defined in config.php to check this
27 $name = $_SESSION["name"];
28 $email = DB_get_email('name',$name);
30 $myid = DB_get_userid('email',$email);
34 $PREF = DB_get_PREF($myid);
36 DB_update_user_timestamp($myid);
38 display_user_menu($myid);
40 /* check if cached version exist */
41 if( !$content = getCache("cache/stats.html",60*60*24) )
47 echo "<div class=\"user wide\">\n";
49 echo "<p>Generated ".date("Y-m-d H:i:s")." (server time) </p>";
51 /* total number of games */
52 echo "<p>The number of finished games on this server is: ";
53 $r = DB_query_array("SELECT COUNT(*) from Game".
54 " WHERE status='gameover'");
56 echo " $GameN </p>\n";
58 echo "<p>The contra party wins in ";
59 $result = DB_query("SELECT COUNT(*) from Score".
60 " WHERE score='againstqueens'");
61 while( $r = DB_fetch_array($result))
65 /* longest and shortest game */
66 $r=DB_query("SELECT timediff(mod_date,create_date) ,session,id".
67 " FROM Game WHERE status='gameover'".
68 " ORDER BY time_to_sec(timediff(mod_date,create_date)) ASC LIMIT 1");
72 $short= DB_fetch_array($r);
73 $names = DB_get_all_names_by_gameid($short[2]);
74 echo "<p> The shortest game took only ".$short[0]." hours and was played by ".join(", ",$names).".<br />\n";
77 $r=DB_query("SELECT datediff(mod_date,create_date) ,session,id".
78 " FROM Game WHERE status='gameover'".
79 " ORDER BY time_to_sec(timediff(mod_date,create_date)) DESC LIMIT 1");
82 $long= DB_fetch_array($r);
83 echo "The longest game took ".$long[0]." days.</p>\n";
86 $r=DB_query("SELECT COUNT(*) as c, session, id FROM Game ".
87 " GROUP BY session ORDER BY c DESC LIMIT 1");
90 $long = DB_fetch_array($r);
91 $names = DB_get_all_names_by_gameid($long[2]);
92 echo "<p>The longest session is session ".$long[1]." with ".$long[0].
93 " games played by ".join(", ",$names).".</p>\n";
98 $result = DB_query_array_all("SELECT type,COUNT(*) as c from Game".
99 " WHERE status='gameover'".
102 array_unshift($result,array("Type","Frequency"));
103 echo output_table($result,"Game types","stats");
105 /* break up solos in types */
106 $result = DB_query_array_all("SELECT solo,COUNT(*) as c from Game".
107 " WHERE status='gameover'".
111 array_unshift($result,array("Type","Frequency"));
112 echo output_table($result,"Kind of solos","stats");
115 2 top user mit maximaler quote an solo (min 10 games)
117 top scoring game: winning players
119 game with the same cards: show 3 at random:
120 player who won, points, what kind of game
121 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
122 select id from game where randomnumbers like "blablabl%"; the % is like .* in regexp
123 select id,type,solo,status from game where id in (select id from game where randomnumbers in (select randomnumbers from game where id=27));
127 $result = DB_query_array_all("SELECT CONCAT_WS(' ',party,IFNULL(point_call,'no call')),COUNT(*) from Hand".
128 " LEFT JOIN Game on Game.id=Hand.game_id ".
129 " WHERE Game.status='gameover'".
130 " GROUP BY party,point_call");
131 array_unshift($result,array("call","Frequency"));
132 echo output_table($result,"Kind of call","stats");
136 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
137 " (SELECT COUNT(*) FROM Hand".
138 " WHERE user_id=User.id) as c".
140 " LEFT JOIN User ON User.id=user_id".
142 " ORDER BY c DESC LIMIT 5" );
143 array_unshift($result,array("Name","Reminders"));
144 echo output_table($result,"Most reminders per game","stats");
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=winner_id".
152 " WHERE score='fox'".
153 " GROUP BY winner_id".
154 " ORDER BY c DESC LIMIT 5" );
155 array_unshift($result,array("Name","Number of foxes caught"));
156 echo output_table($result,"Most caught foxes","stats");
158 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
159 " (SELECT COUNT(*) FROM Hand".
160 " WHERE user_id=User.id) as c".
162 " LEFT JOIN User ON User.id=looser_id".
163 " WHERE score='fox'".
164 " GROUP BY looser_id".
165 " ORDER BY c DESC LIMIT 5" );
166 array_unshift($result,array("Name","Number of foxes lost"));
167 echo output_table($result,"Lost foxes (most)","stats");
169 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
170 " (SELECT COUNT(*) FROM Hand".
171 " WHERE user_id=User.id) as c".
173 " LEFT JOIN User ON User.id=looser_id".
174 " WHERE score='fox'".
175 " GROUP BY looser_id".
176 " ORDER BY c ASC LIMIT 5" );
177 array_unshift($result,array("Name","Number of foxes lost"));
178 echo output_table($result,"Lost foxes (least)","stats");
180 /* which position wins the most tricks */
181 $result = DB_query_array_all("SELECT CASE winner ".
182 " WHEN 1 THEN 'left' ".
183 " WHEN 2 THEN 'top' ".
184 " WHEN 3 THEN 'right' ".
185 " WHEN 4 THEN 'bottom' END,".
186 " COUNT(*) AS c FROM Trick".
188 " HAVING LENGTH(winner)>0 ".
189 " ORDER BY winner ASC " );
190 array_unshift($result,array("Position","Number of tricks"));
191 echo output_table($result,"Tricks at the table","stats");
194 $result = DB_query_array_all("SELECT fullname as fname,".
196 " COUNT(*)/(SELECT COUNT(*) FROM Hand LEFT JOIN User ON User.id=Hand.user_id WHERE fullname=fname) as c ".
198 " LEFT JOIN Hand ON Hand.position=startplayer AND Game.id=Hand.game_id ".
199 " LEFT JOIN User ON User.id=Hand.user_id ".
200 " WHERE type='solo' AND Game.status='gameover' ".
201 " GROUP BY user_id ".
202 " ORDER BY c DESC;");
203 array_unshift($result,array("Name","Number of solos","Solos/game"));
204 echo output_table($result,"Most solos","stats");
207 /* most active games */
208 $result = DB_query_array_all("SELECT fullname, COUNT(*) as c " .
210 " LEFT JOIN User ON User.id=user_id".
211 " LEFT JOIN Game ON Game.id=game_id".
212 " WHERE Game.status IN ('pre','play')".
214 " ORDER BY c DESC LIMIT 7" );
215 array_unshift($result,array("Name","Number of active games"));
216 echo output_table($result,"Active games","stats");
218 /* response time of users*/
219 $result = DB_query_array_all("SELECT User.fullname,".
220 "IFNULL(AVG(if(P1.sequence in (2,3,4),".
221 "-timestampdiff(MINUTE,mod_date,(select mod_date from Play P2 where P1.trick_id=P2.trick_id and P2.sequence=P1.sequence-1)),NULL )),1e9) as a, ".
224 "LEFT JOIN Hand_Card ON P1.hand_card_id=Hand_Card.id ".
225 "LEFT JOIN Hand ON Hand.id=Hand_Card.hand_id ".
226 "LEFT JOIN User ON Hand.user_id=User.id ".
230 array_unshift($result,array("Name","Average minutes before response","trick count"));
231 echo output_table($result,"Response","stats");
234 does the party win more often if they start
236 echo "<p>The party playing first wins in";
237 $result = mysql_query("SELECT COUNT(*) from Score".
238 " LEFT JOIN Game ON Game.id=game_id".
239 " WHERE score='againstqueens'".
240 " AND Game.status='gameover'".
241 " AND Game.type<>'solo'");
242 while( $r = mysql_fetch_array($result,MYSQL_NUM))
243 echo $r[1]." (".$r[0].") <br />\n";
246 $result = generate_global_score_table();
247 array_unshift($result,array("Name","Average score per game","Total Points","Number of games"));
248 echo output_table($result,"Points per game (need more than 10 games)","stats","ScoreTable");
251 * how often is the last trick a non-trump trick
254 /* needs this so that all tables are within the div and don't float around */
255 echo "<p style=\"clear:both;\"> </p>\n";
257 echo "</div>\n"; /* end output */
259 /* write file to cache */
260 $content = ob_get_contents();
262 createCache($content,"cache/stats.html");