From 9c6d1501bc56615b398d487cb7ce5f5cf75079c5 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 14:57:04 +0100 Subject: [PATCH 01/10] archiving and building matches caches file --- update/get_matches.ps1 | 44 +++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/update/get_matches.ps1 b/update/get_matches.ps1 index 376ab26..5430119 100644 --- a/update/get_matches.ps1 +++ b/update/get_matches.ps1 @@ -12,7 +12,7 @@ new-lock -by "get_matches" # Read the content of the file as a single string $fileContent = Get-Content -Path "$scriptroot/../config/config.php" -Raw - +$players = (Get-Content -Path "$scriptroot/../config/clanmembers.json" | ConvertFrom-Json).clanmembers # Use regex to match the apiKey value if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") { $apiKey = $matches[1] @@ -34,10 +34,11 @@ foreach ($player in $player_data) { $playermatches = @() foreach ($match in $lastMatches) { Write-Host "Getting match for $($player.attributes.name) match: $match " - if(Test-Path "$scriptroot/../data/matches/$match.json"){ + if (Test-Path "$scriptroot/../data/matches/$match.json") { write-output "Getting $match from cache" $stats = get-content "$scriptroot/../data/matches/$match.json" | convertfrom-json - }else{ + } + else { $stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/matches/$match" -Method GET -Headers $headers $stats | ConvertTo-Json -Depth 100 | Out-File "$scriptroot/../data/matches/$match.json" } @@ -66,8 +67,8 @@ foreach ($player in $player_data) { if (test-path "$scriptroot/../data/player_matches.json") { $old_player_data = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100 - $new_ids = ($player_matches.player_matches | where-object {$_.stats.winplace -eq 1}).id - $old_ids = ($old_player_data.player_matches | where-object {$_.stats.winplace -eq 1}).id + $new_ids = ($player_matches.player_matches | where-object { $_.stats.winplace -eq 1 }).id + $old_ids = ($old_player_data.player_matches | where-object { $_.stats.winplace -eq 1 }).id $new_win_matches = ((Compare-Object -ReferenceObject $old_ids -DifferenceObject $new_ids) | Where-Object { $_.SideIndicator -eq '=>' }).InputObject | Select-Object -Unique $new_win_matches = $old_player_data.new_win_matches + $new_win_matches | Select-Object -Unique $player_matches += [PSCustomObject]@{ @@ -76,8 +77,6 @@ if (test-path "$scriptroot/../data/player_matches.json") { } - - $currentDateTime = Get-Date # Get current timezone @@ -92,5 +91,36 @@ $playermatches += [PSCustomObject]@{ $player_matches | convertto-json -Depth 100 | out-file "$scriptroot/../data/player_matches.json" +write-output 'Cleaning matches' + +$matchfiles = Get-ChildItem "$scriptroot/../data/matches" -Filter *.json +$player_matches_object = @() +foreach ($file in $matchfiles) { + $filecontent = get-content $file | convertfrom-json + $matchfiledate = $filecontent.data.attributes.createdAt + if ($matchfiledate -lt (get-date).AddMonths(-1)) { + write-output "archiving $matchfiledate" + Move-Item -Path $file -Destination "$scriptroot/../data/matches/archive" + } + else { + $result = ($filecontent.included | where-object { $_.type -eq 'participant' } | Where-Object { $players -contains $_.attributes.stats.name }) + $filecontent.data.id + $result.count + $player_matches_cached = ($filecontent.included | where-object { $_.type -eq 'participant' } | Where-Object { $players -contains $_.attributes.stats.name }).attributes.stats + if ($null -ne $player_matches_cached) { + $player_matches_object += [PSCustomObject]@{ + matchType = $filecontent.data.attributes.matchType + gameMode = $filecontent.data.attributes.gameMode + createdAt = $filecontent.data.attributes.createdAt + mapName = $filecontent.data.attributes.mapName + id = $filecontent.data.id + stats = $player_matches_cached + } + } + write-output "NEW $matchfiledate" + } +} +$player_matches_object | convertto-json -Depth 100 | out-file "$scriptroot/../data/cached_matches.json" + remove-lock Stop-Transcript \ No newline at end of file From fc970ca59eec60ae9abcae4ef995374d33756fd6 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:06:58 +0100 Subject: [PATCH 02/10] $player --- latestmatches.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/latestmatches.php b/latestmatches.php index bebccf0..1349129 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -20,15 +20,15 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo "; - foreach ($players_matches as $player_data) { - if (isset($player_data['playername'])) { - $player_name = $player_data['playername']; - echo ""; - } + foreach ($players['clanMembers'] as $player) { + + echo ""; + } echo "
"; $selected_player = $_GET['selected_player'] ?? $players_matches[0]['playername']; From 37a261bfea1d93e8da0921383fb4fa4758df1072 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:16:02 +0100 Subject: [PATCH 03/10] $selected_match --- latestmatches.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/latestmatches.php b/latestmatches.php index 1349129..956428d 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -31,7 +31,7 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo } echo "
"; - $selected_player = $_GET['selected_player'] ?? $players_matches[0]['playername']; + $selected_player = $_GET['selected_player'] ?? $players[0]; echo "
@@ -57,8 +57,8 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo "Tiger_Main" => "Taego" ); // Display the player's match stats - foreach ($players_matches as $player_data) { - if (isset($player_data['playername']) && $player_data['playername'] === $selected_player) { + foreach ($players_matches as $selected_match) { + if (isset($selected_match['stats']['name']) === $selected_player) { echo "

