next update for top10 and more
This commit is contained in:
parent
b33f6a43c7
commit
d5d1b0b7a5
5 changed files with 116 additions and 8 deletions
|
|
@ -3,5 +3,6 @@
|
|||
<li><a href="index.php">Home</a></li>
|
||||
<li><a href="clan_stats.php">Clan Stats</a></li>
|
||||
<li><a href="user_stats.php">User Stats</a></li>
|
||||
<li><a href="topstats.php">Top10</a></li>
|
||||
</ul>
|
||||
</nav>
|
||||
|
|
|
|||
66
topstats.php
Normal file
66
topstats.php
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
<?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 - User Stats</title>
|
||||
<link rel="stylesheet" href="./includes/styles.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php include './includes/navigation.php'; ?>
|
||||
|
||||
<main>
|
||||
<section>
|
||||
<h2>User Stats</h2>
|
||||
<?php
|
||||
include './config/config.php';
|
||||
|
||||
$players_data = json_decode(file_get_contents('./data/player_lifetime_data.json'), true);
|
||||
$selected_mode = isset($_POST['game_mode']) ? $_POST['game_mode'] : 'squad';
|
||||
|
||||
// Form to select game mode
|
||||
echo "<form method='post' action=''>
|
||||
<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='squad' class='btn'>
|
||||
</form><br>";
|
||||
|
||||
// Displaying top 10 comparisons for each attribute
|
||||
$attributes = ['dBNOs', 'damageDealt', 'roadKills', 'teamKills'];
|
||||
foreach ($attributes as $attribute) {
|
||||
echo "<h3>Top 10 $attribute</h3>";
|
||||
uasort($players_data[$selected_mode], function ($a, $b) use ($attribute) {
|
||||
$account_id_a = array_key_first($a);
|
||||
$account_id_b = array_key_first($b);
|
||||
return $b[$account_id_b][$attribute] <=> $a[$account_id_a][$attribute]; // Sort in descending order
|
||||
});
|
||||
|
||||
echo "<table border='1'>";
|
||||
echo "<tr><th>Player</th><th>$attribute</th></tr>";
|
||||
$count = 0;
|
||||
foreach ($players_data[$selected_mode] as $player_name => $player_details) {
|
||||
if ($count++ >= 10) break; // Limit to top 10 players
|
||||
$account_id = array_key_first($player_details);
|
||||
echo "<tr><td>$player_name</td><td>{$player_details[$account_id][$attribute]}</td></tr>";
|
||||
}
|
||||
echo "</table><br>";
|
||||
}
|
||||
|
||||
echo "Last update " ;
|
||||
echo $players_data['updated'];
|
||||
?>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<?php include './includes/footer.php'; ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
|
||||
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 "../config/config.php" -Raw
|
||||
$fileContent = Get-Content -Path "$scriptroot/../config/config.php" -Raw
|
||||
|
||||
# Use regex to match the apiKey value
|
||||
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
|
||||
|
|
@ -14,12 +19,25 @@ if ($fileContent -match "\`$clanid\s*=\s*\'([^\']+)\'") {
|
|||
} else {
|
||||
Write-Output "No clanid found in $configPath"
|
||||
}
|
||||
|
||||
|
||||
|
||||
$headers = @{
|
||||
'accept' = 'application/vnd.api+json'
|
||||
'Authorization' = "$apiKey"
|
||||
}
|
||||
$claninfo = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/clans/$clanid" -Method GET -Headers $headers
|
||||
$claninfo.data.attributes | convertto-json -Depth 100 | out-file '../data/claninfo.json'
|
||||
|
||||
# Get current date and time
|
||||
$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
|
||||
|
||||
|
||||
[PSCustomObject]$clandata = $claninfo.data.attributes
|
||||
$clandata | Add-Member -Name "updated" -MemberType NoteProperty -Value $formattedString
|
||||
$clandata | convertto-json -Depth 100 | out-file "$scriptroot/../data/claninfo.json"
|
||||
|
||||
$clandata | convertto-json -Depth 100
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
|
||||
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 "../config/config.php" -Raw
|
||||
$fileContent = Get-Content -Path "$scriptroot/../config/config.php" -Raw
|
||||
|
||||
# Use regex to match the apiKey value
|
||||
if ($fileContent -match "\`$apiKey\s*=\s*\'([^\']+)\'") {
|
||||
|
|
@ -64,6 +69,7 @@ $webrequestlimiter = 0
|
|||
foreach ($playmode in $playermodes) {
|
||||
# Fetch stats for the current playmode
|
||||
if($webrequestlimiter -le 8){
|
||||
write-output "Getting data for players $playeridstring gameode $playmode"
|
||||
$stats = Invoke-RestMethod -Uri "https://api.pubg.com/shards/steam/seasons/lifetime/gameMode/$playmode/players?filter[playerIds]=$playeridstring" -Method GET -Headers $headers
|
||||
$webrequestlimiter++
|
||||
}else{
|
||||
|
|
@ -80,7 +86,7 @@ foreach ($playmode in $playermodes) {
|
|||
|
||||
# Fetch the player name for the current stat (account ID) from the dictionary
|
||||
$playerName = $playerList | Where-Object { $_.PlayerID -eq $stat } | Select-Object -ExpandProperty PlayerName
|
||||
|
||||
write-output "Getting data for $playerName with gamemode $playmode"
|
||||
# Fetch the specific stat data for the current stat
|
||||
$specificStat = ($stats.data | where-object {$_.relationships.player.data.id -eq $stat}).attributes.gamemodestats.$playmode
|
||||
|
||||
|
|
@ -91,4 +97,19 @@ foreach ($playmode in $playermodes) {
|
|||
$lifetimestats[$playmode][$playerName][$stat] = $specificStat
|
||||
}
|
||||
}
|
||||
$lifetimestats | convertto-json -Depth 100 | out-file '../data/player_lifetime_data.json'
|
||||
|
||||
|
||||
|
||||
# Get current date and time
|
||||
$currentDateTime = Get-Date
|
||||
|
||||
# Get current timezone
|
||||
$currentTimezone = (Get-TimeZone).Id
|
||||
|
||||
# Format and parse the information into a string
|
||||
$formattedString = "$currentDateTime - Time Zone: $currentTimezone"
|
||||
$lifetimestats['updated']= $formattedString
|
||||
# Output the formatted string
|
||||
|
||||
|
||||
$lifetimestats | convertto-json -Depth 100 | out-file "$scriptroot/../data/player_lifetime_data.json"
|
||||
|
|
@ -58,6 +58,8 @@ error_reporting(E_ALL);
|
|||
} else {
|
||||
echo "No player data available.";
|
||||
}
|
||||
echo "Last update " ;
|
||||
echo $players_data['updated'];
|
||||
?>
|
||||
</section>
|
||||
</main>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue