<?
//change: add player_exclude_list support and some additional fields for some queries
//change: add some awards
global $awardset, $player_exclude_list;

if (count($player_exclude_list)) {
    $excluded_players = "(".implode(",", $player_exclude_list).")";
} else {
    $excluded_players = false;
}

$awardset['avg_games']['sql'][0]    = "select AVG(games) / 2
                                       from {$tp}playerprofile
                                       ".($excluded_players ? "where playerID not in {$excluded_players}" : "")."
                                    ";

                         $avg_games="({\$awardset['avg_games']['sql'][0][0]}-1)";
//------------------------------------------------ added
$awardset['TAG_Thaw']['name']                      = 'Best Thawer';
$awardset['TAG_Thaw']['image']                     = 'TAG_thaw';
$awardset['TAG_Thaw']['category']                  = 'Freeze Tag';
$awardset['TAG_Thaw']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as thaws,
                                                            {$tp}playerprofile.games as games,
                                                            round(sum(eventValue)/games,2) as ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where eventName='THAW'
                                                             and games>$avg_games
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."

                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY ratio DESC
                                                    ";

//------------------------------------------------
$awardset['CTF_Assist']['name']                      = 'Best Supporter';
$awardset['CTF_Assist']['image']                     = 'CTF_Supporter';
$awardset['CTF_Assist']['category']                  = 'CTF';
$awardset['CTF_Assist']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Supports, 
                                                            {$tp}playerprofile.games as Games, 
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where (eventName='Defend_Carrier' OR eventName='Defend_Hurt_Carrier' OR eventName='Flag_Assist_Return' OR eventName='Flag_Assist_Frag')
                                                             and eventCategory='CTF'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."

                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";

//------------------------------------------------
$awardset['CTF_Retriever']['name']                      = 'Best Flag Retriever';
$awardset['CTF_Retriever']['image']                     = 'CTF_Retriever';
$awardset['CTF_Retriever']['category']                  = 'CTF';
$awardset['CTF_Retriever']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Retrieves,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where (eventName='Kill_Carrier' OR eventName='Flag_Return')
                                                             and eventCategory='CTF'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";


//------------------------------------------------
$awardset['CTF_Defend']['name']                      = 'Best Defender';
$awardset['CTF_Defend']['image']                     = 'CTF_Defend';
$awardset['CTF_Defend']['category']                  = 'CTF';
$awardset['CTF_Defend']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Defends,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where (eventName='Defend_Base' OR eventName='Defend_Flag')
                                                             and eventCategory='CTF'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";


//------------------------------------------------
$awardset['CTF_Flag_Capture']['name']                      = 'Best Flag Capper';
$awardset['CTF_Flag_Capture']['image']                     = 'CTF_Flag_Capture';
$awardset['CTF_Flag_Capture']['category']                  = 'CTF';
$awardset['CTF_Flag_Capture']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Captures,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where eventName='Flag_Capture' 
                                                             and eventCategory='CTF'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";

//------------------------------------------------
$awardset['item_quad']['name']                      = 'Quad Whore';
$awardset['item_quad']['image']                     = 'item_quad';
$awardset['item_quad']['category']                  = 'Item';
$awardset['item_quad']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Pickups,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where eventName='quad' 
                                                             and eventCategory='item'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";
//------------------------------------------------
$awardset['item_regen']['name']                      = 'Regen Romper';
$awardset['item_regen']['image']                     = 'item_regen';
$awardset['item_regen']['category']                  = 'Item';
$awardset['item_regen']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Pickups,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where eventName='regen' 
                                                             and eventCategory='item'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";
//------------------------------------------------
$awardset['item_haste']['name']                      = 'Haste Hog';
$awardset['item_haste']['image']                     = 'item_haste';
$awardset['item_haste']['category']                  = 'Item';
$awardset['item_haste']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Pickups,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where eventName='haste' 
                                                             and eventCategory='item'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";
//------------------------------------------------
$awardset['item_mega']['name']                      = 'Mega Slut';
$awardset['item_mega']['image']                     = 'item_mega';
$awardset['item_mega']['category']                  = 'Item';
$awardset['item_mega']['sql'][0]                    = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Pickups,
                                                            {$tp}playerprofile.games as Games,
                                                            round(sum(eventValue)/games,2) as Ratio
                                                       from {$tp}playerprofile,{$tp}eventdata1d
                                                       where eventName='health_mega' 
                                                             and eventCategory='item'
                                                             and games>$avg_games 
                                                             and {$tp}playerprofile.playerID={$tp}eventdata1d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                             
                                                       group by {$tp}eventdata1d.playerID
                                                       ORDER BY Ratio DESC
                                                    ";
//------------------------------------------------

$awardset['kr']['name']                             = 'Best Killer';
$awardset['kr']['image']                            = 'player_killer';
$awardset['kr']['category']                         = 'Player';
      
$awardset['kr']['sql'][0]                           = "select playerID, playerName, kills, games, round(kills/games,2) as Ratio from {$tp}playerprofile
                                                       where games>$avg_games
                                                             ".($excluded_players ? "and playerID not in {$excluded_players}" : "")."
                                                       ORDER BY Ratio DESC
                                                    ";
//------------------------------------------------
$awardset['ks']['name']                             = 'Highest Kill Streak';
$awardset['ks']['image']                            = 'player_killstreak';
$awardset['ks']['category']                         = 'Player';

$awardset['ks']['sql'][0]                           = "select playerID, playerName, kill_streak
                                                       from {$tp}playerprofile
                                                       ".($excluded_players ? "where playerID not in {$excluded_players}" : "")."
                                                       ORDER BY kill_streak DESC
                                                    ";
//------------------------------------------------
$awardset['eff']['name']                            = 'Best Efficiency';
$awardset['eff']['image']                           = 'player_efficiency';
$awardset['eff']['category']                        = 'Player';

$awardset['eff']['sql'][0]                          = "select playerID, playerName, kills, deaths, kills/(1+kills+deaths) as Efficiency
                                                       from {$tp}playerprofile
                                                       where games>$avg_games
                                                             ".($excluded_players ? "and playerID not in {$excluded_players}" : "")."
                                                       ORDER BY Efficiency DESC
                                                    ";
//------------------------------------------------
$awardset['killer__v_weapons']['name']                = 'Best Killer with _v_weapons';
$awardset['killer__v_weapons']['image']               = 'killer__v_weapons';
$awardset['killer__v_weapons']['category']            = 'Carnage';
 
$awardset['killer__v_weapons']['sql'][0]              = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Kills,
                                                            {$tp}playerprofile.games as Games,
                                                            round((sum(eventValue)/{$tp}playerprofile.games),2) as kill_ratio
                                                      from {$tp}eventdata2d,{$tp}playerprofile
                                                      where {$tp}playerprofile.games>$avg_games and
                                                            (eventName='_v_weapons') and
                                                            eventCategory='kill' and
                                                            {$tp}playerprofile.playerID={$tp}eventdata2d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                      group by {$tp}eventdata2d.playerID
                                                      ORDER by kill_ratio DESC
                                                   ";

