<?
@header('Content-Type: text/html; charset=utf-8');
?>
<html><body link=#555555 vlink=#444444>
This list contains information about skilled players' team selection.<br />
Good players playing on the same side in certain maps makes the maps unbalanced.<br />
Negative team ratio indicates clear team selection based on the general map balance.<br />
<br />

<?

$roundsthreshold 
250// After this many rounds map's stats are included in any case

// Connecting, selecting database
$link mysql_connect('localhost''USER''PASSWORD')
   or die(
'Could not connect: ' mysql_error());
mysql_select_db('USER') or die('Could not select database');



$query "SELECT mapdata.ctwon / (mapdata.ctwon + mapdata.terroristwon) as mapctratio, mapdata.terroristwon / (mapdata.ctwon + mapdata.terroristwon) as maptratio, ROUND(mapdata.rounds / maxrounds, 2) AS prcnt, 

 mapdef.name AS mapname, SKILLED.name,
 SUM(stats.ctwon + stats.ctlost) AS ctrounds,
 SUM(stats.terroristwon + stats.terroristlost) AS terroristrounds,
 SUM(stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost) AS sumrounds,
 SUM((stats.ctwon + stats.ctlost)) / SUM(( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost )) AS plrmap_ctratio,
 SUM((stats.terroristwon + stats.terroristlost)) / SUM(( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost )) AS plrmap_tratio, SKILLED.ctratio AS plroverall_ctratio,
 SKILLED.tratio AS plroverall_tratio,
 SUM(ABS(mapdata.ctwon / (mapdata.ctwon + mapdata.terroristwon) - (mapdata.terroristwon / (mapdata.ctwon + mapdata.terroristwon))) * IF(mapdata.ctwon / (mapdata.ctwon + mapdata.terroristwon) > mapdata.terroristwon / (mapdata.ctwon + mapdata.terroristwon), (stats.terroristwon + stats.terroristlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ) - (stats.ctwon + stats.ctlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ), (stats.ctwon + stats.ctlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ) - (stats.terroristwon + stats.terroristlost) / ( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ))) AS teamratio FROM 

`SKILLED_PLAYERS` AS SKILLED, 
pstats_c_plrmaps_halflife_cstrike AS stats, 
( SELECT SKILLED.plrid, AVG( stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost ) AS avg FROM pstats_c_plrmaps_halflife_cstrike AS stats, SKILLED_PLAYERS AS SKILLED WHERE SKILLED.plrid = stats.plrid GROUP BY SKILLED.plrid ) AS rounds,
pstats_c_gamemaps_halflife_cstrike AS mapdata, pstats_defs_maps AS mapdef, ( SELECT SUM(rounds) as maxrounds FROM pstats_c_gamemaps_halflife_cstrike ) AS maxrounds WHERE

(stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost > rounds.avg - 0.3*rounds.avg OR
 stats.ctwon + stats.ctlost + stats.terroristwon + stats.terroristlost > $roundsthreshold) AND
stats.mapid = mapdef.id AND
mapdata.mapid = mapdef.id AND
stats.plrid = SKILLED.plrid AND
rounds.plrid = SKILLED.plrid

GROUP BY SKILLED.plrid

HAVING
sumrounds > 0

ORDER BY teamratio"
;


// Performing SQL query
$result mysql_query($query) or die('Query failed: ' mysql_error());

echo 
"<table cellspacing=0>";
echo 
"<tr><th>Player</th><th>Teamratio</th></tr>\n";    

// Printing results in HTML
while ($row mysql_fetch_array($resultMYSQL_ASSOC)) {
/*
    if ($row[teamratio]*100 <= -40)
       echo "<tr bgcolor=#FF7777>";
    elseif ($row[teamratio]*100 <= -30)
       echo "<tr bgcolor=#EE8888>";
    elseif ($row[teamratio]*100 <= -20)
       echo "<tr bgcolor=#EEAAAA>";
    elseif ($row[teamratio]*100 <= -10)
       echo "<tr bgcolor=#EECCBB>";
    elseif ($row[teamratio]*100 <= 0)
       echo "<tr bgcolor=#CCCCBB>";
    elseif ($row[teamratio]*100 <= 10)
       echo "<tr bgcolor=#CCEEBB>";
    elseif ($row[teamratio]*100 <= 20)
       echo "<tr bgcolor=#BBEEAA>";
    elseif ($row[teamratio]*100 <= 30)
       echo "<tr bgcolor=#AAEEAA>";
    elseif ($row[teamratio]*100 <= 400)
       echo "<tr bgcolor=#99FF99>";
*/
// Having only few groups is better //
    
if ($row[teamratio]*100 <= -30)
       echo 
"<tr bgcolor=#FF7777>";
    elseif (
$row[teamratio]*100 <= -10)
       echo 
"<tr bgcolor=#EE8888>";
    elseif (
$row[teamratio]*100 <= 10)
       echo 
"<tr bgcolor=#DDCCBB>";
    elseif (
$row[teamratio]*100 <= 30)
       echo 
"<tr bgcolor=#CCEEBB>";
    elseif (
$row[teamratio]*100 <= 300)
       echo 
"<tr bgcolor=#AAEEAA>";
    else
       echo 
"<tr>";


    if (
$players[$row[name]])
       echo 
"<td><a href=\"teamratio-player.php?player=$row[name]\"><b>$row[name]</b></a></td><td><b>".round($row[teamratio]*100)."</b></td>";
    else
       echo 
"<td><a href=\"teamratio-player.php?player=$row[name]\">$row[name]</a></td><td>".round($row[teamratio]*100)."</td>";
    echo 
"</tr>\n";
}

echo 
"</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($link);


?>
<br />
<small>Players lose points for playing in usually winning team and gain points for playing in usually losing team.<br />
Teamratio changes faster on maps which are not statistically even. 
Statistically even maps do not affect teamratio very much.</small><br />
<br />
<small><?= date("Y-m-d H:i:s"?></small>
</body></html>