X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=e-DoKo.git;a=blobdiff_plain;f=include%2Ffunctions.php;h=1f8f2ccf1d0c7c4c5c54b41e675a29088596ae08;hp=991d53d1889abc50bc06a1022fa3564a8cbed38c;hb=aeb9ef98850e762291bc6a1d39b31d1ac4db4817;hpb=09515348107d9aab7823a12d31b082a2ebb75555
diff --git a/include/functions.php b/include/functions.php
index 991d53d..1f8f2cc 100644
--- a/include/functions.php
+++ b/include/functions.php
@@ -1,5 +1,24 @@
+ *
+ * This file is part of e-DoKo.
+ *
+ * e-DoKo is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * e-DoKo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with e-DoKo. If not, see
".substr($r[1],0,2)." | \n"; - } - $output.="P | \n||||||||||
".$player[$key]['points']." | \n"; +function generate_global_score_table() +{ + $return = array(); + + /* get all ids, scores and gametypes */ + $gameids = DB_get_gameids_of_finished_games_by_session(0); + + if($gameids == NULL) + return ''; + + $player = array(); + /* get player id, names... from the User table */ + $result = DB_query('SELECT User.id, User.fullname FROM User'); + + /* save information in an array */ + while( $r = DB_fetch_array($result)) + $player[$r[0]] = array('name'=> $r[1], 'points' => 0 , 'nr' => 0, 'active' => 0, + 'response' => 0 , 'solo' => 0, 'soloavg' => 0); + + /* get points and generate table */ + foreach($gameids as $gameid) + { + $re_score = $gameid[1]; + $gametype = $gameid[2]; + + /* get players involved in this game */ + $result = DB_query('SELECT user_id FROM Hand WHERE game_id='.DB_quote_smart($gameid[0])); + while($r = DB_fetch_array($result)) + { + $id = $r[0]; + $party = DB_get_party_by_gameid_and_userid($gameid[0],$id); + if($party == 're') + if($gametype=='solo') + $player[$id]['points'] += 3*$re_score; + else + $player[$id]['points'] += $re_score; + else if ($party == 'contra') + $player[$id]['points'] -= $re_score; + if($party) + $player[$id]['nr']+=1; } - $output.="".abs($re_score);
+ }
+
+ /* add number of active games */
+ $result = DB_query_array_all("SELECT user_id, COUNT(*) as c " .
+ " FROM Hand".
+ " LEFT JOIN Game ON Game.id=game_id".
+ " WHERE Game.status IN ('pre','play')".
+ " GROUP BY user_id");
+
+ foreach($result as $res)
+ {
+ $player[$res[0]]['active'] = $res[1];
+ }
+
+ /* response time of users*/
+ $result = DB_query_array_all("SELECT user_id,".
+ "IFNULL(AVG(if(P1.sequence in (2,3,4),".
+ "-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 ".
+ "FROM Play P1 ".
+ "LEFT JOIN Hand_Card ON P1.hand_card_id=Hand_Card.id ".
+ "LEFT JOIN Hand ON Hand.id=Hand_Card.hand_id ".
+ "GROUP BY user_id ");
+
+ foreach($result as $res)
+ {
+ $player[$res[0]]['response'] = $res[1];
+ }
+
+ /* most solos */
+ $result = DB_query_array_all("SELECT user_id as uid,".
+ " COUNT(*), ".
+ " COUNT(*)/(SELECT COUNT(*) FROM Hand LEFT JOIN User ON User.id=Hand.user_id WHERE User.id=uid) as c ".
+ " FROM Game ".
+ " LEFT JOIN Hand ON Hand.position=startplayer AND Game.id=Hand.game_id ".
+ " WHERE type='solo' AND Game.status='gameover' ".
+ " GROUP BY user_id ");
+
+ foreach($result as $res)
+ {
+ $player[$res[0]]['solo'] = $res[1];
+ $player[$res[0]]['soloavg'] = $res[2];
+ }
+
+
+ /* sort everything nicely */
+
+ 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)
+ {
+ /* limit to players with at least 10 games */
+ if($pl['nr']>10)
+ $return[] = array( $pl['name'], round($pl['points']/$pl['nr'],3), $pl['points'],$pl['nr'],$pl['active'],
+ $pl['response'],$pl['solo'],$pl['soloavg']);
+ }
+
+ return $return;
+}
+
+function format_score_table_ascii($score)
+{
+ $output="";
+ if(sizeof($score)==0)
+ return "";
+
+ /* truncate table if we have too many games */
+ $max = sizeof($score);
+ if($max>6) $output.=" (table truncated to last 6 games)\n";
+
+ /* output header */
+ foreach($score[0]['players'] as $id=>$points)
+ {
+ $name = DB_get_name('userid',$id); /*TODO*/
+ $output.= " ".substr($name,0,2)." |";
+ }
+ $output.=" P |\n";
+ $output.= "------+------+------+------+------+\n";
+
+ /* output score for each game */
+ $i=0;
+ foreach($score as $game)
+ {
+ $i++;
+ if($i-1<$max-6) continue;
+
+ foreach($game['players'] as $id=>$points)
+ $output.=str_pad($points,6," ",STR_PAD_LEFT)."|";
+ $output.=str_pad($game['points'],4," ",STR_PAD_LEFT);
+
+ /* check for solo */
+ if($game['solo'])
+ $output.= " S|";
+ else
+ $output.= " |";
+
+ $output.="\n";
+ }
+ return $output;
+}
+
+function format_score_table_html($score,$userid)
+{
+ global $INDEX;
+
+ if(sizeof($score)==0)
+ return "";
+
+ $output = " \n \n";
+ $output.=$header;
+ if($i>12)
+ $output.=$footer;
+ $output.=$body;
+
+ $output.=" \n
|