Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function build($dir){
- error_reporting(1);
- if($dir == 'build' OR $dir == 'index'){
- echo 'the fuck are you trying to do? Rename it.';
- die();
- }
- Global $ini;
- //demo directory
- $dir = "../requested/".$dir;
- //change directory for some reason.
- chdir($dir);
- $files = glob("*.json*");
- //make player array profiles
- $list = 'SteamID,PlayerName,Games,Kills,Deaths,Assists,Headshots,MVPs,Plants,Defuses,Rescues,TicksAlive,TicksOnServer';
- $list = explode(',', $list);
- //make values into keys
- foreach($list as $key => $value){
- $player[$value] = null;
- }
- $allPlayers = array();
- $totalPlayerCount = 0;
- $playerCount = 0;
- $demoCount = 0;
- //runEachDemo
- $bombA_plants = 0;
- $bombB_plants = 0;
- $bombA_defuses = 0;
- $bombB_defuses = 0;
- $bombA_explosions = 0;
- $bombB_explosions = 0;
- $bombA_timePlanted = null;
- $bombB_timePlanted = null;
- $hostageA_rescueTime = null;
- $hostageB_rescueTime = null;
- $hostageA = 0;
- $hostageB = 0;
- $roundsPlayed = 0;
- $tWins = 0;
- $ctWins = 0;
- $roundLength = 0;
- $dataGuns = array();
- $gunList = explode(',', $ini['gunList']);
- foreach($gunList as $key => $value){
- $dataGuns[$value] = 0;
- }
- $dataGunsAll = null;
- //make player array profiles
- $list = 'SteamID,PlayerName,Games,Kills,Deaths,Assists,Headshots,MVPs,Plants,Defuses,Rescues,TicksAlive,TicksOnServer';
- $list = explode(',', $list);
- //make values into keys
- foreach($list as $key => $value){
- $player[$value] = null;
- }
- $totalPlayerCount = 0;
- $playerCount = 0;
- $demoCount = 0;
- $ctPistolWins = null;
- $tPistolWins = null;
- $scorelines = array();
- $combinedArray = array();
- $deathTime = array();
- foreach($files as $file){
- $json = file_get_contents($file);
- $data = json_decode($json, false, 512, JSON_BIGINT_AS_STRING);
- //
- //Bombsite Stats
- //Hostage
- //
- $bombA_plants = $data->bombsiteStats[0]->Plants+$bombA_plants;
- $bombA_defuses = $data->bombsiteStats[0]->Defuses+$bombA_defuses;
- $bombA_explosions = $data->bombsiteStats[0]->Explosions+$bombA_explosions;
- $bombB_plants = $data->bombsiteStats[1]->Plants+$bombB_plants;
- $bombB_defuses = $data->bombsiteStats[1]->Defuses+$bombB_defuses;
- $bombB_explosions = $data->bombsiteStats[1]->Explosions+$bombB_explosions;
- $hostageA = $data->hostageStats[0]->Rescues+$hostageA;
- $hostageB = $data->hostageStats[1]->Rescues+$hostageB;
- $totalPlants = $bombB_plants+$bombB_plants;
- //
- //Round stats
- //AverageBombsite time
- //Average hostage time
- //
- $secondHalf = 0;
- foreach($data->roundsStats as $round){
- //who won
- if($round->Winners == 'Terrorist'){
- $tWins++;
- }elseif($round->Winners == 'CounterTerrorist'){
- $ctWins++;
- }
- //pistolRound
- if($round->Winners == 1){
- if($round->Winners == 'Terrorist'){
- $tPistolWins++;
- }elseif($round->Winners == 'CounterTerrorist'){
- $ctPistolWins++;
- }
- }
- if($round->Half == 'Second'){
- if($secondHalf > 1){
- }else{
- if($round->Winners == 'Terrorist'){
- $tPistolWins++;
- }elseif($round->Winners == 'CounterTerrorist'){
- $ctPistolWins++;
- }
- }
- $secondHalf++;
- }
- //round length
- $roundLength = $round->Length + $roundLength;
- //Average bomb site time
- if($round->BombsitePlantedAt == 'A'){
- $bombA_timePlanted = $round->TimeInRoundPlanted + $bombA_timePlanted;
- }
- if($round->BombsitePlantedAt == 'B'){
- $bombB_timePlanted = $round->TimeInRoundPlanted + $bombB_timePlanted;
- }
- //Average rescue
- if($round->RescuedHostageA == 'true'){
- $hostageA_rescueTime = $round->TimeInRoundRescuedHostageA + $hostageA_rescueTime;
- }
- if($round->RescuedHostageB == 'true'){
- $hostageB_rescueTime = $round->TimeInRoundRescuedHostageB + $hostageB_rescueTime;
- }
- //total rounds
- $roundsPlayed++;
- }
- //
- //GunStats
- //death Time
- //
- foreach($data->killsStats as $key => $value){
- if(isset($dataGuns[$value->Weapon])){
- $dataGuns[$value->Weapon] = $dataGuns[$value->Weapon]+1;
- }else{
- $dataGuns[$value->Weapon] = 1;
- }
- $dataGunsAll++;
- $deathSecond = round($value->TimeInRound,0);
- if($deathSecond < 131 AND $deathSecond >= 1){
- if(isset($deathTime[$deathSecond])){
- $deathTime[$deathSecond]++;
- }else{
- $deathTime[$deathSecond] = 1;
- }
- }
- }
- //
- //PlayerStats
- //
- foreach($data->playerStats as $players){
- if(array_key_exists($players->SteamID, $allPlayers)){
- //define values for each user
- $allPlayers[$players->SteamID]['PlayerName'] = $players->PlayerName;
- $allPlayers[$players->SteamID]['Games'] = 1 + $allPlayers[$players->SteamID]['Games'];
- $allPlayers[$players->SteamID]['Kills'] = $players->Kills + $allPlayers[$players->SteamID]['Kills'];
- $allPlayers[$players->SteamID]['Deaths'] = $players->Deaths + $allPlayers[$players->SteamID]['Deaths'];
- $allPlayers[$players->SteamID]['Assists'] = $players->Assists + $allPlayers[$players->SteamID]['Assists'];
- $allPlayers[$players->SteamID]['Headshots'] = $players->Headshots + $allPlayers[$players->SteamID] ['Headshots'];
- $allPlayers[$players->SteamID]['MVPs'] = $players->MVPs + $allPlayers[$players->SteamID]['MVPs'];
- $allPlayers[$players->SteamID]['Plants'] = $players->Plants + $allPlayers[$players->SteamID]['Plants'];
- $allPlayers[$players->SteamID]['Defuses'] = $players->Defuses + $allPlayers[$players->SteamID]['Defuses'];
- $allPlayers[$players->SteamID]['Rescues'] = $players->Rescues + $allPlayers[$players->SteamID]['Rescues'];
- $allPlayers[$players->SteamID]['TicksAlive'] = $players->TicksAlive + $allPlayers[$players->SteamID]['TicksAlive'];
- $allPlayers[$players->SteamID]['TicksOnServer'] = $players->TicksOnServer + $allPlayers[$players->SteamID]['TicksOnServer'];
- //get Totals
- $allPlayers['totals']['Games'] = 1 + $allPlayers['totals']['Games'];
- $allPlayers['totals']['Kills'] = $players->Kills + $allPlayers['totals']['Kills'];
- $allPlayers['totals']['Deaths'] = $players->Deaths + $allPlayers['totals']['Deaths'];
- $allPlayers['totals']['Assists'] = $players->Assists + $allPlayers['totals']['Assists'];
- $allPlayers['totals']['Headshots'] = $players->Headshots + $allPlayers['totals']['Headshots'];
- $allPlayers['totals']['Plants'] = $players->Plants + $allPlayers['totals']['Plants'];
- $allPlayers['totals']['Defuses'] = $players->Defuses + $allPlayers['totals']['Defuses'];
- $allPlayers['totals']['Rescues'] = $players->Rescues + $allPlayers['totals']['Rescues'];
- $allPlayers['totals']['Mvps'] = $players->MVPs + $allPlayers['totals']['Mvps'];
- }else{
- $allPlayers[$players->SteamID]['PlayerName'] = $players->PlayerName;
- $allPlayers[$players->SteamID]['Games'] = 1;
- $allPlayers[$players->SteamID]['Kills'] = $players->Kills;
- $allPlayers[$players->SteamID]['Deaths'] = $players->Deaths;
- $allPlayers[$players->SteamID]['Assists'] = $players->Assists;
- $allPlayers[$players->SteamID] ['Headshots'] = $players->Headshots;
- $allPlayers[$players->SteamID]['MVPs'] = $players->MVPs;
- $allPlayers[$players->SteamID]['Plants'] = $players->Plants;
- $allPlayers[$players->SteamID]['Defuses'] = $players->Defuses;
- $allPlayers[$players->SteamID]['Rescues'] = $players->Rescues;
- $allPlayers[$players->SteamID]['TicksAlive'] = $players->TicksAlive;
- $allPlayers[$players->SteamID]['TicksOnServer'] = $players->TicksOnServer;
- $totalPlayerCount++;
- }
- $playerCount++;
- }
- //gather scorelines
- $alphaScore = $data->winnersStats->TeamAlphaRounds;
- $bravoScore = $data->winnersStats->TeamBetaRounds;
- if($alphaScore > $bravoScore){
- $scoreInput = $alphaScore.'-'.$bravoScore;
- }else{
- $scoreInput = $bravoScore.'-'.$alphaScore;
- }
- if(isset($scorelines[$scoreInput])){
- $scorelines[$scoreInput] = $scorelines[$scoreInput]+1;
- }else{
- $scorelines[$scoreInput] = 1;
- }
- //demo count
- $demoCount++;
- }
- $dataGuns['All'] = $dataGunsAll;
- arsort($dataGuns);
- arsort($scorelines);
- ksort($deathTime);
- //Define Array
- $combinedArray['info']['combinedDate'] = date("Y-m-d H:i:s");
- $combinedArray['info']['totalDemos'] = $demoCount;
- $combinedArray['info']['totalRounds'] = $roundsPlayed;
- $combinedArray['info']['totalJoins'] = $playerCount;
- $combinedArray['info']['totalUniquePlayers'] = $totalPlayerCount;
- $combinedArray['bombsite']['A']['plants'] = $bombA_plants;
- $combinedArray['bombsite']['A']['defuses'] = $bombA_defuses;
- $combinedArray['bombsite']['A']['explosions'] = $bombA_explosions;
- $combinedArray['bombsite']['A']['averageTimeToPlant'] = $bombA_timePlanted/zeroCheck($bombA_plants);
- $combinedArray['bombsite']['B']['plants'] = $bombB_plants;
- $combinedArray['bombsite']['B']['defuses'] = $bombB_defuses;
- $combinedArray['bombsite']['B']['explosions'] = $bombB_explosions;
- $combinedArray['bombsite']['B']['averageTimeToPlant'] = $bombB_timePlanted/zeroCheck($bombB_plants);
- $combinedArray['hostage']['A']['rescues'] = $hostageA;
- $combinedArray['hostage']['A']['AverageRescueTime'] = $hostageA_rescueTime/zeroCheck($hostageA);
- $combinedArray['hostage']['B']['rescues'] = $hostageB;
- $combinedArray['hostage']['B']['AverageRescueTime'] = $hostageA_rescueTime/zeroCheck($hostageB);
- $combinedArray['rounds']['TotalCTwins'] = $ctWins;
- $combinedArray['rounds']['TotalTwins'] = $tWins;
- $combinedArray['rounds']['AverageLength'] = $roundLength/zeroCheck($roundsPlayed);
- $combinedArray['rounds']['TotalCTPistolWins'] = $ctPistolWins;
- $combinedArray['rounds']['TotalTPistolWins'] = $tPistolWins;
- $combinedArray['weapons'] = $dataGuns;
- $combinedArray['scores'] = $scorelines;
- $combinedArray['deathTimeChart'] = $deathTime;
- //$combinedArray['players'] = $allPlayers;
- //player Stats
- $totalPlayerCount = count($allPlayers) - 1;
- $totalKills = $allPlayers['totals']['Kills'];
- $totalDeaths = $allPlayers['totals']['Deaths'];
- $totalAssists = $allPlayers['totals']['Assists'];
- $totalGames = $allPlayers['totals']['Games'];
- $totalassists = $allPlayers['totals']['Assists'];
- $totalHeadshot = $allPlayers['totals']['Headshots'];
- $totalPlants = $allPlayers['totals']['Plants'];
- $totalDefuses = $allPlayers['totals']['Defuses'];
- $totalRescues = $allPlayers['totals']['Rescues'];
- $totalMVPs = $allPlayers['totals']['Mvps'];
- //averages
- $averageAssists = $totalAssists / zeroCheck($totalDeaths);
- $averageHeadshot = $totalHeadshot / zeroCheck($totalGames);
- $averagePlants = $totalPlants / zeroCheck($totalGames);
- $averageDefuses = $totalDefuses / zeroCheck($totalGames);
- $averageRescues = $totalRescues / zeroCheck($totalPlayerCount);
- $averageMVPs = $totalMVPs / zeroCheck($totalGames);
- $playersRequested = null;
- $listAllPlayers = $allPlayers;
- unset($listAllPlayers['totals']);
- unset($listAllPlayers['76561197962998814']);
- $listAllPlayers = array_keys($listAllPlayers);
- $playerRating = array();
- $playerProbabtion = array();
- //playerStat
- foreach($allPlayers as $steamID => $stats){
- //figure out stats
- if($allPlayers[$steamID]['Deaths'] == 0){
- $kd = 0;
- }else{
- $kd = round($allPlayers[$steamID]['Kills'] / $allPlayers[$steamID]['Deaths'], 2);
- }
- $ad = $allPlayers[$steamID]['Assists']/ zeroCheck($allPlayers[$steamID]['Deaths']);
- if($allPlayers[$steamID]['Headshots'] == 0){
- $headshot = 0;
- }else{
- $headshot = round($allPlayers[$steamID]['Headshots'] / zeroCheck($allPlayers[$steamID]['Kills'], 2));
- $headshot = $headshot*100;
- }
- $plants = $allPlayers[$steamID]['Defuses']/zeroCheck($allPlayers[$steamID]['Games']);
- $gameThreshold = $demoCount; //required games before gain full scale
- if($allPlayers[$steamID]['Games'] > $gameThreshold){
- $scale = 10;
- }else{
- $scale = $allPlayers[$steamID]['Games']*2;
- }
- //Player Rating
- $kdWeight = weightDefine($kd, 1, $scale);
- $adWeight = weightDefine($ad, $averageAssists, $scale/4);
- $headshotWeight = weightDefine($headshot, $averageHeadshot, $scale/5);
- $plantsWeight = weightDefine($allPlayers[$steamID]['Plants']/$allPlayers[$steamID]['Games'], $averagePlants, $scale/5);
- $defusesWeight = weightDefine($allPlayers[$steamID]['Defuses']/$allPlayers[$steamID]['Games'], $averageDefuses, $scale/5);
- $mvpsWeight = weightDefine($allPlayers[$steamID]['MVPs']/$allPlayers[$steamID]['Games'], $averageMVPs, $scale/3);
- //manually add game weight
- $totalWeights = 6;
- $rating = $kdWeight+
- $adWeight+
- $headshotWeight+
- $plantsWeight+
- $defusesWeight+
- $mvpsWeight;
- $rating = $rating/$totalWeights;
- $rating = $rating/10;
- $rating = round($rating, 1);
- //$rating = $adWeight;
- $playerRating[$steamID] = $rating;
- $playerProbabtion[$steamID] = $scale;
- }
- arsort($playerRating);
- $maxCount = 0;
- foreach($playerRating as $steamID => $rating){
- $combinedArray['players'][$steamID] = $allPlayers[$steamID];
- if($maxCount == 999){
- break;
- }
- $maxCount++;
- }
- chdir('../');
- $file = $dir.".json";
- try{
- //arrayDebug($combinedArray);
- $jsondata = json_encode($combinedArray, JSON_PRETTY_PRINT);
- file_put_contents($file, $jsondata);
- //build heatmaps
- buildHeatmaps($dir);
- //beam me up scotty
- header("Location: build.php");
- }catch (Exception $e) {
- echo 'Status: NotGucci';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement