This commit is contained in:
Lanta 2025-04-15 17:12:33 +02:00
parent 1be9732279
commit 01aa843d0b
18 changed files with 4122 additions and 2393 deletions

View file

@ -1,67 +1,127 @@
<?php
// --- Configuration and Data Fetching ---
$ogDescription = "Discover comprehensive average statistics for PUBG players. Dive into player performance across various game modes including solo, duo, and squad, and explore key metrics like Kills, Damage, Headshots, Wins, and Top10s. Stay updated with the latest statistical trends in PUBG gaming.";
// Include config if it exists
$configPath = './config/config.php';
if (file_exists($configPath)) {
include $configPath;
}
$players_data = null;
$playerAverages = [];
$dataError = '';
$lastUpdated = 'N/A';
$availableModes = ['solo', 'duo', 'squad', 'solo-fpp', 'duo-fpp', 'squad-fpp']; // Define available modes (expanded for consistency)
$metrics = [
'Kills' => 'kills',
'Damage' => 'damageDealt',
'Headshots' => 'headshotKills',
'Wins' => 'wins',
'Top10s' => 'top10s'
];
// Determine selected game mode (using GET for consistency)
$selected_mode = isset($_GET['game_mode']) && in_array($_GET['game_mode'], $availableModes) ? $_GET['game_mode'] : 'squad';
// Load player lifetime data
$dataPath = './data/player_lifetime_data.json';
if (file_exists($dataPath)) {
$jsonData = file_get_contents($dataPath);
$players_data = json_decode($jsonData, true);
if (!is_array($players_data)) {
$dataError = "Error decoding player lifetime data.";
$players_data = null; // Ensure it's null if decoding failed
} else {
$lastUpdated = htmlspecialchars($players_data['updated'] ?? 'N/A');
// Check if the selected mode exists in the data
if (isset($players_data[$selected_mode]) && is_array($players_data[$selected_mode])) {
// Calculate averages for each player in the selected mode
foreach ($players_data[$selected_mode] as $player_name => $player_details) {
$account_id = array_key_first($player_details);
if ($account_id && isset($player_details[$account_id])) {
$stats = $player_details[$account_id];
// Ensure necessary stats exist before calculation
$wins = $stats['wins'] ?? 0;
$losses = $stats['losses'] ?? 0;
$totalGames = $wins + $losses;
$averages = [];
foreach ($metrics as $metricKey) {
$statValue = $stats[$metricKey] ?? 0;
$averages[$metricKey] = ($totalGames > 0) ? round($statValue / $totalGames, 2) : 0;
}
$playerAverages[$player_name] = $averages;
}
}
if (empty($playerAverages)) {
$dataError = "No player stats found to calculate averages for mode: " . htmlspecialchars($selected_mode);
}
} else {
$dataError = "Selected game mode (" . htmlspecialchars($selected_mode) . ") not found in data.";
}
}
} else {
$dataError = "Player lifetime data file not found.";
}
?>
<!DOCTYPE html>
<html lang="en">
<?php include './includes/head.php'; ?>
<?php include './includes/head.php'; // Includes $ogDescription ?>
<body>
<?php
<?php
include './includes/navigation.php';
include './includes/header.php';
?>
?>
<main>
<section>
<h2>Average 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';
<?php if ($dataError): ?>
<p style="color: red;"><?php echo htmlspecialchars($dataError); ?></p>
<?php endif; ?>
// 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>";
<!-- Form to select game mode (using GET) -->
<form method="get" action="">
<?php foreach ($availableModes as $mode): ?>
<input type="submit" name="game_mode" value="<?php echo htmlspecialchars($mode); ?>" class="btn<?php echo ($mode === $selected_mode) ? ' active' : ''; ?>">
<?php endforeach; ?>
</form>
<br>
$metrics = [
'Kills' => 'kills',
'Damage' => 'damageDealt',
'Headshots' => 'headshotKills',
'Wins' => 'wins',
'Top10s' => 'top10s'
];
<?php if (!empty($playerAverages)): ?>
<table border="1" class="sortable">
<thead>
<tr>
<th>Player</th>
<?php foreach ($metrics as $display => $metric): ?>
<th>Average <?php echo htmlspecialchars($display); ?></th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($playerAverages as $player_name => $averages): ?>
<tr>
<td><?php echo htmlspecialchars($player_name); ?></td>
<?php foreach ($metrics as $metricKey): ?>
<td><?php echo htmlspecialchars($averages[$metricKey] ?? '0'); ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<br>
<?php elseif (!$dataError): ?>
<p>No average stats to display for the selected mode.</p>
<?php endif; ?>
echo "<table border='1' class='sortable'>";
echo "<tr><th>Player</th>";
foreach ($metrics as $display => $metric) {
echo "<th>Average $display</th>";
}
echo "</tr>";
<p>Last update: <?php echo $lastUpdated; ?></p>
foreach ($players_data[$selected_mode] as $player_name => $player_details) {
$account_id = array_key_first($player_details);
$stats = $player_details[$account_id];
$totalGames = $stats['wins'] + $stats['losses']; // Wins + Losses
echo "<tr><td>$player_name</td>";
foreach ($metrics as $metric) {
$averageValue = ($totalGames > 0) ? round($stats[$metric] / $totalGames, 2) : 0;
echo "<td>$averageValue</td>";
}
echo "</tr>";
}
echo "</table><br>";
echo "Last update " ;
echo $players_data['updated'];
?>
</section>
</main>