<?php
$link = mysql_connect(‘localhost’, ‘debugper_gostats’, ‘sttsg864@!’, true);
if (!$link) {
die("Could not connect: " . mysql_error());
}
$db_selected = mysql_select_db(‘debugper_sagostats’, $link);
if (!$db_selected) {
die ("Can’t use go : " . mysql_error());
}
//Declare the primary array
$statistics = array();
$HISTORYDAYS = "365";
$months = "Twelve";
//white figures
$result = mysql_query("SELECT EffectiveHandicap, count(points) as GameCount, avg(points) as PointsAverage FROM gostats_history where effectivehandicap=abs(normalizedrank-opponentnormalizedrank) and weight>0 and colour=’W’ group by EffectiveHandicap");
if (!$result) {
die("Invalid query: " . mysql_error());
}
while ($loop = mysql_fetch_array($result))
{
$statistic = new Statistic($loop['EffectiveHandicap']);
$statistic->WhiteGameCount = $loop['GameCount'];
$statistic->WhiteGameAveragePoints = $loop['PointsAverage'];
$statistics[$loop['EffectiveHandicap']] = $statistic;
}
//black figures
$result = mysql_query("SELECT EffectiveHandicap, count(points) as GameCount, avg(points) as PointsAverage FROM gostats_history where effectivehandicap=abs(normalizedrank-opponentnormalizedrank) and weight>0 and colour=’B’ group by EffectiveHandicap");
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
while ($loop = mysql_fetch_array($result))
{
$statistics[$loop['EffectiveHandicap']]->BlackGameCount = $loop['GameCount'];
$statistics[$loop['EffectiveHandicap']]->BlackGameAveragePoints = $loop['PointsAverage'];
}
//white wins
$result = mysql_query("SELECT EffectiveHandicap, count(points) as WinCount FROM gostats_history where effectivehandicap=abs(normalizedrank-opponentnormalizedrank) and weight>0 and colour=’W’ and result = ‘W’ group by EffectiveHandicap");
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
while ($loop = mysql_fetch_array($result))
{
$statistics[$loop['EffectiveHandicap']]->WhiteGameWins = $loop['WinCount'];
}
//black wins
$result = mysql_query("SELECT EffectiveHandicap, count(points) as WinCount FROM gostats_history where effectivehandicap=abs(normalizedrank-opponentnormalizedrank) and weight>0 and colour=’B’ and result = ‘W’ group by EffectiveHandicap");
if (!$result) {
die(‘Invalid query: ‘ . mysql_error());
}
while ($loop = mysql_fetch_array($result))
{
$statistics[$loop['EffectiveHandicap']]->BlackGameWins = $loop['WinCount'];
}
echo "<p><b>Handicapping Analysis for all Rated Correctly Handicapped Games</b>";
echo "<p><table border>";
echo "<tr><th>Handicap</th><th>Black Game Count</th><th>Black Win Ratio</th><th>Black Average Points</th><th>White Game Count</th><th>White Win Ratio</th><th>White Average Points</th></tr>";
$i=0;
while ($i < count($statistics)) {
echo "<tr><td>";
echo $i;
echo "</td><td>";
echo $statistics[$i]->BlackGameCount;
echo "</td><td>";
if($statistics[$i]->BlackGameCount==0)
{
echo "0";
}
else
{
echo number_format($statistics[$i]->BlackGameWins/$statistics[$i]->BlackGameCount*100, 1);
}
echo "%";
echo "</td><td>";
echo number_format($statistics[$i]->BlackGameAveragePoints, 1);
echo "</td><td>";
echo $statistics[$i]->WhiteGameCount;
echo "</td><td>";
if($statistics[$i]->WhiteGameCount==0)
{
echo "0";
}
else
{
echo number_format($statistics[$i]->WhiteGameWins/$statistics[$i]->WhiteGameCount*100, 1);
}
echo "%";
echo "</td><td>";
echo number_format($statistics[$i]->WhiteGameAveragePoints, 1);
echo "</td></tr>";
$i++;
}
echo "</table>";
mysql_close($link);
//Helper Functions
function direction($x)
{
if ($x==’ASC’)
return 1;
else
return -1;
}
function compare($x, $y)
{
global $SORTITEM;
global $DIRECTION;
if ($SORTITEM == ‘AllGamesCount’)
{
if ( $x->AllGamesCount == $y->AllGamesCount )
return 0;
else if ( $x->AllGamesCount < $y->AllGamesCount )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘RankChange’)
{
if ( $x->RankChange == $y->RankChange )
{
if ($x->PreviousRank == $y->PreviousRank)
return 0;
else if ($x->PreviousRank > $y->PreviousRank)
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ( $x->RankChange < $y->RankChange )
return 1;
else
return -1;
}
else if ($SORTITEM == ‘NetIndexPointsAverage’)
{
if ( $x->NetIndexPointsAverage == $y->NetIndexPointsAverage )
return 0;
else if ( $x->NetIndexPointsAverage < $y->NetIndexPointsAverage )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘NormalizedNetIndexPointsAverage’)
{
if ( $x->NormalizedNetIndexPointsAverage == $y->NormalizedNetIndexPointsAverage)
return 0;
else if ( $x->NormalizedNetIndexPointsAverage < $y->NormalizedNetIndexPointsAverage)
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘RatedWinRatio’)
{
if ( $x->RatedWinRatio == $y->RatedWinRatio )
return 0;
else if ( $x->RatedWinRatio < $y->RatedWinRatio )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘TournamentWinRatio’)
{
if ( $x->TournamentWinRatio == $y->TournamentWinRatio )
return 0;
else if ( $x->TournamentWinRatio < $y->TournamentWinRatio )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘Teacher’)
{
if ( $x->WhitePlayRatio == $y->WhitePlayRatio )
return 0;
else if ( $x->WhitePlayRatio < $y->WhitePlayRatio )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘Sponger’)
{
if ( $x->BlackPlayRatio == $y->BlackPlayRatio )
return 0;
else if ( $x->BlackPlayRatio < $y->BlackPlayRatio )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘BlackWinRatio’)
{
if ( $x->RatedBlackWinRatio == $y->RatedBlackWinRatio )
return 0;
else if ( $x->RatedBlackWinRatio < $y->RatedBlackWinRatio )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘WhiteWinRatio’)
{
if ( $x->RatedWhiteWinRatio == $y->RatedWhiteWinRatio )
return 0;
else if ( $x->RatedWhiteWinRatio < $y->RatedWhiteWinRatio )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘LongestWinningStreak’)
{
if ( $x->LongestWinningStreak == $y->LongestWinningStreak )
return 0;
else if ( $x->LongestWinningStreak < $y->LongestWinningStreak )
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘CurrentWinningStreak’)
{
if ( $x->CurrentWinningStreak== $y->CurrentWinningStreak)
return 0;
else if ( $x->CurrentWinningStreak< $y->CurrentWinningStreak)
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘CurrentLosingStreak’)
{
if ( $x->CurrentLosingStreak== $y->CurrentLosingStreak)
return 0;
else if ( $x->CurrentLosingStreak< $y->CurrentLosingStreak)
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
else if ($SORTITEM == ‘LongestLosingStreak’)
{
if ( $x->LongestLosingStreak== $y->LongestLosingStreak)
return 0;
else if ( $x->LongestLosingStreak< $y->LongestLosingStreak)
return 1 * direction($DIRECTION);
else
return -1 * direction($DIRECTION);
}
}
//The Statistic class
class Statistic
{
var $Handicap;
var $WhiteGameCount;
var $WhiteGameAveragePoints;
var $WhiteGameWins;
var $BlackGameCount;
var $BlackGameAveragePoints;
var $BlackGameWins;
function Statistic($Handicap)
{
$this->Handicap = $Handicap;
$this->WhiteGameCount =0;
$this->WhiteGameAveragePoints=0;
$this->WhiteGameWins=0;
$this->BlackGameCount=0;
$this->BlackGameAveragePoints=0;
$this->BlackGameWins=0;
}
}
?>
Posted by Chris Welsh as at 11:32 PM, No Comments »
Recent Comments