t("Statistics"),
'description' => t("displays statistical information."),
'type' => MENU_NORMAL_ITEM,
'page callback' => chess_statistic_main,
'access arguments' => array('access chess module'),
'weight' => -9
);
$leaf = 'lifetime';
$items["$treename/$branch/$leaf"] = array(
'title' => t("LIFETIME ranking"),
'description' => t("displays LIFETIME ranking."),
'type' => MENU_NORMAL_ITEM,
'page callback' => chess_statistic_lifetime,
'access arguments' => array('access chess module'),
'weight' => -9
);
$leaf = 'latestseason';
$items["$treename/$branch/$leaf"] = array(
'title' => t("season ranking"),
'description' => t("displays season ranking."),
'type' => MENU_NORMAL_ITEM,
'page callback' => chess_statistic_season,
'access arguments' => array('access chess module'),
'weight' => -9
);
$leaf = 'user';
$items["$treename/$branch/$leaf/%"] = array(
'title' => t("User stats"),
'description' => t("displays user statistics."),
'type' => MENU_CALLBACK,
'page callback' => chess_statistic_user,
'page arguments' => array(3),
'access arguments' => array('access chess module'),
'weight' => -9
);
# User tab
$items["user/%/chess"] = array(
'title' => t("Chess stats"),
'description' => t("Chess stats"),
'type' => MENU_LOCAL_TASK ,
'page callback' => 'chess_statistic_user',
'page arguments' => array(1),
'access arguments' => array('access chess module'),
//'access' => true,
'weight' => 1,
);
return $items;
}
function chess_statistic_main(){
$max = 10;
$output .= "
Top $max lifetime ladder rank
";
$output .= chess_statistic_lifetime(10);
$output .= '
';
$output .= "Top $max season ladder rank
";
$output .= chess_statistic_season(10);
return $output;
}
function chess_statistic_user($playerID=null) {
if(!$_CONFIG)
require('config.php');
global $user;
if($playerID == null)
if(isset($argv[0]))
$playerID = $argv[0];
else {
$playerID = $user->uid;
}
//kj changes - for some reason the above check doesnt work for displaying user info
if($playerID == 0){
global $user;
$playerID = $user->uid;
}
$userName = db_result(db_query("SELECT name FROM ". $CFG_TABLE[players] ." WHERE uid=$playerID"));
if(!$userName) {
exit();
}
$objStat = db_fetch_object(db_query("select * from ". $CFG_TABLE[statistics] ." where uid=$playerID"));
// determine level
switch ($objStat->lifetime_ladder_rating)
{
case $objStat->lifetime_ladder_rating < 901:
$curLevel=1;
break;
case $objStat->lifetime_ladder_rating < 976:
$curLevel=2;
break;
case $objStat->lifetime_ladder_rating < 1026:
$curLevel=3;
break;
case $objStat->lifetime_ladder_rating < 1101:
$curLevel=4;
break;
case $objStat->lifetime_ladder_rating < 1176:
$curLevel=5;
break;
case $objStat->lifetime_ladder_rating < 1226:
$curLevel=6;
break;
case $objStat->lifetime_ladder_rating > 1226:
$curLevel=7;
break;
default:
$curLevel=3;
break;
}
// Add ties only as half
$total_ended_games = ($objStat->career_W + $objStat->career_L + $objStat->autowins_involved);
$total_ended_games += (0.5*$objStat->career_T);
drupal_set_title("$userName stats");
if($playerID != $user->uid) {
$output .= '';
}
$output .= '';
// Highlights / trophies
$output .= '';
$output .= '';
$output .= 'Highlights: ';
$output .= ' | ';
$output .= '';
if($objStat->stats_comment=="") {
// no stats yet
$output .= 'none yet';
} else {
// show stats comment
for ($i = 0; $i < $objStat->championships; $i++)
{
$output .= ' ';
}
}
$output .= ' | ';
$output .= '
';
// Ladder points
$output .= '';
$output .= '| ';
$output .= 'Ladder points:';
$output .= ' | ';
$output .= '';
$output .= 'Lifetime: '. $objStat->lifetime_ladder_rating .' ';
$output .= 'Season: '. $objStat->ladder_rating .'';
$output .= ' | ';
$output .= '
';
// Career statistics
$output .= '';
$output .= '| ';
$output .= 'Career statistics:';
$output .= ' | ';
$output .= '';
$output .= 'Games Completed '. $total_ended_games .' ';
$output .= '(Wins, Losses, Draws, and AutoWins. Draws count as .5 of a win ) ';
$output .= "|
|
| Win | Loss | Tie | Win Pct |
| Career | {$objStat->career_W} | {$objStat->career_L} | {$objStat->career_T} | ";
$output .= sprintf("%1.2f", $objStat->career_W_pct) . '% | ';
$output .= ' ';
$output .= "| As White |
{$objStat->white_W} |
{$objStat->white_L} |
{$objStat->white_T} |
";
$output .= sprintf("%1.2f", $objStat->white_W_pct) . '% | ';
$output .= ' ';
$output .= "| As White |
{$objStat->black_W} |
{$objStat->black_L} |
{$objStat->black_T} |
";
$output .= sprintf("%1.2f", $objStat->black_W_pct) . '% | ';
$output .= "
| TRUE))
. drupal_get_path('module', 'chess') . '/images/blank.gif'
."' width='50' height='20'> |
";
$output .= "View {$userName}'s Games:";
// List game links
$output .= " ". l(t('ONGOING'), url('chess/listgames', array('absolute' => TRUE)) . "/{$playerID}/ongoing") .
" ". l(t('ENDED'), url('chess/listgames', array('absolute' => TRUE)) . "/{$playerID}/ended") .
" ". l(t('INVITES'), url('chess/listgames', array('absolute' => TRUE)) . "/{$playerID}/invites") .
//" ". l(t('ALL'), url('chess/listgames', array('absolute' => TRUE)) . "/{$playerID}") .
" |
GAMES RESULTING IN AUTOWIN: {$objStat->autowins_involved}
player either ruled winner or loser by admin, or by time expiring
| White | Black |
";
$output .= "
| W/L: |
{$objStat->W_AutoWins} / {$objStat->W_AutoLosses}
|
{$objStat->B_AutoWins} / {$objStat->B_AutoLosses}
|
|
INVITES DECLINED:
|
|
| as White | as Black |
| Player | {$objStat->white_invite_declined} | {$objStat->black_invite_declined} |
| Opponent | {$objStat->white_opp_invite_declined} | {$objStat->black_invite_declined} |
";
$output .= "
| REQUESTS: |
| since Mar 1 11:37:19 EST 2005 |
| Undo | Draw |
| {$objStat->undo_requests} | {$objStat->draw_requests} |
";
$output .= ' | ';
$output .= '';
$output .= '';
return $output;
}
function chess_statistic_lifetime($count=100) {
global $CFG_TABLE;
if(!$_CONFIG)
require('config.php');
$season_table = $CFG_TABLE['statistics'];
if(!isset($count)) $count=10;
if(!isset($minwins)) $minwins=15;
if(!isset($lifetimeminrating)) $lifetimeminrating=900;
if(!isset($minrating)) $minrating=1000;
$header = array(
array('data' => t('Rank'), 'field' => 'rank'),
array('data' => t('Player'), 'field' => 'current_nick',),
array('data' => t('Rating'), 'field' => 'lifetime_ladder_rating', 'sort' => 'desc', ),
);
db_query("SET @ROW=0");
$sql = "
SELECT * FROM (
SELECT
@ROW:=@ROW+1 as rank,
uid,
current_nick,
lifetime_ladder_rating
FROM
$season_table
WHERE
lifetime_ladder_rating > $lifetimeminrating
AND
career_W >= $minwins
ORDER BY lifetime_ladder_rating DESC
LIMIT $count
) as List
";
$tablesort = tablesort_sql($header);
$result = db_query($sql . $tablesort);
while ($items = db_fetch_object($result)) {
$rows[] = array('data' =>
array(
t($items->rank),
l(t($items->current_nick), 'user/'. $items->uid . '/chess', array(), NULL, NULL, FALSE, TRUE),
t($items->lifetime_ladder_rating),
),
);
}
$output .= theme('table', $header, $rows);
//$output .= theme('pager', NULL, 50, 0);
return $output;
}
function chess_statistic_season($count=100) {
global $CFG_TABLE;
if(!$_CONFIG)
require('config.php');
$season_table = $CFG_TABLE['statistics'];
if(!isset($count)) $count=10;
if(!isset($minwins)) $minwins=15;
if(!isset($lifetimeminrating)) $lifetimeminrating=900;
if(!isset($minrating)) $minrating=900;
$object = db_fetch_object(db_query("select date, comments from ". $CFG_TABLE[tbl_updates] ." where app='ladder'"));
$lastupdate = $object->date;
$seasonname = $object-comments;
$startdate = db_result(db_query("select date from ". $CFG_TABLE[tbl_updates] ." where app='ladder start date'"));
###
$header = array(
array('data' => t('Rank'), 'field' => 'rank'),
array('data' => t('Player'), 'field' => 'current_nick',),
array('data' => t('Rating'), 'field' => 'ladder_rating', 'sort' => 'desc'),
);
db_query("SET @ROW:=0");
$sql = "
SELECT * FROM (
SELECT
@ROW:=@ROW+1 as rank,
uid,
current_nick,
ladder_rating
FROM
$season_table
WHERE
ladder_rating > $minrating
AND
ladder_rating <> 1000
ORDER BY ladder_rating DESC
LIMIT $count
) AS List
";
$tablesort = tablesort_sql($header);
$result = db_query($sql . $tablesort);
$i=0;
while ($items = db_fetch_object($result)) {
$rows[] = array('data' =>
array(
t($items->rank),
l(t($items->current_nick), 'chess/statistics/user/'. $items->uid, array(), NULL, NULL, FALSE, TRUE),
t($items->ladder_rating),
),
);
}
$output .= theme('table', $header, $rows);
//$output .= theme('pager', NULL, 50, 0);
return $output;
}