SHARE
TWEET

Untitled

a guest Nov 20th, 2019 102 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function build($dir){
  2.     error_reporting(1);
  3.     if($dir == 'build' OR $dir == 'index'){
  4.         echo 'the fuck are you trying to do? Rename it.';
  5.         die();
  6.     }
  7.     Global $ini;
  8.     //demo directory
  9.     $dir = "../requested/".$dir;
  10.    
  11.     //change directory for some reason.
  12.     chdir($dir);
  13.    
  14.     $files = glob("*.json*");
  15.  
  16.  
  17.     //make player array profiles
  18.     $list = 'SteamID,PlayerName,Games,Kills,Deaths,Assists,Headshots,MVPs,Plants,Defuses,Rescues,TicksAlive,TicksOnServer';
  19.     $list = explode(',', $list);
  20.     //make values into keys
  21.     foreach($list as $key => $value){
  22.         $player[$value] = null;
  23.     }
  24.     $allPlayers = array();
  25.     $totalPlayerCount = 0;
  26.     $playerCount = 0;
  27.     $demoCount = 0;
  28.     //runEachDemo
  29.    
  30.     $bombA_plants = 0;
  31.     $bombB_plants = 0;
  32.     $bombA_defuses = 0;
  33.     $bombB_defuses = 0;
  34.     $bombA_explosions = 0;
  35.     $bombB_explosions = 0;
  36.    
  37.     $bombA_timePlanted = null;
  38.     $bombB_timePlanted = null;
  39.    
  40.     $hostageA_rescueTime = null;
  41.     $hostageB_rescueTime = null;
  42.    
  43.     $hostageA = 0;
  44.     $hostageB = 0;
  45.    
  46.     $roundsPlayed = 0;
  47.     $tWins = 0;
  48.     $ctWins = 0;
  49.     $roundLength = 0;
  50.    
  51.     $dataGuns = array();
  52.     $gunList = explode(',', $ini['gunList']);
  53.     foreach($gunList as $key => $value){
  54.         $dataGuns[$value] = 0;
  55.     }
  56.    
  57.     $dataGunsAll = null;
  58.  
  59.     //make player array profiles
  60.     $list = 'SteamID,PlayerName,Games,Kills,Deaths,Assists,Headshots,MVPs,Plants,Defuses,Rescues,TicksAlive,TicksOnServer';
  61.     $list = explode(',', $list);
  62.     //make values into keys
  63.     foreach($list as $key => $value){
  64.         $player[$value] = null;
  65.     }
  66.  
  67.     $totalPlayerCount = 0;
  68.     $playerCount = 0;
  69.     $demoCount = 0;
  70.    
  71.     $ctPistolWins = null;
  72.     $tPistolWins = null;
  73.    
  74.     $scorelines = array();
  75.    
  76.     $combinedArray = array();
  77.    
  78.     $deathTime = array();
  79.    
  80.     foreach($files as $file){
  81.         $json = file_get_contents($file);
  82.         $data = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
  83.         //
  84.         //Bombsite Stats
  85.         //Hostage
  86.         //
  87.         $bombA_plants = $data->bombsiteStats[0]->Plants+$bombA_plants;
  88.         $bombA_defuses = $data->bombsiteStats[0]->Defuses+$bombA_defuses;
  89.         $bombA_explosions = $data->bombsiteStats[0]->Explosions+$bombA_explosions;
  90.        
  91.         $bombB_plants = $data->bombsiteStats[1]->Plants+$bombB_plants;
  92.         $bombB_defuses = $data->bombsiteStats[1]->Defuses+$bombB_defuses;
  93.         $bombB_explosions = $data->bombsiteStats[1]->Explosions+$bombB_explosions;
  94.        
  95.         $hostageA = $data->hostageStats[0]->Rescues+$hostageA;
  96.         $hostageB = $data->hostageStats[1]->Rescues+$hostageB;
  97.        
  98.         $totalPlants = $bombB_plants+$bombB_plants;
  99.         //
  100.         //Round stats
  101.         //AverageBombsite time
  102.         //Average hostage time
  103.         //
  104.         $secondHalf = 0;
  105.         foreach($data->roundsStats as $round){
  106.             //who won
  107.             if($round->Winners == 'Terrorist'){
  108.                 $tWins++;
  109.             }elseif($round->Winners == 'CounterTerrorist'){
  110.                 $ctWins++;
  111.             }
  112.             //pistolRound
  113.             if($round->Winners == 1){
  114.                 if($round->Winners == 'Terrorist'){
  115.                     $tPistolWins++;
  116.                 }elseif($round->Winners == 'CounterTerrorist'){
  117.                     $ctPistolWins++;
  118.                 }  
  119.             }
  120.             if($round->Half == 'Second'){
  121.                 if($secondHalf > 1){
  122.                 }else{
  123.                     if($round->Winners == 'Terrorist'){
  124.                         $tPistolWins++;
  125.                     }elseif($round->Winners == 'CounterTerrorist'){
  126.                         $ctPistolWins++;
  127.                     }      
  128.                 }
  129.                 $secondHalf++;
  130.             }
  131.             //round length
  132.             $roundLength = $round->Length + $roundLength;
  133.            
  134.             //Average bomb site time
  135.             if($round->BombsitePlantedAt == 'A'){
  136.                 $bombA_timePlanted = $round->TimeInRoundPlanted + $bombA_timePlanted;
  137.             }
  138.             if($round->BombsitePlantedAt == 'B'){
  139.                 $bombB_timePlanted = $round->TimeInRoundPlanted + $bombB_timePlanted;
  140.             }
  141.             //Average rescue
  142.             if($round->RescuedHostageA == 'true'){
  143.                 $hostageA_rescueTime = $round->TimeInRoundRescuedHostageA + $hostageA_rescueTime;
  144.             }
  145.             if($round->RescuedHostageB == 'true'){
  146.                 $hostageB_rescueTime = $round->TimeInRoundRescuedHostageB + $hostageB_rescueTime;
  147.             }
  148.                
  149.             //total rounds
  150.             $roundsPlayed++;
  151.         }
  152.         //
  153.         //GunStats
  154.         //death Time
  155.         //     
  156.         foreach($data->killsStats as $key => $value){  
  157.             if(isset($dataGuns[$value->Weapon])){
  158.                 $dataGuns[$value->Weapon] = $dataGuns[$value->Weapon]+1;
  159.             }else{
  160.                 $dataGuns[$value->Weapon] = 1;
  161.             }
  162.             $dataGunsAll++;
  163.            
  164.             $deathSecond = round($value->TimeInRound,0);
  165.             if($deathSecond < 131 AND $deathSecond >= 1){
  166.                 if(isset($deathTime[$deathSecond])){
  167.                     $deathTime[$deathSecond]++;
  168.                 }else{
  169.                     $deathTime[$deathSecond] = 1;
  170.                 }  
  171.             }
  172.  
  173.         }
  174.         //
  175.         //PlayerStats
  176.         //
  177.         foreach($data->playerStats as $players){
  178.             if(array_key_exists($players->SteamID, $allPlayers)){
  179.                 //define values for each user
  180.                 $allPlayers[$players->SteamID]['PlayerName'] = $players->PlayerName;
  181.                 $allPlayers[$players->SteamID]['Games'] = 1 + $allPlayers[$players->SteamID]['Games'];
  182.                 $allPlayers[$players->SteamID]['Kills'] = $players->Kills + $allPlayers[$players->SteamID]['Kills'];
  183.                 $allPlayers[$players->SteamID]['Deaths'] = $players->Deaths + $allPlayers[$players->SteamID]['Deaths'];
  184.                 $allPlayers[$players->SteamID]['Assists'] = $players->Assists + $allPlayers[$players->SteamID]['Assists'];
  185.                 $allPlayers[$players->SteamID]['Headshots'] = $players->Headshots + $allPlayers[$players->SteamID] ['Headshots'];
  186.                 $allPlayers[$players->SteamID]['MVPs'] = $players->MVPs + $allPlayers[$players->SteamID]['MVPs'];
  187.                 $allPlayers[$players->SteamID]['Plants'] = $players->Plants + $allPlayers[$players->SteamID]['Plants'];
  188.                 $allPlayers[$players->SteamID]['Defuses'] = $players->Defuses + $allPlayers[$players->SteamID]['Defuses'];
  189.                 $allPlayers[$players->SteamID]['Rescues'] = $players->Rescues + $allPlayers[$players->SteamID]['Rescues'];
  190.                 $allPlayers[$players->SteamID]['TicksAlive']  = $players->TicksAlive + $allPlayers[$players->SteamID]['TicksAlive'];
  191.                 $allPlayers[$players->SteamID]['TicksOnServer'] = $players->TicksOnServer + $allPlayers[$players->SteamID]['TicksOnServer'];
  192.                 //get Totals
  193.                 $allPlayers['totals']['Games'] = 1 + $allPlayers['totals']['Games'];
  194.                 $allPlayers['totals']['Kills'] = $players->Kills + $allPlayers['totals']['Kills'];
  195.                 $allPlayers['totals']['Deaths'] = $players->Deaths + $allPlayers['totals']['Deaths'];
  196.                 $allPlayers['totals']['Assists'] = $players->Assists + $allPlayers['totals']['Assists'];
  197.                 $allPlayers['totals']['Headshots'] = $players->Headshots + $allPlayers['totals']['Headshots'];
  198.                 $allPlayers['totals']['Plants'] = $players->Plants + $allPlayers['totals']['Plants'];
  199.                 $allPlayers['totals']['Defuses'] = $players->Defuses + $allPlayers['totals']['Defuses'];
  200.                 $allPlayers['totals']['Rescues'] = $players->Rescues + $allPlayers['totals']['Rescues'];
  201.                 $allPlayers['totals']['Mvps'] = $players->MVPs + $allPlayers['totals']['Mvps'];
  202.             }else{
  203.                 $allPlayers[$players->SteamID]['PlayerName'] = $players->PlayerName;
  204.                 $allPlayers[$players->SteamID]['Games'] = 1;
  205.                 $allPlayers[$players->SteamID]['Kills'] = $players->Kills;
  206.                 $allPlayers[$players->SteamID]['Deaths'] = $players->Deaths;
  207.                 $allPlayers[$players->SteamID]['Assists'] = $players->Assists;
  208.                 $allPlayers[$players->SteamID] ['Headshots'] = $players->Headshots;
  209.                 $allPlayers[$players->SteamID]['MVPs'] = $players->MVPs;
  210.                 $allPlayers[$players->SteamID]['Plants'] = $players->Plants;
  211.                 $allPlayers[$players->SteamID]['Defuses'] = $players->Defuses;
  212.                 $allPlayers[$players->SteamID]['Rescues'] = $players->Rescues;
  213.                 $allPlayers[$players->SteamID]['TicksAlive']  = $players->TicksAlive;
  214.                 $allPlayers[$players->SteamID]['TicksOnServer'] = $players->TicksOnServer;
  215.                 $totalPlayerCount++;               
  216.             }
  217.             $playerCount++;
  218.         }
  219.             //gather scorelines
  220.             $alphaScore = $data->winnersStats->TeamAlphaRounds;
  221.             $bravoScore = $data->winnersStats->TeamBetaRounds;
  222.            
  223.             if($alphaScore > $bravoScore){
  224.                 $scoreInput = $alphaScore.'-'.$bravoScore;
  225.             }else{
  226.                 $scoreInput = $bravoScore.'-'.$alphaScore;
  227.             }
  228.            
  229.             if(isset($scorelines[$scoreInput])){
  230.                 $scorelines[$scoreInput] = $scorelines[$scoreInput]+1;
  231.             }else{
  232.                 $scorelines[$scoreInput] = 1;
  233.             }
  234.         //demo count
  235.         $demoCount++;
  236.     }  
  237.    
  238.     $dataGuns['All'] = $dataGunsAll;
  239.     arsort($dataGuns);
  240.     arsort($scorelines);
  241.     ksort($deathTime);
  242.    
  243.     //Define Array
  244.     $combinedArray['info']['combinedDate'] = date("Y-m-d H:i:s");  
  245.     $combinedArray['info']['totalDemos'] = $demoCount; 
  246.     $combinedArray['info']['totalRounds'] = $roundsPlayed; 
  247.     $combinedArray['info']['totalJoins'] = $playerCount;   
  248.     $combinedArray['info']['totalUniquePlayers'] = $totalPlayerCount;  
  249.    
  250.     $combinedArray['bombsite']['A']['plants'] = $bombA_plants;
  251.     $combinedArray['bombsite']['A']['defuses'] = $bombA_defuses;
  252.     $combinedArray['bombsite']['A']['explosions'] = $bombA_explosions;
  253.     $combinedArray['bombsite']['A']['averageTimeToPlant'] = $bombA_timePlanted/zeroCheck($bombA_plants);
  254.    
  255.     $combinedArray['bombsite']['B']['plants'] = $bombB_plants;
  256.     $combinedArray['bombsite']['B']['defuses'] = $bombB_defuses;
  257.     $combinedArray['bombsite']['B']['explosions'] = $bombB_explosions;
  258.     $combinedArray['bombsite']['B']['averageTimeToPlant'] = $bombB_timePlanted/zeroCheck($bombB_plants);
  259.    
  260.     $combinedArray['hostage']['A']['rescues'] = $hostageA;
  261.     $combinedArray['hostage']['A']['AverageRescueTime'] = $hostageA_rescueTime/zeroCheck($hostageA);
  262.    
  263.     $combinedArray['hostage']['B']['rescues'] = $hostageB;
  264.     $combinedArray['hostage']['B']['AverageRescueTime'] = $hostageA_rescueTime/zeroCheck($hostageB);
  265.    
  266.     $combinedArray['rounds']['TotalCTwins'] = $ctWins;
  267.     $combinedArray['rounds']['TotalTwins'] = $tWins;
  268.     $combinedArray['rounds']['AverageLength'] = $roundLength/zeroCheck($roundsPlayed);
  269.    
  270.     $combinedArray['rounds']['TotalCTPistolWins'] = $ctPistolWins;
  271.     $combinedArray['rounds']['TotalTPistolWins'] = $tPistolWins;
  272.    
  273.     $combinedArray['weapons'] = $dataGuns;
  274.    
  275.     $combinedArray['scores'] = $scorelines;
  276.    
  277.     $combinedArray['deathTimeChart'] = $deathTime;
  278.    
  279.     //$combinedArray['players'] = $allPlayers;
  280.         //player Stats
  281.        
  282.         $totalPlayerCount = count($allPlayers) - 1;
  283.         $totalKills = $allPlayers['totals']['Kills'];
  284.         $totalDeaths = $allPlayers['totals']['Deaths'];
  285.         $totalAssists = $allPlayers['totals']['Assists'];
  286.         $totalGames = $allPlayers['totals']['Games'];
  287.         $totalassists = $allPlayers['totals']['Assists'];
  288.         $totalHeadshot = $allPlayers['totals']['Headshots'];
  289.         $totalPlants = $allPlayers['totals']['Plants'];
  290.         $totalDefuses = $allPlayers['totals']['Defuses'];
  291.         $totalRescues = $allPlayers['totals']['Rescues'];
  292.         $totalMVPs = $allPlayers['totals']['Mvps'];
  293.         //averages
  294.  
  295.         $averageAssists = $totalAssists / zeroCheck($totalDeaths);
  296.         $averageHeadshot = $totalHeadshot / zeroCheck($totalGames);
  297.         $averagePlants = $totalPlants / zeroCheck($totalGames);
  298.         $averageDefuses = $totalDefuses / zeroCheck($totalGames);
  299.         $averageRescues = $totalRescues / zeroCheck($totalPlayerCount);
  300.         $averageMVPs = $totalMVPs / zeroCheck($totalGames);
  301.         $playersRequested = null;
  302.        
  303.         $listAllPlayers = $allPlayers;
  304.         unset($listAllPlayers['totals']);
  305.         unset($listAllPlayers['76561197962998814']);
  306.         $listAllPlayers = array_keys($listAllPlayers);
  307.        
  308.         $playerRating = array();
  309.         $playerProbabtion = array();
  310.     //playerStat
  311.         foreach($allPlayers as $steamID => $stats){
  312.             //figure out stats
  313.             if($allPlayers[$steamID]['Deaths'] == 0){
  314.                 $kd = 0;           
  315.             }else{
  316.                 $kd = round($allPlayers[$steamID]['Kills'] / $allPlayers[$steamID]['Deaths'], 2);          
  317.             }
  318.  
  319.             $ad = $allPlayers[$steamID]['Assists']/ zeroCheck($allPlayers[$steamID]['Deaths']);
  320.            
  321.             if($allPlayers[$steamID]['Headshots'] == 0){
  322.                 $headshot = 0;
  323.             }else{
  324.                 $headshot = round($allPlayers[$steamID]['Headshots'] / zeroCheck($allPlayers[$steamID]['Kills'], 2));
  325.                 $headshot = $headshot*100;         
  326.             }
  327.            
  328.             $plants = $allPlayers[$steamID]['Defuses']/zeroCheck($allPlayers[$steamID]['Games']);
  329.            
  330.             $gameThreshold = $demoCount; //required games before gain full scale   
  331.            
  332.             if($allPlayers[$steamID]['Games'] > $gameThreshold){
  333.                 $scale = 10;
  334.             }else{
  335.                 $scale = $allPlayers[$steamID]['Games']*2;
  336.             }
  337.             //Player Rating
  338.             $kdWeight = weightDefine($kd, 1, $scale);  
  339.             $adWeight = weightDefine($ad, $averageAssists, $scale/4);  
  340.             $headshotWeight = weightDefine($headshot, $averageHeadshot, $scale/5);
  341.             $plantsWeight = weightDefine($allPlayers[$steamID]['Plants']/$allPlayers[$steamID]['Games'], $averagePlants, $scale/5);
  342.             $defusesWeight = weightDefine($allPlayers[$steamID]['Defuses']/$allPlayers[$steamID]['Games'], $averageDefuses, $scale/5);
  343.             $mvpsWeight = weightDefine($allPlayers[$steamID]['MVPs']/$allPlayers[$steamID]['Games'], $averageMVPs, $scale/3);
  344.             //manually add game weight
  345.  
  346.             $totalWeights = 6;
  347.             $rating = $kdWeight+
  348.                       $adWeight+
  349.                       $headshotWeight+
  350.                       $plantsWeight+
  351.                       $defusesWeight+
  352.                       $mvpsWeight;
  353.             $rating = $rating/$totalWeights;
  354.             $rating = $rating/10;
  355.             $rating = round($rating, 1);
  356.             //$rating = $adWeight;
  357.            
  358.             $playerRating[$steamID] = $rating;
  359.             $playerProbabtion[$steamID] = $scale;
  360.         }
  361.         arsort($playerRating);
  362.  
  363.         $maxCount = 0;
  364.        
  365.         foreach($playerRating as $steamID => $rating){
  366.             $combinedArray['players'][$steamID] = $allPlayers[$steamID];
  367.             if($maxCount == 999){
  368.                 break;
  369.             }
  370.             $maxCount++;
  371.         }
  372.    
  373.     chdir('../');
  374.     $file = $dir.".json";
  375.    
  376.     try{
  377.         //arrayDebug($combinedArray);
  378.         $jsondata = json_encode($combinedArray, JSON_PRETTY_PRINT);    
  379.         file_put_contents($file, $jsondata);
  380.         //build heatmaps
  381.         buildHeatmaps($dir);
  382.         //beam me up scotty
  383.         header("Location: build.php");
  384.     }catch (Exception $e) {
  385.         echo 'Status: NotGucci';
  386.     }
  387. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top