/*
//------------------------------------------------
// Hall of Shame
//
$awardset['shame_suicide']['name']                = 'Suicidal Moron';
$awardset['shame_suicide']['image']               = 'shame_suicide';
$awardset['shame_suicide']['category']            = 'Shame Hall';
$awardset['shame_suicide']['sql'][0]              = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as Suicides,
                                                            {$tp}playerprofile.games as Games,
                                                            round((sum(eventValue)/{$tp}playerprofile.games),2) as Ratio
                                                      from {$tp}eventdata2d,{$tp}playerprofile
                                                      where {$tp}playerprofile.games>$avg_games and
                                                            eventCategory='suicide' and
                                                            {$tp}playerprofile.playerID={$tp}eventdata2d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                      group by {$tp}eventdata2d.playerID
                                                      ORDER BY Ratio DESC
                                                    ";

//------------------------------------------------ added
$awardset['shame_camper']['name']                = 'Cheap Ass Camper';
$awardset['shame_camper']['image']               = 'shame_camper';
$awardset['shame_camper']['category']            = 'Shame Hall';
$awardset['shame_camper']['sql'][0]              = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as `Camp Protection Suicides`,
                                                            {$tp}playerprofile.games as Games,
                                                            round((sum(eventValue)/{$tp}playerprofile.games),2) as Ratio
                                                      from {$tp}eventdata2d,{$tp}playerprofile
                                                      where {$tp}playerprofile.games>$avg_games and
                                                            eventName='CAMPER' and
                                                            eventCategory='suicide' and
                                                            {$tp}playerprofile.playerID={$tp}eventdata2d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                      group by {$tp}eventdata2d.playerID
                                                      ORDER BY Ratio DESC
                                                    ";

//------------------------------------------------ added
$awardset['shame_teamkill']['name']                = 'Team Shooting Traitor';
$awardset['shame_teamkill']['image']               = 'shame_teamkill';
$awardset['shame_teamkill']['category']            = 'Shame Hall';
$awardset['shame_teamkill']['sql'][0]              = "select {$tp}playerprofile.playerID,
                                                            {$tp}playerprofile.playerName,
                                                            sum(eventValue) as `Team Kills`,
                                                            {$tp}playerprofile.games as Games,
                                                            round((sum(eventValue)/{$tp}playerprofile.games),2) as Ratio
                                                      from {$tp}eventdata2d,{$tp}playerprofile
                                                      where {$tp}playerprofile.games>$avg_games and
                                                            eventCategory='teamkill' and
                                                            {$tp}playerprofile.playerID={$tp}eventdata2d.playerID
                                                             ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                      group by {$tp}eventdata2d.playerID
                                                      ORDER BY Ratio DESC
                                                    ";

//------------------------------------------------
$awardset['shame_death_strike']['name']            = 'Most Deaths In A Row';
$awardset['shame_death_strike']['image']           = 'shame_death_strike';
$awardset['shame_death_strike']['category']        = 'Shame Hall';

$awardset['shame_death_strike']['sql'][0]          = "select playerID, playerName, death_streak
                                                       from {$tp}playerprofile
                                                       ".($excluded_players ? "where playerID not in {$excluded_players}" : "")."
                                                       ORDER BY death_streak DESC
                                                    ";*/




//------------------------------------------------------------------
// Accuracy awards using compiled tables to make it fast - optimized process
//
$allweaps_id = md5(time()); // haha, i must be a little paranoic xD

$awardset['accuracy_set_table']['sql'][0]    = "drop table {$tp}awardsweaponshots";

$awardset['accuracy_set_table']['sql'][1]    = "CREATE TABLE {$tp}awardsweaponshots (
                                                playerID varchar(100) NOT NULL default ''
                                                ,weaponID varchar(100) NOT NULL default ''
                                                ,shots int(10) unsigned default '0'
                                                ,PRIMARY KEY  (playerID,weaponID)
                                              ) TYPE=MyISAM
                                              ";

$awardset['accuracy_set_table']['sql'][2]    = "insert into {$tp}awardsweaponshots
                                              select {$tp}playerprofile.playerID,
                                                    '{$allweaps_id}' as weaponID,
                                                    sum(eventValue) as shots
                                              from {$tp}eventdata2d,{$tp}playerprofile
                                              where {$tp}playerprofile.games>$avg_games and
                                                    eventName LIKE '%_shots' and
                                                    eventCategory='accuracy' and
                                                    {$tp}playerprofile.playerID={$tp}eventdata2d.playerID
                                                     ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                              group by {$tp}eventdata2d.playerID
                                              ";

$awardset['accuracy__v_weapons_populate_table']['sql'][0]  = "insert into {$tp}awardsweaponshots
                                                              select {$tp}playerprofile.playerID,
                                                                    '_v_weapons' as weaponID,
                                                                    sum(eventValue) as shots
                                                              from {$tp}eventdata2d,{$tp}playerprofile
                                                              where {$tp}playerprofile.games>$avg_games and
                                                                    eventName='_v_weapons_shots' and
                                                                    eventCategory='accuracy' and
                                                                    {$tp}playerprofile.playerID={$tp}eventdata2d.playerID
                                                                     ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                              group by {$tp}eventdata2d.playerID
                                                              ";


$awardset['avg_shots__v_weapons']['sql'][0]    = "select avg(shots/games+1) / 2
                                               from {$tp}awardsweaponshots
                                               where weaponID='_v_weapons'
                                               group by weaponID
                                    ";


