<commit_before><?php

define('DATAVERSION', '2');

require_once('includes/functions.include.php');

// Initialize connexion to database
$pdo = newDBConnection();
foreach ($_GET as &$thing) {
	$thing = secure($pdo, $thing);
}
// Get users to track
$query = rawSelect($pdo, "SELECT * FROM usersToTrack ORDER BY region, summonerId");

// If REMOTE_ADDR ain't set, it's that we're doing this request locally
$ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : "local";

date_default_timezone_set('Europe/Berlin');
$header = "> ".date('d/m/Y H:i:s', time())." - Request by ".$ip.PHP_EOL/*IDE*/;
logAccess($header);/*;3*/
echo $header;

$countTotalMatches = 0;
// Si la requête retourne des résultats
if (count($query) > 0) {
	$countPlayers = 0;
	// For each player
	while ($row = $query->fetch()) {
		// Only used to log informations
		$countPlayers += 1;
		$countNewMatches = 0;

		// Preparing cURL
		$region = strtolower($row['region']);
		$sId = $row['summonerId'];
		$c = curl_init();
		$json = apiGame($c, $region, $sId);
		curl_close($c);
		// Transform json in an Array
		$array = json_decode($json, true);

		if (isset($array['status']) && $array['status']!= "") {
			logError($array['error']);
		} else {
			$matches = $array['games'];

			foreach ($matches as $match) {
			
				// Converting the epoch to Datetime
				$epochCreateDate = $match['createDate'];
				//echo "<br>"."EPOCH: ".$epochCreateDate;
				$DTCreateDate = new DateTime("@$epochCreateDate");
			
				/*
				First we need to match every stat in the json file to a column in the database.
				We'll put things in 3 different tables :
				- games   
				- data    
				- players 
				*/

				/* Every field that is null means it's simply the same
				name as the one in the API and needs no other treatment.
				*/
								
				// Table 'games'
				$games = array (
					"gameId" => null,
					"region" => $region,
					"createDate" => $DTCreateDate->format("Y-m-d H:i:s"),
					"gameMode" => null,
					"gameType" => null,
					"subType" => null,
					"duration" => '0',
					"mapId" => null,
					"invalid" => null,
					"dataVersion" => DATAVERSION, 
					"dataIp" => $_SERVER['REMOTE_ADDR']
				);
				foreach ($games as $key => $value) {
					if (is_null($value)) $value = $match[$key];
				}
				
				// Table 'dates'
				$data = array (
					"gameId" => $match['gameId'], 
					"summonerId" => $sId, 
					"region" => $region, 
					"goldEarned" => null, 
					"championsKilled" => null, 
					"numDeaths" => null, 
					"assists" => null, 
					"minionsKilled" => null, 
					"spell1" => $match['spell1'], 
					"spell2" => $match['spell2'], 
					"item0" => null, 
					"item1" => null, 
					"item2" => null, 
					"item3" => null, 
					"item4" => null, 
					"item5" => null, 
					"item6" => null, 
					"largestMultiKill" => null, 
					"largestKillingSpree" => null, 
					"turretsKilled" => null, 
					"totalHeal" => null, 
					"invalid" => null, 
					"totalDamageDealtToChampions" => null, 
					"physicalDamageDealtToChampions" => null, 
					"magicDamageDealtToChampions" => null, 
					"trueDamageDealtToChampions" => null, 
					"totalDamageDealt" => null, 
					"physicalDamageDealtPlayer" => null, 
					"magicDamageDealtPlayer" => null, 
					"trueDamageDealtPlayer" => null, 
					"totalDamageTaken" => null, 
					"physicalDamageTaken" => null, 
					"magicDamageTaken" => null, 
					"trueDamageTaken" => null, 
					"sightWardsBought" => null, 
					"visionWardsBought" => null, 
					"neutralMinionsKilled" => null, 
					"neutralMinionsKilledYourJungle" => null, 
					"neutralMinionsKilledEnemyJungle" => null, 
					"level" => null, 
					"wardPlaced" => null, 
					"wardKilled" => null, 
					"summonerLevel" => null, 
					"totalTimeCrowdControlDealt" => null, 
					"largestCriticalStrike" => null, 
					"win" => null, 
					"barracksKilled" => null, 
					"totalScoreRank" => null, 
					"objectivePlayerScore" => null, 
					"victoryPointTotal" => null, 
					"nodeCaptureAssist" => null, 
					"totalPlayerScore" => null, 
					"nodeCapture" => null, 
					"nodeNeutralize" => null, 
					"nodeNeutralizeAssist" => null, 
					"teamObjective" => null, 
					"combatPlayerScore" => null, 
					"consumablesPurchased" => null, 
					"firstBlood" => null, 
					"spell1Cast" => null, 
					"spell2Cast" => null, 
					"spell3Cast" => null, 
					"spell4Cast" => null, 
					"summonSpell1Cast" => null, 
					"summonSpell2Cast" => null, 
					"superMonsterKilled" => null, 
					"timePlayed" => null, 
					"unrealKills" => null, 
					"doubleKills" => null, 
					"tripleKills" => null, 
					"quadraKills" => null, 
					"pentaKills" => null, 
					"nexusKilled" => null, 
					"gold" => null, 
					"itemsPurchased" => null, 
					"numItemsBought" => null, 
					"dataVersion" => DATAVERSION, 
					"dataIp" => $_SERVER['REMOTE_ADDR']
				);
				foreach ($data as $key => $value) {
					if (is_null($value)) $value = $match['stats'][$key];
				}


				// Matching columns in "players" with API
				$players = array();
				foreach ($match['fellowPlayers'] as $player) {
					$players[] = array (	
						"gameId" => $match['gameId'],<commit_msg>I don't know how to code lol. Hi.<commit_after><?php

define('DATAVERSION', '3');

require_once('includes/functions.include.php');

// Initialize connexion to database
$pdo = newDBConnection();
foreach ($_GET as &$thing) {
	$thing = secure($pdo, $thing);
}
// Get users to track
$query = rawSelect($pdo, "SELECT * FROM usersToTrack ORDER BY region, summonerId");

// If REMOTE_ADDR ain't set, it's that we're doing this request locally
$ip = (isset($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : "local";

date_default_timezone_set('Europe/Berlin');
$header = "> ".date('d/m/Y H:i:s', time())." - Request by ".$ip.PHP_EOL/*IDE*/;
logAccess($header);/*;3*/
echo $header;

$countTotalMatches = 0;
// Si la requête retourne des résultats
if (count($query) > 0) {
	$countPlayers = 0;
	// For each player
	while ($row = $query->fetch()) {
		// Only used to log informations
		$countPlayers += 1;
		$countNewMatches = 0;

		// Preparing cURL
		$region = strtolower($row['region']);
		$sId = $row['summonerId'];
		$c = curl_init();
		$json = apiGame($c, $region, $sId);
		curl_close($c);
		// Transform json in an Array
		$array = json_decode($json, true);

		if (isset($array['status']) && $array['status']!= "") {
			logError($array['error']);
		} else {
			$matches = $array['games'];

			foreach ($matches as $match) {
			
				// Converting the epoch to Datetime
				$epochCreateDate = $match['createDate'];
				//echo "<br>"."EPOCH: ".$epochCreateDate;
				$DTCreateDate = new DateTime("@$epochCreateDate");
			
				/*
				First we need to match every stat in the json file to a column in the database.
				We'll put things in 3 different tables :
				- games   
				- data    
				- players 
				*/

				/* Every field that is null means it's simply the same
				name as the one in the API and needs no other treatment.
				*/
								
				// Table 'games'
				$games = array (
					"gameId" => null,
					"region" => $region,
					"createDate" => $DTCreateDate->format("Y-m-d H:i:s"),
					"gameMode" => null,
					"gameType" => null,
					"subType" => null,
					"duration" => '0',
					"mapId" => null,
					"invalid" => null,
					"dataVersion" => DATAVERSION, 
					"dataIp" => $_SERVER['REMOTE_ADDR']
				);
				foreach ($games as $key => $value) {
					if (is_null($value)) {$games[$key] = $match[$key];}
				}
				
				// Table 'dates'
				$data = array (
					"gameId" => $match['gameId'], 
					"summonerId" => $sId, 
					"region" => $region, 
					"goldEarned" => null, 
					"championsKilled" => null, 
					"numDeaths" => null, 
					"assists" => null, 
					"minionsKilled" => null, 
					"spell1" => $match['spell1'], 
					"spell2" => $match['spell2'], 
					"item0" => null, 
					"item1" => null, 
					"item2" => null, 
					"item3" => null, 
					"item4" => null, 
					"item5" => null, 
					"item6" => null, 
					"largestMultiKill" => null, 
					"largestKillingSpree" => null, 
					"turretsKilled" => null, 
					"totalHeal" => null, 
					"invalid" => null, 
					"totalDamageDealtToChampions" => null, 
					"physicalDamageDealtToChampions" => null, 
					"magicDamageDealtToChampions" => null, 
					"trueDamageDealtToChampions" => null, 
					"totalDamageDealt" => null, 
					"physicalDamageDealtPlayer" => null, 
					"magicDamageDealtPlayer" => null, 
					"trueDamageDealtPlayer" => null, 
					"totalDamageTaken" => null, 
					"physicalDamageTaken" => null, 
					"magicDamageTaken" => null, 
					"trueDamageTaken" => null, 
					"sightWardsBought" => null, 
					"visionWardsBought" => null, 
					"neutralMinionsKilled" => null, 
					"neutralMinionsKilledYourJungle" => null, 
					"neutralMinionsKilledEnemyJungle" => null, 
					"level" => null, 
					"wardPlaced" => null, 
					"wardKilled" => null, 
					"summonerLevel" => null, 
					"totalTimeCrowdControlDealt" => null, 
					"largestCriticalStrike" => null, 
					"win" => null, 
					"barracksKilled" => null, 
					"totalScoreRank" => null, 
					"objectivePlayerScore" => null, 
					"victoryPointTotal" => null, 
					"nodeCaptureAssist" => null, 
					"totalPlayerScore" => null, 
					"nodeCapture" => null, 
					"nodeNeutralize" => null, 
					"nodeNeutralizeAssist" => null, 
					"teamObjective" => null, 
					"combatPlayerScore" => null, 
					"consumablesPurchased" => null, 
					"firstBlood" => null, 
					"spell1Cast" => null, 
					"spell2Cast" => null, 
					"spell3Cast" => null, 
					"spell4Cast" => null, 
					"summonSpell1Cast" => null, 
					"summonSpell2Cast" => null, 
					"superMonsterKilled" => null, 
					"timePlayed" => null, 
					"unrealKills" => null, 
					"doubleKills" => null, 
					"tripleKills" => null, 
					"quadraKills" => null, 
					"pentaKills" => null, 
					"nexusKilled" => null, 
					"gold" => null, 
					"itemsPurchased" => null, 
					"numItemsBought" => null, 
					"dataVersion" => DATAVERSION, 
					"dataIp" => $_SERVER['REMOTE_ADDR']
				);
				foreach ($data as $key => $value) {
					if (is_null($value)) {$data[$key] = $match['stats'][$key];}
				}


				// Matching columns in "players" with API
				$players = array();
				foreach ($match['fellowPlayers'] as $player) {
					$players[] = array (	
						"gameId" => $match['gameId'],
{'fraction_non_alphanumeric': 0.17201503324660306, 'fraction_numerical': 0.005011082201021489, 'mean_word_length': 2.829520295202952, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 197, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1290536', 'n_tokens_mistral': 4790, 'n_tokens_neox': 3725, 'n_words': 804}