Recent Matches for $selected_player

"; echo ""; From bc50b85890637f4f931b3383c0a0c8090692b2d7 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:17:52 +0100 Subject: [PATCH 04/10] debug --- latestmatches.php | 1 + 1 file changed, 1 insertion(+) diff --git a/latestmatches.php b/latestmatches.php index 956428d..1ae4876 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -58,6 +58,7 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo ); // Display the player's match stats foreach ($players_matches as $selected_match) { + print_r($selected_match); if (isset($selected_match['stats']['name']) === $selected_player) { echo "

Recent Matches for $selected_player

"; From 601779a983e376675e6227d32d1e9b4b59653c2d Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:19:10 +0100 Subject: [PATCH 05/10] names --- latestmatches.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latestmatches.php b/latestmatches.php index 1ae4876..29e4392 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -58,7 +58,7 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo ); // Display the player's match stats foreach ($players_matches as $selected_match) { - print_r($selected_match); + print_r($selected_match['stats']['name']); if (isset($selected_match['stats']['name']) === $selected_player) { echo "

Recent Matches for $selected_player

"; From b2fa4b62ac2bf4334b3305b641a869d15f4f5d25 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:20:22 +0100 Subject: [PATCH 06/10] fix --- latestmatches.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/latestmatches.php b/latestmatches.php index 29e4392..d5dc4c1 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -59,7 +59,7 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo // Display the player's match stats foreach ($players_matches as $selected_match) { print_r($selected_match['stats']['name']); - if (isset($selected_match['stats']['name']) === $selected_player) { + if ($selected_match['stats']['name'] === $selected_player) { echo "

Recent Matches for $selected_player

"; echo "
"; From d53a2de62cd851c06d6105da545c1a5f530ab315 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:25:27 +0100 Subject: [PATCH 07/10] fix --- latestmatches.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/latestmatches.php b/latestmatches.php index d5dc4c1..cbc76fd 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -57,20 +57,18 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo "Tiger_Main" => "Taego" ); // Display the player's match stats - foreach ($players_matches as $selected_match) { - print_r($selected_match['stats']['name']); - if ($selected_match['stats']['name'] === $selected_player) { + echo "

Recent Matches for $selected_player

"; + echo "
"; + echo ""; + foreach ($players_matches as $match) { + if ($match['stats']['name'] === $selected_player) { - echo "

Recent Matches for $selected_player