$awardset['accuracy__v_weapons']['name']                 = 'Best Accuracy with _v_weapons';
$awardset['accuracy__v_weapons']['image']                = 'accuracy__v_weapons';
$awardset['accuracy__v_weapons']['category']             = 'Accuracy';
$awardset['accuracy__v_weapons']['sql'][0]               = "select {$tp}playerprofile.playerID,
                                                                {$tp}playerprofile.playerName,
                                                                {$tp}playerprofile.games as games,
                                                                sum(eventValue) as hits,
                                                                shots,
                                                                round(sum(eventValue)/shots*100,2) as accuracy
                                                          from {$tp}eventdata2d,{$tp}playerprofile,{$tp}awardsweaponshots
                                                          where weaponID='_v_weapons' and
                                                                eventName='_v_weapons_hits' and
                                                                eventCategory='accuracy' and
                                                                {$tp}playerprofile.playerID={$tp}eventdata2d.playerID and
                                                                {$tp}playerprofile.playerID={$tp}awardsweaponshots.playerID
                                                          group by {$tp}eventdata2d.playerID
                                                          having (shots/games+1) > ({\$awardset['avg_shots__v_weapons']['sql'][0][0]}-1)
                                                          ORDER by accuracy DESC
                                                          ";




$awardset['accuracyALLWEAPONS']['name']                 = 'Best Overall Accuracy';
$awardset['accuracyALLWEAPONS']['image']                = 'accuracy_ALLWEAPONS';
$awardset['accuracyALLWEAPONS']['category']             = 'Accuracy';
$awardset['accuracyALLWEAPONS']['sql'][0]               = "select {$tp}playerprofile.playerID,
                                                                {$tp}playerprofile.playerName,
                                                                {$tp}playerprofile.games as games,
                                                                sum(eventValue) as hits,
                                                                shots,
                                                                round(sum(eventValue)/shots*100,2) as accuracy
                                                          from {$tp}eventdata2d,{$tp}playerprofile,{$tp}awardsweaponshots
                                                          where weaponID='{$allweaps_id}' and
                                                                eventName like '%_hits' and
                                                                eventCategory='accuracy' and
                                                                {$tp}playerprofile.playerID={$tp}eventdata2d.playerID and
                                                                {$tp}playerprofile.playerID={$tp}awardsweaponshots.playerID
                                                          group by {$tp}eventdata2d.playerID
                                                          ORDER by accuracy DESC
                                                           ";

