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);
15 $PREF = DB_get_PREF($myid);
17 DB_update_user_timestamp($myid);
19 display_user_menu($myid);
21 /* check if cached version exist */
22 if( !$content = getCache("cache/stats.html",60*60*24) )
28 echo "<div class=\"user wide\">\n";
30 echo "<p>Generated ".date("Y-m-d H:i:s")." (server time) </p>";
32 /* total number of games */
33 echo "<p>The number of finished games on this server is: ";
34 $r = DB_query_array("SELECT COUNT(*) from Game".
35 " WHERE status='gameover'");
37 echo " $GameN </p>\n";
39 echo "<p>The contra party wins in ";
40 $result = DB_query("SELECT COUNT(*) from Score".
41 " LEFT JOIN Game ON Game.id=game_id".
42 " WHERE score='againstqueens'".
43 " AND Game.status='gameover'");
44 while( $r = DB_fetch_array($result))
48 /* longest and shortest game */
49 $r=DB_query("SELECT timediff(mod_date,create_date) ,session,id".
50 " FROM Game WHERE status='gameover'".
51 " ORDER BY time_to_sec(timediff(mod_date,create_date)) ASC LIMIT 1");
55 $short= DB_fetch_array($r);
56 $names = DB_get_all_names_by_gameid($short[2]);
57 echo "<p> The shortest game took only ".$short[0]." hours and was played by ".join(", ",$names).".<br />\n";
60 $r=DB_query("SELECT datediff(mod_date,create_date) ,session,id".
61 " FROM Game WHERE status='gameover'".
62 " ORDER BY time_to_sec(timediff(mod_date,create_date)) DESC LIMIT 1");
65 $long= DB_fetch_array($r);
66 echo "The longest game took ".$long[0]." days.</p>\n";
69 $r=DB_query("SELECT COUNT(*) as c, session, id FROM Game ".
70 " GROUP BY session ORDER BY c DESC LIMIT 1");
73 $long = DB_fetch_array($r);
74 $names = DB_get_all_names_by_gameid($long[2]);
75 echo "<p>The longest session is session ".$long[1]." with ".$long[0].
76 " games played by ".join(", ",$names).".</p>\n";
81 $result = DB_query_array_all("SELECT type,COUNT(*) as c from Game".
82 " WHERE status='gameover'".
85 array_unshift($result,array("Type","Frequency"));
86 echo output_table($result,"Game types","stats");
88 /* break up solos in types */
89 $result = DB_query_array_all("SELECT solo,COUNT(*) as c from Game".
90 " WHERE status='gameover'".
94 array_unshift($result,array("Type","Frequency"));
95 echo output_table($result,"Kind of solos","stats");
98 2 top user mit maximaler quote an solo (min 10 games)
100 top scoring game: winning players
102 game with the same cards: show 3 at random:
103 player who won, points, what kind of game
104 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
105 select id from game where randomnumbers like "blablabl%"; the % is like .* in regexp
106 select id,type,solo,status from game where id in (select id from game where randomnumbers in (select randomnumbers from game where id=27));
110 $result = DB_query_array_all("SELECT CONCAT_WS(' ',party,IFNULL(point_call,'no call')),COUNT(*) from Hand".
111 " LEFT JOIN Game on Game.id=Hand.game_id ".
112 " WHERE Game.status='gameover'".
113 " GROUP BY party,point_call");
114 array_unshift($result,array("call","Frequency"));
115 echo output_table($result,"Kind of call","stats");
119 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
120 " (SELECT COUNT(*) FROM Hand".
121 " WHERE user_id=User.id) as c".
123 " LEFT JOIN User ON User.id=user_id".
125 " ORDER BY c DESC LIMIT 5" );
126 array_unshift($result,array("Name","Reminders"));
127 echo output_table($result,"Most reminders per game","stats");
130 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
131 " (SELECT COUNT(*) FROM Hand".
132 " WHERE user_id=User.id) as c".
134 " LEFT JOIN User ON User.id=winner_id".
135 " WHERE score='fox'".
136 " GROUP BY winner_id".
137 " ORDER BY c DESC LIMIT 5" );
138 array_unshift($result,array("Name","Number of foxes caught"));
139 echo output_table($result,"Most caught foxes","stats");
141 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
142 " (SELECT COUNT(*) FROM Hand".
143 " WHERE user_id=User.id) as c".
145 " LEFT JOIN User ON User.id=looser_id".
146 " WHERE score='fox'".
147 " GROUP BY looser_id".
148 " ORDER BY c DESC LIMIT 5" );
149 array_unshift($result,array("Name","Number of foxes lost"));
150 echo output_table($result,"Lost foxes (most)","stats");
152 $result = DB_query_array_all("SELECT fullname, COUNT(*) /" .
153 " (SELECT COUNT(*) FROM Hand".
154 " WHERE user_id=User.id) as c".
156 " LEFT JOIN User ON User.id=looser_id".
157 " WHERE score='fox'".
158 " GROUP BY looser_id".
159 " ORDER BY c ASC LIMIT 5" );
160 array_unshift($result,array("Name","Number of foxes lost"));
161 echo output_table($result,"Lost foxes (least)","stats");
163 /* which position wins the most tricks */
164 $result = DB_query_array_all("SELECT CASE winner ".
165 " WHEN 1 THEN 'left' ".
166 " WHEN 2 THEN 'top' ".
167 " WHEN 3 THEN 'right' ".
168 " WHEN 4 THEN 'bottom' END,".
169 " COUNT(*) AS c FROM Trick".
171 " HAVING LENGTH(winner)>0 ".
172 " ORDER BY winner ASC " );
173 array_unshift($result,array("Position","Number of tricks"));
174 echo output_table($result,"Tricks at the table","stats");
177 $result = DB_query_array_all("SELECT fullname, COUNT(*) as c " .
179 " LEFT JOIN User ON User.id=user_id".
181 " ORDER BY c DESC LIMIT 7" );
182 array_unshift($result,array("Name","Number of games"));
183 echo output_table($result,"Most games","stats");
186 $result = DB_query_array_all("SELECT fullname as fname,".
188 " COUNT(*)/(SELECT COUNT(*) FROM Hand LEFT JOIN User ON User.id=Hand.user_id WHERE fullname=fname) as c ".
190 " LEFT JOIN Hand ON Hand.position=startplayer AND Game.id=Hand.game_id ".
191 " LEFT JOIN User ON User.id=Hand.user_id ".
192 " WHERE type='solo' AND Game.status='gameover' ".
193 " GROUP BY user_id ".
194 " ORDER BY c DESC;");
195 array_unshift($result,array("Name","Number of solos","Solos/game"));
196 echo output_table($result,"Most solos","stats");
199 /* most active games */
200 $result = DB_query_array_all("SELECT fullname, COUNT(*) as c " .
202 " LEFT JOIN User ON User.id=user_id".
203 " LEFT JOIN Game ON Game.id=game_id".
204 " WHERE Game.status<>'gameover'".
206 " ORDER BY c DESC LIMIT 7" );
207 array_unshift($result,array("Name","Number of active games"));
208 echo output_table($result,"Active games","stats");
210 /* response time of users*/
211 $result = DB_query_array_all("SELECT User.fullname,".
212 "IFNULL(AVG(if(P1.sequence in (2,3,4),".
213 "-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, ".
216 "LEFT JOIN Hand_Card ON P1.hand_card_id=Hand_Card.id ".
217 "LEFT JOIN Hand ON Hand.id=Hand_Card.hand_id ".
218 "LEFT JOIN User ON Hand.user_id=User.id ".
222 array_unshift($result,array("Name","Average minutes before response","trick count"));
223 echo output_table($result,"Response","stats");
226 does the party win more often if they start
228 echo "<p>The party playing first wins in";
229 $result = mysql_query("SELECT COUNT(*) from Score".
230 " LEFT JOIN Game ON Game.id=game_id".
231 " WHERE score='againstqueens'".
232 " AND Game.status='gameover'".
233 " AND Game.type<>'solo'");
234 while( $r = mysql_fetch_array($result,MYSQL_NUM))
235 echo $r[1]." (".$r[0].") <br />\n";
238 $result = generate_global_score_table();
239 array_unshift($result,array("Name","Average score per game"));
240 echo output_table($result,"Points per game","stats");
243 how often is the last trick a non-trump trick
246 /* needs this so that all tables are within the div and don't float around */
247 echo "<p style=\"clear:both;\"> </p>\n";
249 echo "</div>\n"; /* end output */
251 /* write file to cache */
252 $content = ob_get_contents();
254 createCache($content,"cache/stats.html");