"; - echo "
Match DateGame ModeMatch TypeMapKillsDamage DealtTime Survivedwin Place
"; - echo ""; + foreach ($player_data['player_matches'] as $match) { if (isset($_GET['filter_by_match_type'])) { if ($_GET['filter_by_match_type'] !== 'all' && $match['matchType'] !== $_GET['filter_by_match_type']) { continue; } - - } $date = new DateTime($match['createdAt']); $date->modify('+1 hours'); From 9bd4c304b86ab8fbfcea2e797d92d159ca1c7dc0 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:27:04 +0100 Subject: [PATCH 08/10] fix --- latestmatches.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/latestmatches.php b/latestmatches.php index cbc76fd..e098019 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -9,10 +9,10 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo - + ?>
@@ -26,9 +26,9 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo // Display buttons for each player echo ""; foreach ($players['clanMembers'] as $player) { - - echo ""; - + + echo ""; + } echo "
"; $selected_player = $_GET['selected_player'] ?? $players[0]; @@ -63,12 +63,10 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo foreach ($players_matches as $match) { if ($match['stats']['name'] === $selected_player) { - - foreach ($player_data['player_matches'] as $match) { - if (isset($_GET['filter_by_match_type'])) { - if ($_GET['filter_by_match_type'] !== 'all' && $match['matchType'] !== $_GET['filter_by_match_type']) { - continue; - } + + if (isset($_GET['filter_by_match_type'])) { + if ($_GET['filter_by_match_type'] !== 'all' && $match['matchType'] !== $_GET['filter_by_match_type']) { + continue; } $date = new DateTime($match['createdAt']); $date->modify('+1 hours'); From f9add0ef203e22db27cedf2601c1b409b5f49183 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:29:52 +0100 Subject: [PATCH 09/10] table --- latestmatches.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/latestmatches.php b/latestmatches.php index e098019..71ef2fd 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -91,10 +91,12 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo "; } - echo "
Match DateGame ModeMatch TypeMapKillsDamage DealtTime Survivedwin Place

"; + } + } + echo "
"; ?> From 23b7ddac83b71c1d9afcc37613116ce9591f2c31 Mon Sep 17 00:00:00 2001 From: Lanta Date: Wed, 22 Nov 2023 15:31:04 +0100 Subject: [PATCH 10/10] if statement --- latestmatches.php | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/latestmatches.php b/latestmatches.php index 71ef2fd..be2bd21 100644 --- a/latestmatches.php +++ b/latestmatches.php @@ -68,18 +68,19 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo if ($_GET['filter_by_match_type'] !== 'all' && $match['matchType'] !== $_GET['filter_by_match_type']) { continue; } - $date = new DateTime($match['createdAt']); - $date->modify('+1 hours'); - $formattedDate = $date->format('m-d H:i:s'); + } + $date = new DateTime($match['createdAt']); + $date->modify('+1 hours'); + $formattedDate = $date->format('m-d H:i:s'); - $matchType = $match['matchType']; - $gameMode = $match['gameMode']; - $mapName = isset($mapNames[$match['mapName']]) ? $mapNames[$match['mapName']] : $match['mapName']; - $kills = $match['stats']['kills']; - $damage = number_format($match['stats']['damageDealt'], 0, '.', ''); - $timeSurvived = $match['stats']['timeSurvived']; - $winPlace = $match['stats']['winPlace']; - echo " + $matchType = $match['matchType']; + $gameMode = $match['gameMode']; + $mapName = isset($mapNames[$match['mapName']]) ? $mapNames[$match['mapName']] : $match['mapName']; + $kills = $match['stats']['kills']; + $damage = number_format($match['stats']['damageDealt'], 0, '.', ''); + $timeSurvived = $match['stats']['timeSurvived']; + $winPlace = $match['stats']['winPlace']; + echo " " . $formattedDate . " " . $gameMode . " " . $matchType . " @@ -90,11 +91,11 @@ $ogDescription = "Dive into the detailed match stats of DTCH Clan in PUBG. Explo " . $winPlace . " "; - } - + + } - + } echo "
"; ?>