/*
//------------------------------------------------------------------
// Accuracy awards using compiled tables to make it fast - still too slow
//
$awardset['accuracy_set_table']['sql'][0]    = "drop table {$tp}awardsaccuracy";

$awardset['accuracy_set_table']['sql'][1]    = "CREATE TABLE {$tp}awardsaccuracy (
                                                playerID varchar(100) NOT NULL default ''
                                                ,playerName varchar(255) NOT NULL default ''
                                                ,weaponID varchar(100) NOT NULL default ''
                                                ,games int(10) unsigned default '0'
                                                ,hits int(10) unsigned default '0'
                                                ,shots int(10) unsigned default '0'
                                                ,accuracy float(10,2) unsigned default '0'
                                                ,PRIMARY KEY  (playerID,weaponID)
                                              ) TYPE=MyISAM                                    
                                              ";

$awardset['accuracy__v_weapons_populate_table']['sql'][0]  = "insert into {$tp}awardsaccuracy
                                                              select ed1.playerID
                                                                     ,{$tp}playerprofile.playerName
                                                                     ,ed1.eventName
                                                                     ,{$tp}playerprofile.games as games
                                                                     ,sum(ed1.eventValue) as hits 
                                                                     ,sum(ed2.eventValue) as shots
                                                                     ,round(sum(ed1.eventValue)/sum(ed2.eventValue)*100.0,2) as accuracy 
                                                              from {$tp}eventdata2d as ed1 join {$tp}playerprofile
                                                              left join {$tp}eventdata2d as ed2 
                                                              on (
                                                                  ed1.playerid=ed2.playerid and
                                                                  ed1.gameid=ed2.gameid and 
                                                                  ed1.round=ed2.round and
                                                                  ed1.team=ed2.team and 
                                                                  ed1.role=ed2.role and 
                                                                  ed1.eventCategory=ed2.eventCategory and
                                                                  ed1.player2id=ed2.player2id and 
                                                                  ed1.team2=ed2.team2 and 
                                                                  ed1.role2=ed2.role2
                                                                 ) 
                                                              where 
                                                              {$tp}playerprofile.games>$avg_games 
                                                              and {$tp}playerprofile.playerID=ed1.playerID 
                                                              and ed1.eventName='_v_weapons_hits' 
                                                              and ed2.eventName='_v_weapons_shots'
                                                              and ed1.eventCategory='accuracy'
                                                              ".($excluded_players ? "and {$tp}playerprofile.playerID not in {$excluded_players}" : "")."
                                                              group by playerID,ed1.eventName
                                                              order by accuracy DESC
                                                              ";


$awardset['avg_shots__v_weapons']['sql'][0]    = "select std(shots)
                                               from {$tp}awardsaccuracy
                                               where weaponID='_v_weapons_hits' 
                                               group by weaponID 
                                    ";


$awardset['accuracy__v_weapons']['name']                 = 'Best Accuracy with _v_weapons';
$awardset['accuracy__v_weapons']['image']                = 'accuracy__v_weapons';
$awardset['accuracy__v_weapons']['category']             = 'Accuracy';
$awardset['accuracy__v_weapons']['sql'][0]               = "select playerID,playerName,games,hits ,shots,accuracy 
                                                          from {$tp}awardsaccuracy
                                                          where weaponID='_v_weapons_hits'
                                                          and shots > ({\$awardset['avg_shots_v_weapons']['sql'][0][0]}-1)
                                                          group by playerID
                                                          order by accuracy DESC
                                                          ";




$awardset['accuracyALLWEAPONS']['name']                 = 'Best Overall Accuracy';
$awardset['accuracyALLWEAPONS']['image']                = 'accuracy_ALLWEAPONS';
$awardset['accuracyALLWEAPONS']['category']             = 'Accuracy';
$awardset['accuracyALLWEAPONS']['sql'][0]               = "select playerID
                                                                  ,playerName,games
                                                                  ,sum(hits) as hits
                                                                  ,sum(shots) as shots
                                                                  ,sum(hits)/sum(shots) as accuracy 
                                                           from {$tp}awardsaccuracy
                                                           group by playerID 
                                                           order by accuracy DESC,hits/games DESC";
*/










//------------------------------------------------------------------












/*
//------------------------------------------------------------------
// Accuracy awards using direct method (slow)
//
$awardset['avg_shots__v_weapons']['sql'][0]    = "select avg(eventValue) as shots 
                                               from {tp}eventdata2d 
                                               where eventname='_v_weapons_shots' 
                                               group by playerid 
                                               order by shots desc
                                    ";


$awardset['accuracy__v_weapons-direct']['name']           = 'Best Accuracy with _v_weapons';
$awardset['accuracy__v_weapons-direct']['image']               = 'accuracy__v_weapons';
$awardset['accuracy__v_weapons-direct']['category']            = 'Accuracy';
$awardset['accuracy__v_weapons-direct']['sql'][0] = "select ed1.playerID,{$tp}playerprofile.playerName,{$tp}playerprofile.games as games,sum(ed1.eventValue) as hits ,sum(ed2.eventValue) as shots,round(sum(ed1.eventValue)/sum(ed2.eventValue)*100.0,2) as accuracy 
                                            from {$tp}eventdata2d as ed1,{$tp}playerprofile 
                                            left join {$tp}eventdata2d as ed2 
                                            on (
                                                ed1.playerid=ed2.playerid and
                                                ed1.gameid=ed2.gameid and 
                                                ed1.round=ed2.round and
                                                ed1.team=ed2.team and 
                                                ed1.role=ed2.role and 
                                                ed1.eventCategory=ed2.eventCategory and
                                                ed1.player2id=ed2.player2id and 
                                                ed1.team2=ed2.team2 and 
                                                ed1.role2=ed2.role2
                                               ) 
                                            where 
                                            {$tp}playerprofile.playerID=ed1.playerID and 
                                            ed1.eventName='_v_weapons_hits' and ed2.eventName='_v_weapons_shots'
                                            group by playerID
                                            having shots > ({\$awardset['avg_shots_v_weapons']['sql'][0][0]}-1)
                                            and games>$avg_games 
                                            order by accuracy DESC
                                            ";

//------------------------------------------------------------------
*/








?>