Merge pull request #21 from OpzekerIT/dev

Fair kd stats (humen vs all kills / deaths)
This commit is contained in:
Lanta 2023-09-25 14:15:00 +02:00 committed by GitHub
commit af2a592c10
11 changed files with 10163 additions and 347 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
config/config.php config/config.php
data/telemetry_cache/*

View file

@ -3,13 +3,13 @@
"type": "player", "type": "player",
"id": "account.3e75bc1560664817900f3747e2270659", "id": "account.3e75bc1560664817900f3747e2270659",
"attributes": { "attributes": {
"name": "Lanta01",
"stats": null,
"titleId": "pubg",
"shardId": "steam", "shardId": "steam",
"patchVersion": "", "patchVersion": "",
"banType": "Innocent", "banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776", "clanId": "clan.d67f3a9805414aa7b78a1f122a7de776"
"name": "Lanta01",
"stats": null,
"titleId": "pubg"
}, },
"relationships": { "relationships": {
"assets": { "assets": {
@ -17,6 +17,14 @@
}, },
"matches": { "matches": {
"data": [ "data": [
{
"type": "match",
"id": "ff8b0997-9faf-4e38-b0b2-a8abb85a1684"
},
{
"type": "match",
"id": "2606363d-8559-47af-84f3-7c5cc32c049d"
},
{ {
"type": "match", "type": "match",
"id": "270a18a6-381e-4dea-bf2c-392382e7fbe6" "id": "270a18a6-381e-4dea-bf2c-392382e7fbe6"
@ -293,13 +301,13 @@
"type": "player", "type": "player",
"id": "account.889799e275e94395aa1a9e66ec3e1ff2", "id": "account.889799e275e94395aa1a9e66ec3e1ff2",
"attributes": { "attributes": {
"stats": null,
"titleId": "pubg", "titleId": "pubg",
"shardId": "steam", "shardId": "steam",
"patchVersion": "", "patchVersion": "",
"banType": "Innocent", "banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776", "clanId": "clan.d67f3a9805414aa7b78a1f122a7de776",
"name": "Petje1972" "name": "Petje1972",
"stats": null
}, },
"relationships": { "relationships": {
"assets": { "assets": {
@ -307,6 +315,34 @@
}, },
"matches": { "matches": {
"data": [ "data": [
{
"type": "match",
"id": "2925480f-5732-4c66-8bb0-d03ac212edb6"
},
{
"type": "match",
"id": "5adb0e00-0604-4117-9734-467f5891e8f5"
},
{
"type": "match",
"id": "2606363d-8559-47af-84f3-7c5cc32c049d"
},
{
"type": "match",
"id": "eb164a8a-bfc1-4bf4-85f1-0951645f32bc"
},
{
"type": "match",
"id": "09ee2eb1-4721-447d-8e9d-9735cbd6f69d"
},
{
"type": "match",
"id": "37ebed06-8c47-485b-9bf5-439e505c29c4"
},
{
"type": "match",
"id": "4711907b-2901-43ee-8c5a-ca22e38ea70a"
},
{ {
"type": "match", "type": "match",
"id": "a54daaad-62b7-4ed9-b9a8-b7fd39fe6a15" "id": "a54daaad-62b7-4ed9-b9a8-b7fd39fe6a15"
@ -483,13 +519,13 @@
"type": "player", "type": "player",
"id": "account.4622686b9d9f44209d64503b18d96a1d", "id": "account.4622686b9d9f44209d64503b18d96a1d",
"attributes": { "attributes": {
"patchVersion": "",
"banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776",
"name": "TaGMoM", "name": "TaGMoM",
"stats": null, "stats": null,
"titleId": "pubg", "titleId": "pubg",
"shardId": "steam" "shardId": "steam",
"patchVersion": "",
"banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776"
}, },
"relationships": { "relationships": {
"assets": { "assets": {
@ -552,38 +588,6 @@
{ {
"type": "match", "type": "match",
"id": "be2dbf4e-8f84-417f-a381-0588f9075deb" "id": "be2dbf4e-8f84-417f-a381-0588f9075deb"
},
{
"type": "match",
"id": "9d324c46-62c1-440c-a9f4-d65a9cd9f184"
},
{
"type": "match",
"id": "56f88a51-7c01-4643-8e64-6ac378e20f8a"
},
{
"type": "match",
"id": "2be7878a-fd39-4b0f-9a82-411e301d5cc9"
},
{
"type": "match",
"id": "192a12e1-4e3a-4652-b6dd-4b30184507d4"
},
{
"type": "match",
"id": "23b2b259-61ad-4dd9-bc79-e6d7943de61b"
},
{
"type": "match",
"id": "17340fd8-32ae-4afd-81f6-faff4370d679"
},
{
"type": "match",
"id": "89b959fd-2b65-4297-a115-698d0727c1a1"
},
{
"type": "match",
"id": "a00aced7-b4d3-43cf-bd6e-d94664a8f55e"
} }
] ]
} }
@ -597,13 +601,13 @@
"type": "player", "type": "player",
"id": "account.b39f1fc9e49b471f8cd9ccce15ad9676", "id": "account.b39f1fc9e49b471f8cd9ccce15ad9676",
"attributes": { "attributes": {
"stats": null,
"titleId": "pubg",
"shardId": "steam", "shardId": "steam",
"patchVersion": "", "patchVersion": "",
"banType": "Innocent", "banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776", "clanId": "clan.d67f3a9805414aa7b78a1f122a7de776",
"name": "r00tger" "name": "r00tger",
"stats": null,
"titleId": "pubg"
}, },
"relationships": { "relationships": {
"assets": { "assets": {
@ -627,20 +631,33 @@
"type": "player", "type": "player",
"id": "account.2322e3d471a5418696b6f14271afd83a", "id": "account.2322e3d471a5418696b6f14271afd83a",
"attributes": { "attributes": {
"patchVersion": "",
"banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776",
"name": "Masistuta", "name": "Masistuta",
"stats": null, "stats": null,
"titleId": "pubg", "titleId": "pubg",
"shardId": "steam", "shardId": "steam"
"patchVersion": "",
"banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776"
}, },
"relationships": { "relationships": {
"assets": {
"data": []
},
"matches": { "matches": {
"data": [ "data": [
{
"type": "match",
"id": "ff8b0997-9faf-4e38-b0b2-a8abb85a1684"
},
{
"type": "match",
"id": "2925480f-5732-4c66-8bb0-d03ac212edb6"
},
{
"type": "match",
"id": "5adb0e00-0604-4117-9734-467f5891e8f5"
},
{
"type": "match",
"id": "2606363d-8559-47af-84f3-7c5cc32c049d"
},
{ {
"type": "match", "type": "match",
"id": "ae90fefb-3f9d-4157-bec0-0c4709ad936c" "id": "ae90fefb-3f9d-4157-bec0-0c4709ad936c"
@ -792,24 +809,11 @@
{ {
"type": "match", "type": "match",
"id": "2be7878a-fd39-4b0f-9a82-411e301d5cc9" "id": "2be7878a-fd39-4b0f-9a82-411e301d5cc9"
},
{
"type": "match",
"id": "192a12e1-4e3a-4652-b6dd-4b30184507d4"
},
{
"type": "match",
"id": "23b2b259-61ad-4dd9-bc79-e6d7943de61b"
},
{
"type": "match",
"id": "89b959fd-2b65-4297-a115-698d0727c1a1"
},
{
"type": "match",
"id": "a00aced7-b4d3-43cf-bd6e-d94664a8f55e"
} }
] ]
},
"assets": {
"data": []
} }
}, },
"links": { "links": {
@ -821,13 +825,13 @@
"type": "player", "type": "player",
"id": "account.275452133d6744d494a1b145da12f75a", "id": "account.275452133d6744d494a1b145da12f75a",
"attributes": { "attributes": {
"titleId": "pubg",
"shardId": "steam",
"patchVersion": "", "patchVersion": "",
"banType": "TemporaryBan", "banType": "TemporaryBan",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776", "clanId": "clan.d67f3a9805414aa7b78a1f122a7de776",
"name": "RalphNorris", "name": "RalphNorris",
"stats": null "stats": null,
"titleId": "pubg",
"shardId": "steam"
}, },
"relationships": { "relationships": {
"assets": { "assets": {
@ -1022,22 +1026,6 @@
{ {
"type": "match", "type": "match",
"id": "05f81d57-7bec-4b79-bb77-bddfd4532911" "id": "05f81d57-7bec-4b79-bb77-bddfd4532911"
},
{
"type": "match",
"id": "89b959fd-2b65-4297-a115-698d0727c1a1"
},
{
"type": "match",
"id": "a00aced7-b4d3-43cf-bd6e-d94664a8f55e"
},
{
"type": "match",
"id": "e3c43fcf-64c6-4463-8d05-6cade0996c3f"
},
{
"type": "match",
"id": "7bb80b83-5587-470b-96ce-58176fdd0821"
} }
] ]
} }
@ -1065,6 +1053,66 @@
}, },
"matches": { "matches": {
"data": [ "data": [
{
"type": "match",
"id": "2b9c4668-e2de-41d0-ab5a-db39ded3ad4c"
},
{
"type": "match",
"id": "4597838f-a317-403c-80be-f872332d29a4"
},
{
"type": "match",
"id": "6d97094c-304b-4d5f-84b8-c97b4d9914f3"
},
{
"type": "match",
"id": "bea1cd04-5de0-40f8-b626-248dbd5ef8e8"
},
{
"type": "match",
"id": "56ba45fc-430c-43c9-9f43-7cac4a5521d4"
},
{
"type": "match",
"id": "20f68f6e-21d4-4fec-a396-701e9e8048db"
},
{
"type": "match",
"id": "88e4800f-aaf9-4a11-9f0f-5aa319026483"
},
{
"type": "match",
"id": "8bffabd7-5027-42ff-974d-71948c21c116"
},
{
"type": "match",
"id": "d1eb616b-ae29-46bd-96a4-9d5e02db2936"
},
{
"type": "match",
"id": "a2bb7007-68c7-4af0-b04b-f297502c5421"
},
{
"type": "match",
"id": "5d795f0a-bd56-4744-aa9c-1769f4b13aba"
},
{
"type": "match",
"id": "ee56af8a-533d-46d1-91ba-e9757702c48b"
},
{
"type": "match",
"id": "effd3894-325a-4026-adaa-f8e21e64cf7d"
},
{
"type": "match",
"id": "d1208de1-0841-4383-9c3f-d340704800f5"
},
{
"type": "match",
"id": "e869949d-c33e-4312-a061-79dee84c1509"
},
{ {
"type": "match", "type": "match",
"id": "a4093c92-0322-4b6d-a78d-8bec8223faa5" "id": "a4093c92-0322-4b6d-a78d-8bec8223faa5"
@ -1189,25 +1237,33 @@
"type": "player", "type": "player",
"id": "account.56ea56d593e440a48c3eaa5613b7eaa0", "id": "account.56ea56d593e440a48c3eaa5613b7eaa0",
"attributes": { "attributes": {
"name": "Shepherders",
"stats": null, "stats": null,
"titleId": "pubg", "titleId": "pubg",
"shardId": "steam", "shardId": "steam",
"patchVersion": "", "patchVersion": "",
"banType": "Innocent", "banType": "Innocent",
"clanId": "clan.d67f3a9805414aa7b78a1f122a7de776" "clanId": "clan.d67f3a9805414aa7b78a1f122a7de776",
"name": "Shepherders"
}, },
"relationships": { "relationships": {
"assets": {
"data": []
},
"matches": { "matches": {
"data": [ "data": [
{
"type": "match",
"id": "42c5aa3d-a85b-4767-bdb2-667b541d3cda"
},
{
"type": "match",
"id": "4e9a4d06-a247-4e7b-99d8-b2c184029566"
},
{ {
"type": "match", "type": "match",
"id": "3efd17c2-cf13-4f64-96d6-6a54af9acb4e" "id": "3efd17c2-cf13-4f64-96d6-6a54af9acb4e"
} }
] ]
},
"assets": {
"data": []
} }
}, },
"links": { "links": {

View file

@ -0,0 +1,77 @@
[
{
"playername": "Lanta01",
"deaths": 56.0,
"kills": 215.0,
"humankills": 66.0,
"matches": 68,
"KD_H": 1.1785714285714286,
"KD_ALL": 3.8392857142857144
},
{
"playername": "Petje1972",
"deaths": 42.0,
"kills": 251.0,
"humankills": 54.0,
"matches": 48,
"KD_H": 1.2857142857142858,
"KD_ALL": 5.976190476190476
},
{
"playername": "TaGMoM",
"deaths": 13.0,
"kills": 42.0,
"humankills": 1.0,
"matches": 14,
"KD_H": 0.07692307692307693,
"KD_ALL": 3.230769230769231
},
{
"playername": "r00tger",
"deaths": 0.0,
"kills": 6.0,
"humankills": 2.0,
"matches": 4,
"KD_H": "Infinity",
"KD_ALL": "Infinity"
},
{
"playername": "Masistuta",
"deaths": 31.0,
"kills": 139.0,
"humankills": 17.0,
"matches": 42,
"KD_H": 0.5483870967741935,
"KD_ALL": 4.483870967741935
},
{
"playername": "RalphNorris",
"deaths": 42.0,
"kills": 80.0,
"humankills": 10.0,
"matches": 47,
"KD_H": 0.23809523809523808,
"KD_ALL": 1.9047619047619047
},
{
"playername": "Jimbo_The_One",
"deaths": 34.0,
"kills": 38.0,
"humankills": 20.0,
"matches": 43,
"KD_H": 0.5882352941176471,
"KD_ALL": 1.1176470588235294
},
{
"playername": "Shepherders",
"deaths": 3.0,
"kills": 4.0,
"humankills": 0.0,
"matches": 3,
"KD_H": 0.0,
"KD_ALL": 1.3333333333333333
},
{
"updated": "09/25/2023 13:52:33 - Time Zone: W. Europe Standard Time"
}
]

File diff suppressed because it is too large Load diff

8828
data/player_matches.json Normal file

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,8 @@
<li><a href="user_stats.php">User Stats</a></li> <li><a href="user_stats.php">User Stats</a></li>
<li><a href="topstats.php">Top10</a></li> <li><a href="topstats.php">Top10</a></li>
<li><a href="topstatsavg.php">Match % T10</a></li> <li><a href="topstatsavg.php">Match % T10</a></li>
<li><a href="latestmatches.php">Last 10 Matches</a></li>
<li><a href="last_stats.php">Last 14 days %</a></li>
</ul> </ul>
</nav> </nav>

80
last_stats.php Normal file
View file

@ -0,0 +1,80 @@
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DTCH - PUBG Clan - Match Stats</title>
<link rel="stylesheet" href="./includes/styles.css">
<script src="./lib/sorttable.js"></script>
</head>
<body>
<?php include './includes/navigation.php'; ?>
<main>
<section>
<h2>Player Stats past 14 days</h2>
<?php
include './config/config.php';
$players_matches = json_decode(file_get_contents('./data/player_last_stats.json'), true);
echo "<table border='1' class='sortable'>";
echo "<tr>
<th>Playername</th>
<th>Deaths</th>
<th>Kills</th>
<th>Human Kills</th>
<th>Matches</th>
<th>K/D (Human)</th>
<th>K/D (All)</th>
</tr>";
foreach ($players_matches as $player_data) {
if (isset($player_data['updated'])) {
continue; // Skip this iteration and move to the next
}
$player_name = $player_data['playername'];
$deaths = number_format($player_data['deaths'], 2, ',', '');
$kills = number_format($player_data['kills'], 2, ',', '');
$humankills = number_format($player_data['humankills'], 2, ',', '');
$matches = $player_data['matches'];
$KD_H = ($player_data['KD_H'] == "Infinity") ? "" : number_format($player_data['KD_H'], 2, ',', '');
$KD_ALL = ($player_data['KD_ALL'] == "Infinity") ? "" : number_format($player_data['KD_ALL'], 2, ',', '');
echo "<tr>
<td>$player_name</td>
<td>$deaths</td>
<td>$kills</td>
<td>$humankills</td>
<td>$matches</td>
<td>$KD_H</td>
<td>$KD_ALL</td>
</tr>";
}
echo "</table>";
echo "Last update: ";
foreach ($players_matches as $player_data) {
if (isset($player_data['updated'])) {
echo $player_data['updated'];
break; // Once found, exit the loop
}
}
?>
</section>
</main>
<?php include './includes/footer.php'; ?>
</body>
</html>

View file

@ -1,53 +1,70 @@
<?php <?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
?>
// Sample data from the API <!DOCTYPE html>
$data = json_decode(file_get_contents('./data/player_data.json'), true); // Replace 'YOUR_JSON_DATA_HERE' with the JSON data you've provided <html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DTCH - PUBG Clan - Match Stats</title>
<link rel="stylesheet" href="./includes/styles.css">
<script src="./lib/sorttable.js"></script>
</head>
<body>
// Extract details <?php include './includes/navigation.php'; ?>
$mapName = $data['data']['attributes']['mapName'];
$matchType = $data['data']['attributes']['matchType'];
$participants = []; <main>
<section>
<h2>Match Stats</h2>
<?php
include './config/config.php';
// Find all participants in the "included" section $players_matches = json_decode(file_get_contents('./data/player_matches.json'), true);
foreach ($data['included'] as $include) {
if ($include['type'] === 'participant') {
$participants[$include['id']] = $include['attributes']['stats'];
}
}
echo '<table border="1">'; // Display buttons for each player
echo '<tr>'; echo "<form method='post' action=''>";
echo '<th>Name</th>'; foreach ($players_matches as $player_data) {
echo '<th>DBNOs</th>'; $player_name = $player_data['playername'];
echo '<th>Assists</th>'; echo "<button type='submit' name='selected_player' value='$player_name' class='btn'>$player_name</button>";
echo '<th>Headshot Kills</th>'; }
echo '<th>Kills</th>'; echo "</form><br>";
echo '<th>Revives</th>';
echo '</tr>'; $selected_player = $_POST['selected_player'] ?? $players_matches[0]['playername'];
// Display the player's match stats
foreach ($players_matches as $player_data) {
if ($player_data['playername'] === $selected_player) {
echo "<h2>Recent Matches for $selected_player</h2>";
echo "<table border='1' class='sortable'>";
echo "<tr><th>Match Date</th><th>Game Mode</th><th>MatchType</th><th>Map</th><th>Kills</th><th>Damage Dealt</th><th>Time Survived</th><th>winPlace</th></tr>";
foreach ($player_data['player_matches'] as $match) {
$date = new DateTime($match['createdAt']);
$date->modify('+2 hours');
$formattedDate = $date->format('d F Y, H:i:s');
$matchType = $match['matchType'];
$gameMode = $match['gameMode'];
$mapName = $match['mapName'];
$kills = $match['stats']['kills'];
$damage = $match['stats']['damageDealt'];
$timeSurvived = $match['stats']['timeSurvived'];
$winPlace = $match['stats']['winPlace'];
echo "<tr><td>$formattedDate</td><td>$gameMode</td><td>$matchType</td><td>$mapName</td><td>$kills</td><td>$damage</td><td>$timeSurvived</td><td>$winPlace</td></tr>";
}
echo "</table><br>";
// Iterate through rosters and link players to participants
foreach ($data['data']['relationships']['rosters']['data'] as $roster) {
foreach ($data['included'] as $include) {
if ($include['type'] === 'roster' && $include['id'] === $roster['id']) {
foreach ($include['relationships']['participants']['data'] as $participant) {
if (isset($participants[$participant['id']])) {
echo '<tr>';
echo '<td>' . $participants[$participant['id']]['name'] . '</td>';
echo '<td>' . $participants[$participant['id']]['DBNOs'] . '</td>';
echo '<td>' . $participants[$participant['id']]['assists'] . '</td>';
echo '<td>' . $participants[$participant['id']]['headshotKills'] . '</td>';
echo '<td>' . $participants[$participant['id']]['kills'] . '</td>';
echo '<td>' . $participants[$participant['id']]['revives'] . '</td>';
echo '</tr>';
} }
} }
} ?>
} </section>
} </main>
echo '</table>'; <?php include './includes/footer.php'; ?>
echo '<p>Map Name: ' . $mapName . '</p>';
echo '<p>Match Type: ' . $matchType . '</p>';
?> </body>
</html>

View file

@ -28,7 +28,7 @@ error_reporting(E_ALL);
$selected_mode = isset($_POST['game_mode']) ? $_POST['game_mode'] : 'squad'; $selected_mode = isset($_POST['game_mode']) ? $_POST['game_mode'] : 'squad';
// Form to select game mode // Form to select game mode
echo "<form method='post' action='' class='sortable'> echo "<form method='post' action=''>
<input type='submit' name='game_mode' value='solo' class='btn'> <input type='submit' name='game_mode' value='solo' class='btn'>
<input type='submit' name='game_mode' value='duo' class='btn'> <input type='submit' name='game_mode' value='duo' class='btn'>
<input type='submit' name='game_mode' value='squad' class='btn'> <input type='submit' name='game_mode' value='squad' class='btn'>

82
update/get_matches.ps1 Normal file
View file

@ -0,0 +1,82 @@
if ($PSScriptRoot.length -eq 0) {
$scriptroot = Get-Location
}
else {
$scriptroot = $PSScriptRoot
}
# Read the content of the file as a single string
$fileContent = Get-Content -Path "$scriptroot/../config/config.php" -Raw
# Use regex to match the apiKey value
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
$apiKey = $matches[1]
}
else {
Write-Output "API Key not found"
}
if ($fileContent -match "\`$clanmembers\s*=\s*array\(([^)]+)\)") {
# Remove quotes and split by comma to get individual members
$clanMembers = ($matches[1] -replace '"|\'', '' -split ","').replace(" ", "")
$clanMembersArray = $clanMembers.split(",").trim()
Write-Output "Clan Members: $($clanMembersArray -join ', ')"
}
else {
Write-Output "Clan members not found"
}
if ($clanMembersArray.count -ge 10 ) {
write-output "Currently not able to process more then 10 players"
exit
}
$headers = @{
'accept' = 'application/vnd.api+json'
'Authorization' = "$apiKey"
}
$player_data = get-content "$scriptroot/../data/player_data.json" | convertfrom-json -Depth 100
$player_matches = @()
foreach ($player in $player_data) {
$lastMatches = $player.relationships.matches.data.id #| Select-Object -First 10
$playermatches = @()
foreach ($match in $lastMatches) {
Write-Host "Getting match for $($player.attributes.name) match: $match "
$stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/matches/$match" -Method GET -Headers $headers
$playermatches += [PSCustomObject]@{
stats = $stats.included.ATTRIBUTES.stats | where-object {$_.name -eq $player.attributes.name}
matchType = $stats.data.attributes.matchtype
gameMode = $stats.data.attributes.gameMode
createdAt = $stats.data.attributes.createdAt
mapName = $stats.data.attributes.mapName
winPlace = $stats.data.attributes.winPlace
telemetry_url = ($stats.included.attributes | Where-Object {$_.name -eq 'telemetry'}).URL
}
}
$obj = [PSCustomObject]@{
playername = $player.attributes.name
player_matches = $playermatches
}
$player_matches += $obj
}
$currentDateTime = Get-Date
# Get current timezone
$currentTimezone = (Get-TimeZone).Id
# Format and parse the information into a string
$formattedString = "$currentDateTime - Time Zone: $currentTimezone"
# Output the formatted string
$player_matches| Add-Member -Name "updated" -MemberType NoteProperty -Value $formattedString
$player_matches | convertto-json -Depth 100 | out-file "$scriptroot/../data/player_matches.json"

97
update/matchparser.ps1 Normal file
View file

@ -0,0 +1,97 @@
if($PSScriptRoot.length -eq 0){
$scriptroot = Get-Location
}else{
$scriptroot = $PSScriptRoot
}
function get-killstats {
param (
$player_name,
$telemetry
)
$attacks = @()
foreach ($action in $telemetry) {
if ($action.PSObject.Properties.name.contains('killer')) {
#write-output "Analyzing dBNOid $($action.dBNOId)"
$attacks += $action
}
}
$kills = $attacks | where-object { $_.killer.name -eq $player_name }
return @{
playername = $player_name
humankills = ($kills | where-object { $_.victim.accountId -notlike 'ai.*' }).count
kills = $kills.count
deaths = ($attacks | where-object { $_.victim.name -eq $player_name }).count
}
}
$all_player_matches = get-content "$scriptroot/../data/player_matches.json" | convertfrom-json -Depth 100
$killstats = @()
foreach ($player in $all_player_matches) {
$player_name = $player.playername
foreach ($match in $player.player_matches) {
$telemetryfile = "$scriptroot/../data/telemetry_cache/$($match.telemetry_url.split("/")[-1])"
if (!(test-path -Path $telemetryfile)) {
write-output "Saving $telemetryfile"
$telemetry_content = (Invoke-WebRequest -Uri $match.telemetry_url).content
$telemetry_content | out-file $telemetryfile
$telemetry = $telemetry_content | ConvertFrom-Json
}else{
write-output "Getting from cache $telemetryfile"
$telemetry = get-content $telemetryfile | convertfrom-json
}
write-output "Analyzing for player $player_name telemetry: $($match.telemetry_url)"
$killstats += get-killstats -player_name $player_name -telemetry $telemetry
}
}
$playerstats = @()
foreach ($player in $all_player_matches.playername) {
$deaths = (($killstats | where-object { $_.playername -eq $player }).deaths | Measure-Object -sum).sum
$kills = (($killstats | where-object { $_.playername -eq $player }).kills | Measure-Object -sum).sum
$humankills = (($killstats | where-object { $_.playername -eq $player }).humankills | Measure-Object -sum).sum
$playerstats += [PSCustomObject]@{
playername = $player
deaths = $deaths
kills = $kills
humankills = $humankills
matches = ($killstats | where-object { $_.playername -eq $player }).count
KD_H = $humankills / $deaths
KD_ALL = $kills / $deaths
}
}
$currentDateTime = Get-Date
# Get current timezone
$currentTimezone = (Get-TimeZone).Id
# Format and parse the information into a string
$formattedString = "$currentDateTime - Time Zone: $currentTimezone"
# Output the formatted string
$playerstats += [PSCustomObject]@{
updated = $formattedString
}
($playerstats | convertto-json) | out-file "$scriptroot/../data/player_last_stats.json"